All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alexey Charkov" <alchark@flipper.net>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v3 2/3] usb: gadget: udc: Forget a deactivation when the gadget driver unbinds
Date: Tue, 17 Nov 2026 13:06:55 +0000	[thread overview]
Message-ID: <sashiko-outbox-218838@kernel.org> (raw)
In-Reply-To: <20261117-udc-connect-v3-2-9413b491d213@flipper.net>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: gadget: configfs: stale cdev->deactivations after failed
  bind
--

commit 08b8abaff4ff275aaa5fed522a9a3de79db20527
Author: Alexey Charkov <alchark@flipper.net>

usb: gadget: udc: Forget a deactivation when the gadget driver unbinds

This commit clears gadget->deactivated under connect_lock in the UDC core
upon driver unbind and bind failure, removing the unlocked reset from
configfs_composite_unbind().

> diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
> index 577bc15f61a15..449b303c2f813 100644
> --- a/drivers/usb/gadget/udc/core.c
> +++ b/drivers/usb/gadget/udc/core.c
> @@ -1705,6 +1705,11 @@ static int gadget_bind_driver(struct device *dev)
>  		dev_err(&udc->dev, "failed to start %s: %d\n",
>  			driver->function, ret);
>  
> +	/* The driver may have deactivated the gadget before failing */
> +	mutex_lock(&udc->connect_lock);
> +	gadget->deactivated = false;
> +	mutex_unlock(&udc->connect_lock);
> +
>  	mutex_lock(&udc_lock);
>  	udc->driver = NULL;
>  	driver->is_bound = false;

[Severity: Medium]
Can clearing gadget->deactivated on the err_bind path leave it out of sync
with cdev->deactivations for a configfs gadget?

In configfs_composite_bind() -> usb_add_function(), if a function has
bind_deactivated set (such as f_uvc or f_obex), usb_function_deactivate()
is called before function->bind():

drivers/usb/gadget/composite.c:usb_function_deactivate() {
	...
	if (cdev->deactivations == 0) {
		spin_unlock_irqrestore(&cdev->lock, flags);
		status = usb_gadget_deactivate(cdev->gadget);
		spin_lock_irqsave(&cdev->lock, flags);
	}
	if (status == 0)
		cdev->deactivations++;
	...
}

If function->bind() or a later step in configfs_composite_bind() fails,
driver->bind() returns an error to gadget_bind_driver() and jumps to
err_bind without calling configfs_composite_unbind(), which is the only
place that resets cdev->deactivations = 0.  Clearing gadget->deactivated
here leaves gi->cdev.deactivations non-zero on the configfs gadget_info
instance.

When binding the same configfs gadget is retried, usb_function_deactivate()
sees cdev->deactivations != 0 and skips usb_gadget_deactivate(), so the UDC
enables pullup before userspace activates the function, and subsequent
usb_function_activate() calls never decrement cdev->deactivations back to
zero.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-udc-connect-v3-0-9413b491d213@flipper.net?part=2

  reply	other threads:[~2026-11-17 13:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 12:48 [PATCH v3 0/3] usb: gadget: udc: Rework when the gadget connects Alexey Charkov
2026-11-17 12:48 ` [PATCH v3 1/3] usb: gadget: udc: Clear a pending connection when starting the UDC Alexey Charkov
2026-11-17 13:03   ` sashiko-bot
2026-11-17 12:48 ` [PATCH v3 2/3] usb: gadget: udc: Forget a deactivation when the gadget driver unbinds Alexey Charkov
2026-11-17 13:06   ` sashiko-bot [this message]
2026-11-17 12:48 ` [PATCH v3 3/3] usb: gadget: udc: Decide on connecting in one place Alexey Charkov
2026-11-17 13:19   ` sashiko-bot

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=sashiko-outbox-218838@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alchark@flipper.net \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.