Commit 99c49407 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Linus Torvalds

idr: add ida_is_empty

Two of the USB Gadgets were poking around in the internals of struct ida
in order to determine if it is empty.  Add the appropriate abstraction.

Link: http://lkml.kernel.org/r/1480369871-5271-63-git-send-email-mawilcox@linuxonhyperv.comSigned-off-by: default avatarMatthew Wilcox <willy@linux.intel.com>
Acked-by: default avatarKonstantin Khlebnikov <koct9i@gmail.com>
Tested-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Felipe Balbi <balbi@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 3e3cdc68
...@@ -905,7 +905,7 @@ static void hidg_free_inst(struct usb_function_instance *f) ...@@ -905,7 +905,7 @@ static void hidg_free_inst(struct usb_function_instance *f)
mutex_lock(&hidg_ida_lock); mutex_lock(&hidg_ida_lock);
hidg_put_minor(opts->minor); hidg_put_minor(opts->minor);
if (idr_is_empty(&hidg_ida.idr)) if (ida_is_empty(&hidg_ida))
ghid_cleanup(); ghid_cleanup();
mutex_unlock(&hidg_ida_lock); mutex_unlock(&hidg_ida_lock);
...@@ -931,7 +931,7 @@ static struct usb_function_instance *hidg_alloc_inst(void) ...@@ -931,7 +931,7 @@ static struct usb_function_instance *hidg_alloc_inst(void)
mutex_lock(&hidg_ida_lock); mutex_lock(&hidg_ida_lock);
if (idr_is_empty(&hidg_ida.idr)) { if (ida_is_empty(&hidg_ida)) {
status = ghid_setup(NULL, HIDG_MINORS); status = ghid_setup(NULL, HIDG_MINORS);
if (status) { if (status) {
ret = ERR_PTR(status); ret = ERR_PTR(status);
...@@ -944,7 +944,7 @@ static struct usb_function_instance *hidg_alloc_inst(void) ...@@ -944,7 +944,7 @@ static struct usb_function_instance *hidg_alloc_inst(void)
if (opts->minor < 0) { if (opts->minor < 0) {
ret = ERR_PTR(opts->minor); ret = ERR_PTR(opts->minor);
kfree(opts); kfree(opts);
if (idr_is_empty(&hidg_ida.idr)) if (ida_is_empty(&hidg_ida))
ghid_cleanup(); ghid_cleanup();
goto unlock; goto unlock;
} }
......
...@@ -1265,7 +1265,7 @@ static void gprinter_free_inst(struct usb_function_instance *f) ...@@ -1265,7 +1265,7 @@ static void gprinter_free_inst(struct usb_function_instance *f)
mutex_lock(&printer_ida_lock); mutex_lock(&printer_ida_lock);
gprinter_put_minor(opts->minor); gprinter_put_minor(opts->minor);
if (idr_is_empty(&printer_ida.idr)) if (ida_is_empty(&printer_ida))
gprinter_cleanup(); gprinter_cleanup();
mutex_unlock(&printer_ida_lock); mutex_unlock(&printer_ida_lock);
...@@ -1289,7 +1289,7 @@ static struct usb_function_instance *gprinter_alloc_inst(void) ...@@ -1289,7 +1289,7 @@ static struct usb_function_instance *gprinter_alloc_inst(void)
mutex_lock(&printer_ida_lock); mutex_lock(&printer_ida_lock);
if (idr_is_empty(&printer_ida.idr)) { if (ida_is_empty(&printer_ida)) {
status = gprinter_setup(PRINTER_MINORS); status = gprinter_setup(PRINTER_MINORS);
if (status) { if (status) {
ret = ERR_PTR(status); ret = ERR_PTR(status);
...@@ -1302,7 +1302,7 @@ static struct usb_function_instance *gprinter_alloc_inst(void) ...@@ -1302,7 +1302,7 @@ static struct usb_function_instance *gprinter_alloc_inst(void)
if (opts->minor < 0) { if (opts->minor < 0) {
ret = ERR_PTR(opts->minor); ret = ERR_PTR(opts->minor);
kfree(opts); kfree(opts);
if (idr_is_empty(&printer_ida.idr)) if (ida_is_empty(&printer_ida))
gprinter_cleanup(); gprinter_cleanup();
goto unlock; goto unlock;
} }
......
...@@ -195,6 +195,11 @@ static inline int ida_get_new(struct ida *ida, int *p_id) ...@@ -195,6 +195,11 @@ static inline int ida_get_new(struct ida *ida, int *p_id)
return ida_get_new_above(ida, 0, p_id); return ida_get_new_above(ida, 0, p_id);
} }
static inline bool ida_is_empty(struct ida *ida)
{
return idr_is_empty(&ida->idr);
}
void __init idr_init_cache(void); void __init idr_init_cache(void);
#endif /* __IDR_H__ */ #endif /* __IDR_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment