public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Venkata Swamy Kassa <venkatswamy7@gmail.com>
Cc: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Venkata Swamy Kassa <venkata.swamy.kassa@hexagon.com>
Subject: Re: [PATCH] usb: typec: hd3ss3220: Add sysfs attribute for USB role state
Date: Fri, 27 Feb 2026 15:26:14 -0500	[thread overview]
Message-ID: <2026022737-bunion-preflight-6a20@gregkh> (raw)
In-Reply-To: <20260227182454.761925-1-venkata.swamy.kassa@hexagon.com>

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@hexagon.com>
> ---
>  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

  reply	other threads:[~2026-02-27 20:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-27 18:24 [PATCH] usb: typec: hd3ss3220: Add sysfs attribute for USB role state Venkata Swamy Kassa
2026-02-27 20:26 ` Greg KH [this message]
2026-03-02 10:35 ` Heikki Krogerus
  -- strict thread matches above, loose matches on Subject: below --
2026-02-27 18:23 Venkata Swamy Kassa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2026022737-bunion-preflight-6a20@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=venkata.swamy.kassa@hexagon.com \
    --cc=venkatswamy7@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox