Re: [RFC v2] usb/gadget: the start of the configfs interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Nov 29 2012, Sebastian Andrzej Siewior wrote:
> |# modprobe dummy_hcd num=2
>
> |# find /sys/kernel/config/ -ls
>
> |   557    0 drwxr-xr-x   3 root     root            0 Nov 29 17:26 /sys/kernel/config/
> |   558    0 drwxr-xr-x   5 root     root            0 Nov 29 17:26 /sys/kernel/config/usb_gadget
> |   561    0 drwxr-xr-x   4 root     root            0 Nov 29 17:26 /sys/kernel/config/usb_gadget/udcs
> |   569    0 drwxr-xr-x   2 root     root            0 Nov 29 17:26 /sys/kernel/config/usb_gadget/udcs/dummy_udc.1
> |   568    0 drwxr-xr-x   2 root     root            0 Nov 29 17:26 /sys/kernel/config/usb_gadget/udcs/dummy_udc.0
> |   560    0 drwxr-xr-x   2 root     root            0 Nov 29 17:26 /sys/kernel/config/usb_gadget/gadgets
> |   559    0 drwxr-xr-x   2 root     root            0 Nov 29 17:26 /sys/kernel/config/usb_gadget/functions
>
> | # lsmod
> | Module                  Size  Used by
> | dummy_hcd              20287  0
> | udc                    10219  1 dummy_hcd
>
> |# mkdir /sys/kernel/config/usb_gadget/functions/acm.one
>
> | # lsmod
> | Module                  Size  Used by
> | f_acm                   5306  0
> | u_serial                9644  1 f_acm
> | libcomposite           17052  1 f_acm
> | dummy_hcd              20287  0
> | udc                    10219  3 f_acm,dummy_hcd,libcomposite

Looks good to me.

> +#define MAX_NAME_LEN	40
> +static struct config_group *function_make(
> +		struct config_group *group,
> +		const char *name)
> +{
> +	struct usb_function *f;
> +	char buf[MAX_NAME_LEN];
> +	char *func_name;
> +	char *instance_name;
> +	int ret;
> +
> +	ret = snprintf(buf, MAX_NAME_LEN, "%s", name);
> +	if (ret >= MAX_NAME_LEN)
> +		ERR_PTR(-ENAMETOOLONG);

This copying is a bit pointless at the moment, but I'm assuming that's
because this is just RFC, right?

> +	func_name = buf;
> +	instance_name = strstr(func_name, ".");

strchr(func_name, '.')

> +	if (!instance_name) {
> +		pr_err("Unable to locate _ in FUNC_INSTANCE\n");
> +		return ERR_PTR(-EINVAL);
> +	}
> +	*instance_name = '\0';
> +	instance_name++;
> +
> +	pr_err("%s() try to get %s for %s\n", __func__, func_name, instance_name);
> +	f = usb_get_function(func_name);
> +	usb_put_function(f);
> +	pr_err("%s() %s\n", __func__,
> +			IS_ERR(f) ? "failed" : "good");
> +	return ERR_PTR(-EINVAL);
> +}

> @@ -512,12 +518,30 @@ static int __init usb_udc_init(void)
>  	}
>  
>  	udc_class->dev_uevent = usb_udc_uevent;
> +#ifndef MODULE
>  	return 0;
> +#else
> +	ret = gadget_cfs_init();
> +	if (ret)
> +		class_destroy(udc_class);
> +	return ret;
> +#endif

Could the ifdef logic be reversed?  Ie. have #ifdef rather than #ifndef?

>  }
>  subsys_initcall(usb_udc_init);
>  
> +#ifndef MODULE
> +static int __init usb_udc_init_mod(void)
> +{
> +	if (IS_ERR(udc_class))
> +		return PTR_ERR(udc_class);
> +	return gadget_cfs_init();
> +}
> +module_init(usb_udc_init_mod);
> +#endif
> +
>  static void __exit usb_udc_exit(void)
>  {
> +	gadget_cfs_exit();
>  	class_destroy(udc_class);
>  }
>  module_exit(usb_udc_exit);

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: mpn@xxxxxxxxxx>--------------ooO--(_)--Ooo--

Attachment: pgph7eVoGp_sH.pgp
Description: PGP signature


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux