Re: Bug caused by 53965c79c2db (USB: Fix device driver race)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2020-10-21 at 14:02 +0200, Bastien Nocera wrote:
> On Wed, 2020-10-21 at 13:53 +0200, Bastien Nocera wrote:
> <snip>
> > I'll prepare a patch that adds a match function. I'll let you
> > (Vefa)
> > look at which of your patches need backporting though, as I'm
> > really
> > quite a bit lost in the different patch sets and branches :/
> 
> Something like that (untested):
> 
> diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c
> b/drivers/usb/misc/apple-mfi-fastcharge.c
> index b403094a6b3a..bb89dde018b1 100644
> --- a/drivers/usb/misc/apple-mfi-fastcharge.c
> +++ b/drivers/usb/misc/apple-mfi-fastcharge.c
> @@ -163,17 +163,26 @@ static const struct power_supply_desc
> apple_mfi_fc_desc = {
>         .property_is_writeable  = apple_mfi_fc_property_is_writeable
>  };
>  
> +static bool mfi_fc_match(struct usb_device *udev)
> +{
> +       int idProduct, idVendor;
> +
> +       idVendor = le16_to_cpu(udev->descriptor.idVendor);
> +       idProduct = le16_to_cpu(udev->descriptor.idProduct);
> +       /* See comment above mfi_fc_id_table[] */
> +       return (idVendor == APPLE_VENDOR_ID &&
> +               idProduct >= 0x1200 &&
> +               idProduct <= 0x12ff);
> +}
> +
>  static int mfi_fc_probe(struct usb_device *udev)
>  {
>         struct power_supply_config battery_cfg = {};
>         struct mfi_device *mfi = NULL;
> -       int err, idProduct;
> +       int err;
>  
> -       idProduct = le16_to_cpu(udev->descriptor.idProduct);
> -       /* See comment above mfi_fc_id_table[] */
> -       if (idProduct < 0x1200 || idProduct > 0x12ff) {
> +       if (!mfi_fc_probe(udev))

Even with the s/mfi_fc_probe/mfi_fc_match/ fix, I don't think this
patch will work.

The code in drivers/usb/core/driver.c usb_device_match() will look at
the ID table first, and check whether there's a match and exit if there
was, then check for the result of the ->match function.

But apple-mfi-fastcharge.ko will not get automatically loaded if
there's no ID table. And its match function at all won't get called if
there's an ID table.

So we'd need to check for id_table matching *and* match function
matching.

Is my reasoning correct here?

I have a local patch, which I'll test shortly.




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux