public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Hans de Goede <hansg@kernel.org>,
	Israel Cepeda <israel.a.cepeda.lopez@intel.com>,
	Wolfram Sang <wsa@kernel.org>, Andi Shyti <andi.shyti@kernel.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	Linus Walleij <linus.walleij@linaro.org>,
	Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>,
	Richard Hughes <rhughes@redhat.com>,
	linux-i2c@vger.kernel.org, linux-usb@vger.kernel.org,
	linux-gpio@vger.kernel.org
Subject: Re: [PATCH 1/3] usb: misc: Add Intel USBIO bridge driver
Date: Mon, 11 Aug 2025 09:23:41 +0000	[thread overview]
Message-ID: <aJm2naLnWChQOChH@kekkonen.localdomain> (raw)
In-Reply-To: <2025081128-ecard-ecosphere-8170@gregkh>

Hi Greg,

On Mon, Aug 11, 2025 at 10:31:22AM +0200, Greg Kroah-Hartman wrote:
> On Mon, Aug 11, 2025 at 07:29:37AM +0000, Sakari Ailus wrote:
> > Hi Greg,
> > 
> > On Mon, Aug 11, 2025 at 09:12:36AM +0200, Greg Kroah-Hartman wrote:
> > > On Mon, Aug 11, 2025 at 06:51:03AM +0000, Sakari Ailus wrote:
> > > > > +/**
> > > > > + * struct usbio_client - represents a usbio client
> > > > > + *
> > > > > + * @adev: auxiliary device object
> > > > > + * @bridge: usbio bridge who service the client
> > > > > + * @link: usbio bridge clients list member
> > > > > + */
> > > > > +struct usbio_client {
> > > > > +	struct auxiliary_device adev;
> > > > > +	struct usbio_device *bridge;
> > > > > +	struct list_head link;
> > > > > +};
> > > > > +
> > > > > +#define adev_to_client(adev) container_of(adev, struct usbio_client, adev)
> > > > 
> > > > Please use a different name than "adev" for the argument, which is also the
> > > > struct field of interest.
> > > 
> > > Why?  That's a very common way of doing this.  My only complaint is that
> > > it really should be "container_of_const()" instead of just
> > > "container_of()"
> > 
> > Because the struct field has the same name. The macro isn't intended for
> > obtaining the container struct based on any field in the struct, only the
> > field called "adev".
> 
> And that's fine, the macro works like this, so all should be ok.
> 
> > I'll post a patch to add the container_of() check to checkpatch.pl.
> 
> Patch to add it to do what?

You're cc'd. :-)

