All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: roles: Switch on role-switch uevent reporting
@ 2020-05-08 16:29 Bryan O'Donoghue
  2020-05-09  3:24 ` Wen Yang
  0 siblings, 1 reply; 3+ messages in thread
From: Bryan O'Donoghue @ 2020-05-08 16:29 UTC (permalink / raw)
  To: heikki.krogerus, gregkh, linux-usb, bryan.odonoghue
  Cc: Chunfeng Yun, Suzuki K Poulose, Alexandre Belloni, Wen Yang,
	chenqiwu, linux-kernel

Right now we don't report to user-space a role switch when doing a
usb_role_switch_set_role() despite having registered the uevent callbacks.

This patch switches on the notifications allowing user-space to see
role-switch change notifications and subsequently determine the current
controller data-role.

example:
PFX=/devices/platform/soc/78d9000.usb/ci_hdrc.0

root@somebox# udevadm monitor -p

KERNEL[49.894994] change $PFX/usb_role/ci_hdrc.0-role-switch (usb_role)
ACTION=change
DEVPATH=$PFX/usb_role/ci_hdrc.0-role-switch
SUBSYSTEM=usb_role
DEVTYPE=usb_role_switch
USB_ROLE_SWITCH=ci_hdrc.0-role-switch
SEQNUM=2432

Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Chunfeng Yun <chunfeng.yun@mediatek.com>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Wen Yang <wenyang@linux.alibaba.com>
Cc: chenqiwu <chenqiwu@xiaomi.com>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
 drivers/usb/roles/class.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index 5b17709821df..27d92af29635 100644
--- a/drivers/usb/roles/class.c
+++ b/drivers/usb/roles/class.c
@@ -49,8 +49,10 @@ int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role)
 	mutex_lock(&sw->lock);
 
 	ret = sw->set(sw, role);
-	if (!ret)
+	if (!ret) {
 		sw->role = role;
+		kobject_uevent(&sw->dev.kobj, KOBJ_CHANGE);
+	}
 
 	mutex_unlock(&sw->lock);
 
-- 
2.25.1


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

* Re: [PATCH] usb: roles: Switch on role-switch uevent reporting
  2020-05-08 16:29 [PATCH] usb: roles: Switch on role-switch uevent reporting Bryan O'Donoghue
@ 2020-05-09  3:24 ` Wen Yang
  2020-05-09 16:37   ` Bryan O'Donoghue
  0 siblings, 1 reply; 3+ messages in thread
From: Wen Yang @ 2020-05-09  3:24 UTC (permalink / raw)
  To: Bryan O'Donoghue, heikki.krogerus, gregkh, linux-usb
  Cc: Chunfeng Yun, Suzuki K Poulose, Alexandre Belloni, chenqiwu,
	linux-kernel



在 2020/5/9 上午12:29, Bryan O'Donoghue 写道:
> Right now we don't report to user-space a role switch when doing a
> usb_role_switch_set_role() despite having registered the uevent callbacks.
> 
> This patch switches on the notifications allowing user-space to see
> role-switch change notifications and subsequently determine the current
> controller data-role.
> 
> example:
> PFX=/devices/platform/soc/78d9000.usb/ci_hdrc.0
> 
> root@somebox# udevadm monitor -p
> 
> KERNEL[49.894994] change $PFX/usb_role/ci_hdrc.0-role-switch (usb_role)
> ACTION=change
> DEVPATH=$PFX/usb_role/ci_hdrc.0-role-switch
> SUBSYSTEM=usb_role
> DEVTYPE=usb_role_switch
> USB_ROLE_SWITCH=ci_hdrc.0-role-switch
> SEQNUM=2432
> 
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Chunfeng Yun <chunfeng.yun@mediatek.com>
> Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
> Cc: Wen Yang <wenyang@linux.alibaba.com>
> Cc: chenqiwu <chenqiwu@xiaomi.com>
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> ---
>   drivers/usb/roles/class.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index 5b17709821df..27d92af29635 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -49,8 +49,10 @@ int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role)
>   	mutex_lock(&sw->lock);
>   
>   	ret = sw->set(sw, role);
> -	if (!ret)
> +	if (!ret) {
>   		sw->role = role;
> +		kobject_uevent(&sw->dev.kobj, KOBJ_CHANGE);
> +	}
>   
>   	mutex_unlock(&sw->lock);
>   
> 

Hi, we may also need to deal with the return value of kobject_uevent(). 
Should we move it under the line mutex_unlock(&sw->lock)?

Regards,
Wen


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

* Re: [PATCH] usb: roles: Switch on role-switch uevent reporting
  2020-05-09  3:24 ` Wen Yang
