Skip to content

Commit

Permalink
usb: gadget: f_printer: actually limit the number of instances
Browse files Browse the repository at this point in the history
There is a predefined maximum number of printer instances, currently 4.
A chrdev region is allocated accordingly, but with configfs the user
can create as many printer function directories as they like. To make the
number of printer  instances consistent with the number of allocated
minors, the limit is enforced at directory creation time.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Andrzej Pietrasiewicz authored and Felipe Balbi committed Jul 27, 2015
1 parent 774cf72 commit 4248bd7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion drivers/usb/gadget/function/f_printer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,15 @@ static struct config_item_type printer_func_type = {

static inline int gprinter_get_minor(void)
{
return ida_simple_get(&printer_ida, 0, 0, GFP_KERNEL);
int ret;

ret = ida_simple_get(&printer_ida, 0, 0, GFP_KERNEL);
if (ret >= PRINTER_MINORS) {
ida_simple_remove(&printer_ida, ret);
ret = -ENODEV;
}

return ret;
}

static inline void gprinter_put_minor(int minor)
Expand Down

0 comments on commit 4248bd7

Please sign in to comment.