All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cheng Lingfei <chenglingfei@foxmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Alan Stern <stern@rowland.harvard.edu>,
	Felipe Balbi <balbi@kernel.org>, Peter Chen <peter.chen@nxp.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+06ec7624018233e17113@syzkaller.appspotmail.com
Subject: Re: [PATCH v3 2/2] usb: gadget: goku_udc: fix kobject warning on probe failure
Date: Tue, 1 Sep 2026 11:08:26 +0800	[thread overview]
Message-ID: <tencent_CD7E18210FC0A874E644DBB097794EE29C09@qq.com> (raw)
In-Reply-To: <2026082647-tripping-skater-fe31@gregkh>

On 8/26/2026 5:27 PM, Greg Kroah-Hartman wrote:
> On Wed, Aug 26, 2026 at 05:15:07PM +0800, Cheng Lingfei wrote:
>> goku_probe() calls goku_remove() when hardware initialization fails, but
>> the gadget device is initialized only near the end of probe. As a result,
>> goku_remove() calls usb_del_gadget_udc(), which drops a reference to an
>> uninitialized gadget device and triggers a kobject warning.
>>
>> Initialize the gadget device immediately after allocating the controller,
>> but add it only after all hardware resources have been acquired. Track the
>> gadget registration state so goku_remove() can safely clean up both partial
>> probe state and a fully initialized device.
>>
>> Use the split gadget removal API and drop the final gadget reference only
>> after all hardware resources have been released. Obtain the controller from
>> the embedded gadget device in the release callback because driver data is
>> set on the PCI device rather than the gadget device.
>>
>> Fixes: 3301c215a2bb ("USB: UDC: Expand device model API interface")
>> Reported-by: syzbot+06ec7624018233e17113@syzkaller.appspotmail.com
>> Closes: https://syzkaller.appspot.com/bug?extid=06ec7624018233e17113
>> Tested-by: syzbot+06ec7624018233e17113@syzkaller.appspotmail.com
>> Assisted-by: Codex:gpt-5.6
>> Signed-off-by: Cheng Lingfei <chenglingfei@foxmail.com>
>> ---
>>   drivers/usb/gadget/udc/goku_udc.c | 28 ++++++++++++++--------------
>>   drivers/usb/gadget/udc/goku_udc.h |  3 ++-
>>   2 files changed, 16 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/usb/gadget/udc/goku_udc.c b/drivers/usb/gadget/udc/goku_udc.c
>> index 5ad8633f522b..615cc6b8f354 100644
>> --- a/drivers/usb/gadget/udc/goku_udc.c
>> +++ b/drivers/usb/gadget/udc/goku_udc.c
>> @@ -20,6 +20,7 @@
>>   // #define	VERBOSE		/* extra debug messages (success too) */
>>   // #define	USB_TRACE	/* packet-level success messages */
>>   
>> +#include <linux/container_of.h>
>>   #include <linux/debugfs.h>
>>   #include <linux/kernel.h>
>>   #include <linux/module.h>
>> @@ -1726,7 +1727,7 @@ static irqreturn_t goku_irq(int irq, void *_dev)
>>   
>>   static void gadget_release(struct device *_dev)
>>   {
>> -	struct goku_udc	*dev = dev_get_drvdata(_dev);
>> +	struct goku_udc *dev = container_of(_dev, struct goku_udc, gadget.dev);
> 
> That looks wrong.  If it is correct, please create a proper macro for it
> so that you verify that this all is working properly.

The object allocated by goku_probe() is struct goku_udc, with struct 
usb_gadget embedded in it. Therefore, when the gadget release callback 
is invoked with a pointer to the embedded gadget.dev, it must recover 
and free the enclosing struct goku_udc.
This follows the same pattern used by the net2280 and fsl_qe_udc 
drivers. I agree that the conversion should be made explicit, so I will 
add a helper macro in the next revision:

#define to_goku_udc(g) \
	container_of((g), struct goku_udc, gadget)

#define gadget_dev_to_goku_udc(d) \
	to_goku_udc(dev_to_usb_gadget(d))

-- 
Best regards,
Cheng Lingfei


      reply	other threads:[~2026-09-01  3:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260826-b4-fix-usb-v3-0-b28366e817f3@foxmail.com>
2026-08-26  9:15 ` [PATCH v3 1/2] usb: gadget: goku_udc: move debug output to debugfs Cheng Lingfei
2026-08-26  9:25   ` Greg Kroah-Hartman
2026-08-26 10:49     ` Cheng Lingfei
2026-08-26  9:27   ` Greg Kroah-Hartman
2026-09-01  2:23     ` Cheng Lingfei
2026-08-26  9:15 ` [PATCH v3 2/2] usb: gadget: goku_udc: fix kobject warning on probe failure Cheng Lingfei
2026-08-26  9:27   ` Greg Kroah-Hartman
2026-09-01  3:08     ` Cheng Lingfei [this message]

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=tencent_CD7E18210FC0A874E644DBB097794EE29C09@qq.com \
    --to=chenglingfei@foxmail.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=peter.chen@nxp.com \
    --cc=stern@rowland.harvard.edu \
    --cc=syzbot+06ec7624018233e17113@syzkaller.appspotmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.