Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: gadget: configfs: allow setting function instance's name

USB function's configfs config group is created in a generic way in
usb/gadget/configfs.c:function_make(), which in turn delegates actual
allocation and setup of the USB function instance to a particular
implementation, e.g. in f_acm.c. The said implementation does its job
in a parameter-less function e.g. acm_alloc_instance(), which results
in creating an unnamed config group, whose name is set later in
function_make(). function_make() creates the name by parsing a string
of the form:

<function name>.<instance name>

which comes from userspace as a parameter to mkdir invocation.

Up to now only <function name> has been used, while <instance name>
has been ignored. This patch adds a set_inst_name() operation to
struct usb_function_instance which allows passing the <instance name>
from function_make() so that it is not ignored. It is entirely up to the
implementor of set_inst_name() what to do with the <instance name>.

In a typical case, the struct usb_function_instance is embedded in a
larger struct which is retrieved in set_inst_name() with container_of(),
and the larger struct contains a field to store the <instance name>.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>

authored by

Andrzej Pietrasiewicz and committed by
Felipe Balbi
1933861d b963a81a

+9
+7
drivers/usb/gadget/configfs.c
··· 564 564 usb_put_function_instance(fi); 565 565 return ERR_PTR(ret); 566 566 } 567 + if (fi->set_inst_name) { 568 + ret = fi->set_inst_name(fi, instance_name); 569 + if (ret) { 570 + usb_put_function_instance(fi); 571 + return ERR_PTR(ret); 572 + } 573 + } 567 574 568 575 gi = container_of(group, struct gadget_info, functions_group); 569 576
+2
include/linux/usb/composite.h
··· 468 468 struct config_group group; 469 469 struct list_head cfs_list; 470 470 struct usb_function_driver *fd; 471 + int (*set_inst_name)(struct usb_function_instance *inst, 472 + const char *name); 471 473 void (*free_func_inst)(struct usb_function_instance *inst); 472 474 }; 473 475