--- zzzz-none-000/linux-4.9.276/lib/idr.c 2021-07-20 14:21:16.000000000 +0000 +++ falcon-5530-750/linux-4.9.276/lib/idr.c 2023-04-05 08:19:02.000000000 +0000 @@ -543,11 +543,11 @@ } /** - * idr_remove - remove the given id and free its slot + * _idr_remove - remove the given id and free its slot * @idp: idr handle * @id: unique key */ -void idr_remove(struct idr *idp, int id) +static void _idr_remove(struct idr *idp, int id) { struct idr_layer *p; struct idr_layer *to_free; @@ -578,6 +578,27 @@ free_layer(idp, to_free); } } + +/* + * idr_remove remove the given id, free its slot and return the deleted entry + * @idp: idr handle + * @id unique key + */ +void *idr_remove(struct idr *idp, int id) +{ + void *data = idr_find(idp, id); + + /* + * first check data as if idr_find wouldn't succeed idr_remove wouldn't + * succeed either with the given id! idr_find only fails with an invalid + * id or NULL given. + **/ + + if (!data) + return NULL; + _idr_remove(idp, id); + return data; +} EXPORT_SYMBOL(idr_remove); static void __idr_remove_all(struct idr *idp)