Re: [PATCH] usb: gadget: udc: Add null pointer check for udc in gadget_match_driver

From: Alan Stern
Date: Sat Aug 31 2024 - 00:29:18 EST


On Fri, Aug 30, 2024 at 06:16:12PM +0530, Selvarasu Ganesan wrote:
> Hi Alan,
>
> Thanks for your comments. I understand your suggestions. We already have
> a similar reference check with the udc name before calling
> usb_gadget_register_driver.
> In the drivers/usb/gadget/configfs.c file, I am wondering if there might
> be an issue with the check of udc_name before
> usb_gadget_register_driver. This is the only way to allow
> gadget_register to be called before releasing or unregistering an
> existing udc. Do you think we need to add an additional check here,
> referencing the UDC, to prevent gadget_register from being called before
> the existing UDC is released?

I don't understand what you're saying. There is no routine named
"gadget_register". (And there is no variable named "udc_name" in the
code below, although there is gi->composite.gadget_driver.udc_name --
but that's not a variable, it is a field in a structure.)

> drivers/usb/gadget/configfs.c : gadget_dev_desc_UDC_store()
> ===========================================================
> if (gi->composite.gadget_driver.udc_name) {
>                         ret = -EBUSY;
>                         goto err;
>                 }
> gi->composite.gadget_driver.udc_name = name;

Are you talking about this check and assignment? Why do you think there
might be a problem here?

Are you worried that some UDC might be released while this code is
running? If that happens, why would it be a problem?

> ret = usb_gadget_register_driver(&gi->composite.gadget_driver);

Alan Stern