@ 2020-05-09 16:37   ` Bryan O'Donoghue
  0 siblings, 0 replies; 3+ messages in thread
From: Bryan O'Donoghue @ 2020-05-09 16:37 UTC (permalink / raw)
  To: Wen Yang, heikki.krogerus, gregkh, linux-usb
  Cc: Chunfeng Yun, Suzuki K Poulose, Alexandre Belloni, chenqiwu,
	linux-kernel

On 09/05/2020 04:24, Wen Yang wrote:
> 
> 
> 在 2020/5/9 上午12:29, Bryan O'Donoghue 写道:
>> Right now we don't report to user-space a role switch when doing a
>> usb_role_switch_set_role() despite having registered the uevent 
>> callbacks.
>>
>> This patch switches on the notifications allowing user-space to see
>> role-switch change notifications and subsequently determine the current
>> controller data-role.
>>
>> example:
>> PFX=/devices/platform/soc/78d9000.usb/ci_hdrc.0
>>
>> root@somebox# udevadm monitor -p
>>
>> KERNEL[49.894994] change $PFX/usb_role/ci_hdrc.0-role-switch (usb_role)
>> ACTION=change
>> DEVPATH=$PFX/usb_role/ci_hdrc.0-role-switch
>> SUBSYSTEM=usb_role
>> DEVTYPE=usb_role_switch
>> USB_ROLE_SWITCH=ci_hdrc.0-role-switch
>> SEQNUM=2432
>>
>> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Cc: Chunfeng Yun <chunfeng.yun@mediatek.com>
>> Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
>> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
>> Cc: Wen Yang <wenyang@linux.alibaba.com>
>> Cc: chenqiwu <chenqiwu@xiaomi.com>
>> Cc: linux-kernel@vger.kernel.org
>> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
>> ---
>>   drivers/usb/roles/class.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
>> index 5b17709821df..27d92af29635 100644
>> --- a/drivers/usb/roles/class.c
>> +++ b/drivers/usb/roles/class.c
>> @@ -49,8 +49,10 @@ int usb_role_switch_set_role(struct usb_role_switch 
>> *sw, enum usb_role role)
>>       mutex_lock(&sw->lock);
>>       ret = sw->set(sw, role);
>> -    if (!ret)
>> +    if (!ret) {
>>           sw->role = role;
>> +        kobject_uevent(&sw->dev.kobj, KOBJ_CHANGE);
>> +    }
>>       mutex_unlock(&sw->lock);
>>
> 
> Hi, we may also need to deal with the return value of kobject_uevent(). 

For an KOBJ_ADD you'd return an error.

grep -r "= kobject_uevent(" *
drivers/misc/cxl/sysfs.c:	rc = kobject_uevent(&cr->kobj, KOBJ_ADD);
drivers/uio/uio.c:		ret = kobject_uevent(&map->kobj, KOBJ_ADD);
drivers/uio/uio.c:		ret = kobject_uevent(&portio->kobj, KOBJ_ADD);
drivers/visorbus/visorchipset.c:	res = 
kobject_uevent(&chipset_dev->acpi_device->dev.kobj, KOBJ_ONLINE);
drivers/visorbus/visorchipset.c:	int res = 
kobject_uevent(&chipset_dev->acpi_device->dev.kobj,

For a KOBJ_CHANGE I guess we could print an error

if (kobject_uevent(&sw->dev.kobj, KOBJ_CHANGE)
     dev_err(&sw->dev, "failed to signal USB role-switch uevent\n");

Nobody else seems that bothered about it.

grep -r "if (kobject_uevent(" *

> Should we move it under the line mutex_unlock(&sw->lock)?

I think probably not. the mutex serializes the notification. In theory 
outside the mutex you could get an out-of-order notification.

The main reason I put it where it is, is we already test ret and should 
only notify the change, when the role-switch has suceeded.

As I say, in theory anyway, the mutex enforces the signalling, whatever 
about the reception, of the role-switch change, so IMO inside the bounds 
of the mutex is the right place to put it.

---
bod

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

end of thread, other threads:[~2020-05-09 16:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-08 16:29 [PATCH] usb: roles: Switch on role-switch uevent reporting Bryan O'Donoghue
2020-05-09  3:24 ` Wen Yang
2020-05-09 16:37   ` Bryan O'Donoghue

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.