From: Andrzej Pietrasiewicz Date: Fri, 24 Jul 2015 07:48:40 +0000 (+0200) Subject: usb: gadget: f_hid: actually limit the number of instances X-Git-Tag: v4.2-rc6~10^2~3^2~2 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=774cf72f8ad971031428f8057d2947c8780a7b8c;p=linux-block.git usb: gadget: f_hid: actually limit the number of instances There is a predefined maximum number of hid instances, currently 4. A chrdev region is allocated accordingly, but with configfs the user can create as many hid function directories as they like. To make the number of hid instances consistent with the number of allocated minors, the limit is enforced at directory creation time. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Felipe Balbi --- diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c index f7f35a36c09a..6df9715a4bcd 100644 --- a/drivers/usb/gadget/function/f_hid.c +++ b/drivers/usb/gadget/function/f_hid.c @@ -699,6 +699,10 @@ static inline int hidg_get_minor(void) int ret; ret = ida_simple_get(&hidg_ida, 0, 0, GFP_KERNEL); + if (ret >= HIDG_MINORS) { + ida_simple_remove(&hidg_ida, ret); + ret = -ENODEV; + } return ret; }