Re: [PATCH] usb: typec: hd3ss3220: Add sysfs attribute for USB role state

From: Greg KH

Date: Fri Feb 27 2026 - 15:26:36 EST


On Fri, Feb 27, 2026 at 06:24:54PM +0000, Venkata Swamy Kassa wrote:
> The HD3SS3220 driver correctly detects USB Type-C cable attach/detach
> events and propagates the role to the USB controller. However, there is
> no way for userspace to query the current role state (device/host/none).
>
> This becomes problematic when using udev rules to trigger scripts on
> role changes. The driver generates kobject change events, but the event
> itself doesn't contain the role information. Userspace needs to read
> the current state to determine the appropriate action.
>
> Add a 'usb_role' sysfs attribute that exposes the current USB role as
> a string ("device", "host", or "none"). Also ensure sysfs_notify() and
> kobject_uevent() are called when the role changes, enabling userspace
> applications to poll() on the sysfs file or receive udev events.
>
> This is useful for systems that need to:
> - Start/stop USB gadget functions based on cable connection
> - Switch between host and device modes dynamically
> - Monitor USB Type-C port state from userspace

Did you send 2 copies of this?

> Signed-off-by: Venkata Swamy Kassa <venkata.swamy.kassa@xxxxxxxxxxx>
> ---
> drivers/usb/typec/hd3ss3220.c | 32 ++++++++++++++++++++++++++++++++

You have to document new sysfs files.

But really, you just created a new user/kernel api for just a single
driver, are you sure that is a good idea? Shouldn't you be using the
standard api for this instead as this is something that all of these
drivers need to handle.

And finally, a code comment:

> static void output_poll_execute(struct work_struct *work)
> @@ -310,6 +336,12 @@ static int hd3ss3220_probe(struct i2c_client *client)
> if (ret < 0)
> goto err_unreg_port;
>
> + ret = devm_device_add_group(&client->dev, &hd3ss3220_attr_group);

You just raced userspace and lost. Please, if you are creating sysfs
files, do it as a default group for the driver, the sysfs core will
handle the logic for that properly instead.

thanks,

greg k-h