> 
> > > > > +static int usbio_ctrl_msg(struct usbio_device *usbio, u8 type, u8 cmd,
> > > > > +			  const void *obuf, u16 obuf_len, void *ibuf, u16 ibuf_len)
> > > > > +{
> > > > > +	u8 request = USB_TYPE_VENDOR | USB_RECIP_DEVICE;
> > > > > +	struct usbio_ctrl_packet *cpkt;
> > > > > +	unsigned int pipe;
> > > > > +	u16 cpkt_len;
> > > > > +	int ret;
> > > > > +
> > > > > +	lockdep_assert_held(&usbio->mutex);
> > > > > +
> > > > > +	if ((obuf_len > (usbio->ctrlbuf_len - sizeof(*cpkt))) ||
> > > > > +	    (ibuf_len > (usbio->ctrlbuf_len - sizeof(*cpkt))))
> > > > 
> > > > You can (and should) remove all parentheses except the outer ones here.
> > > 
> > > No, don't do that.  If you do that you will have to manually go and try
> > > to remember the order of operations every time you read this code.
> > 
> > I presume kernel developers in general do.
> > 
> > But if in doubt: <URL:https://users.ece.utexas.edu/~adnan/c-refcard.pdf>.
> 
> Don't force me to look it up all the time, use () to make it obvious
> please.  That's the biggest thing I hate about that checkpatch "rule",
> please do not follow it for any code that I am a maintainer for.
> 
> > > > > +static void usbio_disconnect(struct usb_interface *intf)
> > > > > +{
> > > > > +	struct usbio_device *usbio = usb_get_intfdata(intf);
> > > > > +	struct usbio_client *client, *prev;
> > > > > +
> > > > > +	list_for_each_entry_safe_reverse(client, prev, &usbio->cli_list, link) {
> > > > > +		auxiliary_device_delete(&client->adev);
> > > > > +		list_del_init(&client->link);
> > > > > +		auxiliary_device_uninit(&client->adev);
> > > > > +	}
> > > > > +
> > > > > +	usb_kill_urb(usbio->urb);
> > > > > +	usb_free_urb(usbio->urb);
> > > > 
> > > > What will happen on client drivers if they're working with the bridge while
> > > > disconnect happens?
> > > > 
> > > > One easy solution to this could be to use an rw_semaphore where client
> > > > acquire it for readingin conjunction (in a helper that also checks the
> > > > interface status) and disconnect callback for writing.
> > > 
> > > How is that going to change anything?  And how can a disconnect happen?
> > > Isn't this an onboard device?
> > 
> > It is, but the device firmware is known to crash occasionally.
> 
> Then fix the firmware :)

In practice this depends on device vendor and we all know the quality of
firmware from random sources. These are not Intel-implemented devices.

> 
> > The documantation says you can't access USB interfaces once disconnect has
> > returned. I'm not sure if there are checks to safeguard against ongoing or
> > additional accesses in the USB stack but on many other buses this may
> > simply lead to a system crash.
> 
> How can you access the USB interface after disconnect has returned on
> these codepaths?  The child devices should all be cleaned up properly
> after disconnect happens so there should not be a pointer to even use
> anymore.

See functions exported by the main USBIO driver.

-- 
Regards,

Sakari Ailus

  reply	other threads:[~2025-08-11  9:23 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-09 10:23 [PATCH 0/3] usb/gpio/i2c: Add Intel USBIO USB IO-expander drivers Hans de Goede
2025-08-09 10:23 ` [PATCH 1/3] usb: misc: Add Intel USBIO bridge driver Hans de Goede
2025-08-09 14:28   ` Greg Kroah-Hartman
2025-08-09 15:05     ` Hans de Goede
2025-08-09 15:29   ` kernel test robot
2025-08-10  0:19   ` kernel test robot
2025-08-11  6:51   ` Sakari Ailus
2025-08-11  7:12     ` Greg Kroah-Hartman
2025-08-11  7:29       ` Sakari Ailus
2025-08-11  8:31         ` Greg Kroah-Hartman
2025-08-11  9:23           ` Sakari Ailus [this message]
2025-08-11  9:29             ` Hans de Goede
2025-08-11  9:13     ` Hans de Goede
2025-08-11  9:32       ` Sakari Ailus
2025-09-05 18:36     ` Hans de Goede
2025-08-09 10:23 ` [PATCH 2/3] gpio: Add Intel USBIO GPIO driver Hans de Goede
2025-08-11  7:07   ` Sakari Ailus
2025-08-11  9:23     ` Hans de Goede
2025-08-11  9:43       ` Sakari Ailus
2025-08-09 10:23 ` [PATCH 3/3] i2c: Add Intel USBIO I2C driver Hans de Goede
2025-08-11  7:16   ` Sakari Ailus
2025-08-11  9:49     ` Hans de Goede
2025-09-05 21:28       ` Sakari Ailus
2025-09-05 18:50     ` Hans de Goede
2025-09-05 21:34       ` Sakari Ailus

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=aJm2naLnWChQOChH@kekkonen.localdomain \
    --to=sakari.ailus@linux.intel.com \
    --cc=andi.shyti@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=gregkh@linuxfoundation.org \
    --cc=hansg@kernel.org \
    --cc=israel.a.cepeda.lopez@intel.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=rhughes@redhat.com \
    --cc=stanislaw.gruszka@linux.intel.com \
    --cc=wsa@kernel.org \
    /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