linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [v1,11/12] usb: gadget: Add configfs attribuite for controling match_existing_only
@ 2018-12-03  3:45 Yu Chen
  0 siblings, 0 replies; 4+ messages in thread
From: Yu Chen @ 2018-12-03  3:45 UTC (permalink / raw)
  To: linux-usb, devicetree, linux-kernel
  Cc: suzhuangluan, kongfei, Yu Chen, Felipe Balbi, Greg Kroah-Hartman,
	John Stultz, Binghui Wang

Currently the "match_existing_only" of usb_gadget_driver in configfs is
set to one which is not flexible.
Dwc3 udc will be removed when usb core switch to host mode. This causes
failure of writing name of dwc3 udc to configfs's UDC attribuite.
To fix this we need to add a way to change the config of
"match_existing_only".
This patch adds a configfs attribuite for controling match_existing_only
which allow user to config "match_existing_only".

Cc: Felipe Balbi <balbi@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Binghui Wang <wangbinghui@hisilicon.com>
Signed-off-by: Yu Chen <chenyu56@huawei.com>
---
 drivers/usb/gadget/configfs.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 025129942894..c82b7bc98dea 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -291,6 +291,36 @@ static ssize_t gadget_dev_desc_UDC_store(struct config_item *item,
 	return ret;
 }
 
+static ssize_t gadget_driver_match_existing_only_store(struct config_item *item,
+		const char *page, size_t len)
+{
+	struct usb_gadget_driver *gadget_driver =
+		&(to_gadget_info(item)->composite.gadget_driver);
+	bool match_existing_only;
+	int ret;
+
+	ret = kstrtobool(page, &match_existing_only);
+	if (ret)
+		return ret;
+
+	if (match_existing_only)
+		gadget_driver->match_existing_only = 1;
+	else
+		gadget_driver->match_existing_only = 0;
+
+	return len;
+}
+
+static ssize_t gadget_driver_match_existing_only_show(struct config_item *item,
+		char *page)
+{
+	struct usb_gadget_driver *gadget_driver =
+		&(to_gadget_info(item)->composite.gadget_driver);
+	bool match_existing_only = !!gadget_driver->match_existing_only;
+
+	return sprintf(page, "%s\n", match_existing_only ? "true" : "false");
+}
+
 CONFIGFS_ATTR(gadget_dev_desc_, bDeviceClass);
 CONFIGFS_ATTR(gadget_dev_desc_, bDeviceSubClass);
 CONFIGFS_ATTR(gadget_dev_desc_, bDeviceProtocol);
@@ -300,6 +330,7 @@ CONFIGFS_ATTR(gadget_dev_desc_, idProduct);
 CONFIGFS_ATTR(gadget_dev_desc_, bcdDevice);
 CONFIGFS_ATTR(gadget_dev_desc_, bcdUSB);
 CONFIGFS_ATTR(gadget_dev_desc_, UDC);
+CONFIGFS_ATTR(gadget_, driver_match_existing_only);
 
 static struct configfs_attribute *gadget_root_attrs[] = {
 	&gadget_dev_desc_attr_bDeviceClass,
@@ -311,6 +342,7 @@ static struct configfs_attribute *gadget_root_attrs[] = {
 	&gadget_dev_desc_attr_bcdDevice,
 	&gadget_dev_desc_attr_bcdUSB,
 	&gadget_dev_desc_attr_UDC,
+	&gadget_attr_driver_match_existing_only,
 	NULL,
 };
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [v1,11/12] usb: gadget: Add configfs attribuite for controling match_existing_only
@ 2018-12-04  1:22 Yu Chen
  0 siblings, 0 replies; 4+ messages in thread
From: Yu Chen @ 2018-12-04  1:22 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: wangbinghui, USB, devicetree, Linux Kernel Mailing List,
	Suzhuangluan, Kongfei, Felipe Balbi, Greg Kroah-Hartman,
	John Stultz

On 2018/12/3 17:25, Andy Shevchenko wrote:
> On Mon, Dec 3, 2018 at 5:47 AM Yu Chen <chenyu56@huawei.com> wrote:
>>
>> Currently the "match_existing_only" of usb_gadget_driver in configfs is
>> set to one which is not flexible.
>> Dwc3 udc will be removed when usb core switch to host mode. This causes
>> failure of writing name of dwc3 udc to configfs's UDC attribuite.
>> To fix this we need to add a way to change the config of
>> "match_existing_only".
>> This patch adds a configfs attribuite for controling match_existing_only
>> which allow user to config "match_existing_only".
> 
>> +static ssize_t gadget_driver_match_existing_only_store(struct config_item *item,
>> +               const char *page, size_t len)
>> +{
> 
>> +       struct usb_gadget_driver *gadget_driver =
>> +               &(to_gadget_info(item)->composite.gadget_driver);
> 
> It would be easier for reader to see two lines with two variables
> instead of this.

OK.
> 
>> +       bool match_existing_only;
>> +       int ret;
>> +
>> +       ret = kstrtobool(page, &match_existing_only);
>> +       if (ret)
>> +               return ret;
>> +
> 
>> +       if (match_existing_only)
>> +               gadget_driver->match_existing_only = 1;
>> +       else
>> +               gadget_driver->match_existing_only = 0;
> 
>           gadget_driver->match_existing_only = match_existing_only;
> But the question rather why is it not direct parameter to kstrtobool?
> 
I wrote the code in this way to avoid type conversion.

>> +
>> +       return len;
>> +}
> 
>> +       struct usb_gadget_driver *gadget_driver =
>> +               &(to_gadget_info(item)->composite.gadget_driver);
> 
> Make it neat.
> 
OK.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [v1,11/12] usb: gadget: Add configfs attribuite for controling match_existing_only
@ 2018-12-03  9:53 Krzysztof Opasiak
  0 siblings, 0 replies; 4+ messages in thread
From: Krzysztof Opasiak @ 2018-12-03  9:53 UTC (permalink / raw)
  To: Yu Chen, linux-usb, devicetree, linux-kernel
  Cc: suzhuangluan, kongfei, Felipe Balbi, Greg Kroah-Hartman,
	John Stultz, Binghui Wang

On 03.12.2018 04:45, Yu Chen wrote:
> Currently the "match_existing_only" of usb_gadget_driver in configfs is
> set to one which is not flexible.
> Dwc3 udc will be removed when usb core switch to host mode. This causes
> failure of writing name of dwc3 udc to configfs's UDC attribuite.
> To fix this we need to add a way to change the config of
> "match_existing_only".
> This patch adds a configfs attribuite for controling match_existing_only
> which allow user to config "match_existing_only".
> 

To be honest I strongly disagree with that patch.
This attribute was intended for build-in gadgets to allow user to decide 
whether probe should fail or gadget should wait for UDC (used when 
gadget is built-in). For ConfigFS we expect the UDC to always exist 
prior to binding a gadget to it. If UDC goes away from what ever reason 
gadget should be unbound.

So what this patch does in my opinion is abusing the attribute and 
hacking the kernel instead of creating a simple udev rule that whenever 
dwc3 appears and it gadget should be enabled write its name to UDC 
attribute.

Best regards,

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [v1,11/12] usb: gadget: Add configfs attribuite for controling match_existing_only
@ 2018-12-03  9:25 Andy Shevchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2018-12-03  9:25 UTC (permalink / raw)
  To: chenyu56
  Cc: USB, devicetree, Linux Kernel Mailing List, Suzhuangluan,
	Kongfei, Felipe Balbi, Greg Kroah-Hartman, John Stultz,
	Wangbinghui

On Mon, Dec 3, 2018 at 5:47 AM Yu Chen <chenyu56@huawei.com> wrote:
>
> Currently the "match_existing_only" of usb_gadget_driver in configfs is
> set to one which is not flexible.
> Dwc3 udc will be removed when usb core switch to host mode. This causes
> failure of writing name of dwc3 udc to configfs's UDC attribuite.
> To fix this we need to add a way to change the config of
> "match_existing_only".
> This patch adds a configfs attribuite for controling match_existing_only
> which allow user to config "match_existing_only".

> +static ssize_t gadget_driver_match_existing_only_store(struct config_item *item,
> +               const char *page, size_t len)
> +{

> +       struct usb_gadget_driver *gadget_driver =
> +               &(to_gadget_info(item)->composite.gadget_driver);

It would be easier for reader to see two lines with two variables
instead of this.

> +       bool match_existing_only;
> +       int ret;
> +
> +       ret = kstrtobool(page, &match_existing_only);
> +       if (ret)
> +               return ret;
> +

> +       if (match_existing_only)
> +               gadget_driver->match_existing_only = 1;
> +       else
> +               gadget_driver->match_existing_only = 0;

          gadget_driver->match_existing_only = match_existing_only;
But the question rather why is it not direct parameter to kstrtobool?

> +
> +       return len;
> +}

> +       struct usb_gadget_driver *gadget_driver =
> +               &(to_gadget_info(item)->composite.gadget_driver);

Make it neat.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-12-04  1:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-03  3:45 [v1,11/12] usb: gadget: Add configfs attribuite for controling match_existing_only Yu Chen
2018-12-03  9:25 Andy Shevchenko
2018-12-03  9:53 Krzysztof Opasiak
2018-12-04  1:22 Yu Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).