Linux USB
 help / color / mirror / Atom feed
From: Aristo Chen <aristo.chen@canonical.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Neill Kapron <nkapron@google.com>
Cc: Alan Stern <stern@rowland.harvard.edu>,
	Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>,
	Jassi Brar <jassisinghbrar@gmail.com>,
	linux-usb@vger.kernel.org,
	Aristo Chen <aristo.chen@canonical.com>
Subject: [PATCH 0/2] usb: gadget: fix max3420_udc endpoint index and bind without pullup
Date: Wed, 25 Nov 2026 09:05:28 +0000	[thread overview]
Message-ID: <20261125092004.15562-1-aristo.chen@canonical.com> (raw)

This series fixes two bugs that I found while looking at max3420_udc.

Patch 1 fixes an out of bounds array index in the SETUP handling of
max3420_udc. The endpoint number comes from wIndex, which the host
controls, and the driver uses it without a range check.

Patch 2 fixes the gadget core. Since v6.7, gadget_bind_driver() fails
when the connect step returns an error, and that step returns
-EOPNOTSUPP when the UDC has no pullup callback. So no gadget driver
can bind to such a UDC. This affects max3420_udc and four other UDC
drivers.

Patch 1 comes first so that the bounds check is in place when patch 2
makes the bind work again. Mainline v5.7 to v6.6 have the driver but
not the bind problem, so they only need patch 1.

I do not have the hardware. I tested with a KUnit test under User Mode
Linux that emulates the chip on a fake SPI controller. It gives the
driver SETUP packets and records the answers. With KASAN and UBSAN, on
usb-linus:

  no patch:       the gadget driver does not bind (-EOPNOTSUPP)
  patch 1 only:   the same, the driver still cannot bind
  patch 2 only:   it binds, bad endpoint numbers give UBSAN and KASAN
                  reports
  both patches:   the tests pass, no reports

I also built both files with W=1 for x86_64 and arm64.

I did not test the other UDC drivers that patch 2 affects.

The pullup callbacks of pxa25x_udc, pxa27x_udc and fsl_udc_core can
return -EOPNOTSUPP themselves. This series does not change how the
bind handles that.

The test is not part of this series. I can send it on request.

AI tools were used for this series. The out of bounds index in patch 1
was found by an AI code review of the driver. I used an AI coding
assistant (Claude Code) to write the KUnit test, both patches and their
descriptions. Running that test showed the bind problem that patch 2
fixes. A second AI tool (GitHub Copilot) reviewed the patches. I have
reviewed all of it.

Aristo Chen (2):
  usb: gadget: max3420_udc: fix out of bounds endpoint index from wIndex
  usb: gadget: udc: do not fail bind when the UDC has no pullup callback

 drivers/usb/gadget/udc/core.c        | 9 ++++++---
 drivers/usb/gadget/udc/max3420_udc.c | 8 +++++++-
 2 files changed, 13 insertions(+), 4 deletions(-)


base-commit: b0baaf6cbb16bc773d0c76916aac17c44a6cd557
-- 
2.53.0


             reply	other threads:[~2026-11-25  9:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  9:05 Aristo Chen [this message]
2026-11-25  9:05 ` [PATCH 1/2] usb: gadget: max3420_udc: fix out of bounds endpoint index from wIndex Aristo Chen
2026-11-25  9:05 ` [PATCH 2/2] usb: gadget: udc: do not fail bind when the UDC has no pullup callback Aristo Chen
2026-11-25  9:25 ` [PATCH 0/2] usb: gadget: fix max3420_udc endpoint index and bind without pullup 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=20261125092004.15562-1-aristo.chen@canonical.com \
    --to=aristo.chen@canonical.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jassisinghbrar@gmail.com \
    --cc=krishna.kurapati@oss.qualcomm.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=nkapron@google.com \
    --cc=stern@rowland.harvard.edu \
    /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