From: sashiko-bot@kernel.org
To: "Igor Skalkin" <igor.skalkin@oss.qualcomm.com>
Cc: virtualization@lists.linux.dev, linux-usb@vger.kernel.org,
"Michael S. Tsirkin" <mst@redhat.com>,
"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [RFC PATCH v2 2/7] virtio-usb: add protocol header and skeleton dual-role driver
Date: Tue, 01 Dec 2026 17:52:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-243909@kernel.org> (raw)
In-Reply-To: <50920b37d1ea7344ca50350c2bf795beec0c927c.1796144390.git.igor.skalkin@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] virtio-usb: missing validation of vusb->nports in
virtio_usb_probe()
- [Medium] virtio-usb: missing error check after virtio_find_vqs() in
virtio_usb_find_vqs()
- [Low] virtio-usb: inaccurate kernel-doc comments in controller.c and
controller.h
--
commit 06d3f56e0e8338e08d4921c33eb3c4f7d9b9afec
Author: Aiswarya Cyriac <aiswarya.cyriac@oss.qualcomm.com>
virtio-usb: add protocol header and skeleton dual-role driver
This commit adds the UAPI protocol header and the initial skeleton for the
dual-role virtio-usb controller driver, including probe/remove plumbing
and per-port state allocation.
> diff --git a/drivers/usb/virtio_usb/controller.c b/drivers/usb/virtio_usb/controller.c
> new file mode 100644
> index 0000000000000..4fcf3d7a6107f
> --- /dev/null
> +++ b/drivers/usb/virtio_usb/controller.c
> @@ -0,0 +1,155 @@
[ ... ]
> +/**
> + * virtio_usb_find_vqs() - Enumerate and initialize all virtqueues.
> + * @vusb: VirtIO usb device.
> + *
> + * Context: Any context.
> + * Return: 0 on success, -errno on failure.
> + */
> +static int virtio_usb_find_vqs(struct virtio_usb *vusb)
> +{
> + unsigned int nvqs = vusb->nvqs, i;
> + struct virtqueue **vqs = NULL;
> + int rc = -ENOMEM;
> +
> + vqs = kcalloc(nvqs, sizeof(void *), GFP_KERNEL);
> + if (!vqs)
> + return -ENOMEM;
> +
> + struct virtqueue_info *vqs_info =
> + kcalloc(nvqs, sizeof(*vqs_info), GFP_KERNEL);
> + if (!vqs_info) {
> + rc = -ENOMEM;
> + goto on_exit;
> + }
> + for (i = 0; i < nvqs; i++) {
> + vqs_info[i].name = vusb->vqueues[i].name;
> + vqs_info[i].callback = vusb->vqueues[i].callback;
> + }
> + rc = virtio_find_vqs(vusb->vdev, nvqs, vqs, vqs_info, NULL);
> +
> + kfree(vqs_info);
> +
> + for (i = 0; i < nvqs; i++) {
> + vusb->vqueues[i].vqueue = vqs[i];
> + spin_lock_init(&vusb->vqueues[i].lock);
> + }
> +on_exit:
> + kfree(vqs);
> + return rc;
> +}
[Severity: Medium]
Should virtio_usb_find_vqs() check rc and jump to on_exit before copying
vqs[] into vusb->vqueues[]?
When virtio_find_vqs() fails partway through setting up virtqueues, the
transport leaves an ERR_PTR in the failed vqs[k] slot and frees earlier
queues via del_vqs() without clearing vqs[0..k-1]. Once later patches in
the series set nvqs > 0 and unwind probe failures through
virtio_usb_remove() -> vusb->vqueues[i].stop(), stop() tests
if (vq->vqueue) and passes these dangling or ERR_PTR pointers to
virtqueue_disable_cb().
[ ... ]
> +static int virtio_usb_probe(struct virtio_device *vdev)
> +{
> + struct virtio_usb *vusb;
> + unsigned int nvqs = 0;
> + int rc = 0;
> +
> + vusb = devm_kzalloc(&vdev->dev, sizeof(*vusb), GFP_KERNEL);
> + if (!vusb)
> + return -ENOMEM;
> +
> + vusb->vdev = vdev;
> + vdev->priv = vusb;
> +
> + virtio_cread_le(vdev, struct virtio_usb_config, ports, &vusb->nports);
> +
> + vusb->vports = devm_kcalloc(&vdev->dev, vusb->nports,
> + sizeof(*vusb->vports), GFP_KERNEL);
> + if (!vusb->vports)
> + return -ENOMEM;
[Severity: Medium]
Should virtio_usb_probe() validate vusb->nports before passing it to
devm_kcalloc()?
If the device reports 0 ports, devm_kcalloc() returns ZERO_SIZE_PTR, which
passes the !vusb->vports check and leaves a non-dereferenceable pointer in
vusb->vports. Conversely, because struct virtio_usb_config.ports is 32
bits while struct virtio_usb_dev_cmd_hdr and struct virtio_usb_request use
__le16 for port, a bogus large value from the device can exceed the 16-bit
wire field or trigger a page allocator warning when the allocation size
exceeds KMALLOC_MAX_SIZE.
> diff --git a/drivers/usb/virtio_usb/controller.h b/drivers/usb/virtio_usb/controller.h
> new file mode 100644
> index 0000000000000..5a47c9ca52add
> --- /dev/null
> +++ b/drivers/usb/virtio_usb/controller.h
> @@ -0,0 +1,84 @@
[ ... ]
> +/**
> + * struct virtio_usb_queue - Virtqueue wrapper structure.
> + * @name: Name of the virtqueue.
> + * @callback: Used to synchronize access to a virtqueue.
> + * @vqueue: Underlying virtqueue.
> + * @lock: Used to synchronize access to a virtqueue.
> + * @process: queue process callback function
> + * @stop: queue stop callback function
> + */
[Severity: Low]
This isn't a bug, but @callback has the description from @lock copy-pasted
over it, and the kernel-doc header for virtio_usb_find_vqs() in
controller.c says "Context: Any context." even though it allocates with
GFP_KERNEL and calls virtio_find_vqs().
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796144390.git.igor.skalkin@oss.qualcomm.com?part=2
next prev parent reply other threads:[~2026-12-01 17:52 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 16:08 [PATCH 0/8] virtio-usb: add dual-role virtio USB driver Igor Skalkin
2026-09-24 16:09 ` [PATCH 1/8] virtio-usb: add protocol header and skeleton dual-role driver Igor Skalkin
2026-09-24 16:23 ` sashiko-bot
2026-09-25 5:14 ` Greg Kroah-Hartman
2026-09-28 14:19 ` Igor Skalkin
2026-09-25 5:21 ` Greg Kroah-Hartman
2026-09-28 14:14 ` Igor Skalkin
2026-09-24 16:09 ` [PATCH 2/8] virtio-usb: add host role (USB Host Controller) support Igor Skalkin
2026-09-24 16:25 ` sashiko-bot
2026-09-25 5:18 ` Greg Kroah-Hartman
2026-09-28 14:01 ` Igor Skalkin
2026-09-24 16:09 ` [PATCH 3/8] virtio-usb: add device role (USB Device " Igor Skalkin
2026-09-24 16:28 ` sashiko-bot
2026-09-24 16:09 ` [PATCH 4/8] virtio-usb: add OTG role query support Igor Skalkin
2026-09-24 16:19 ` sashiko-bot
2026-09-24 16:09 ` [PATCH 5/8] virtio-usb: add USB On-The-Go role-switching support Igor Skalkin
2026-09-24 16:24 ` sashiko-bot
2026-09-24 16:09 ` [PATCH 6/8] virtio-usb: rework endpoint lifecycle to an async split-phase state machine Igor Skalkin
2026-09-24 16:30 ` sashiko-bot
2026-09-24 16:09 ` [PATCH 7/8] virtio-usb: add SuperSpeed device-role support Igor Skalkin
2026-09-24 16:35 ` sashiko-bot
2026-09-24 16:09 ` [PATCH 8/8] virtio-usb: support a guest UDC name prefix from the bind event Igor Skalkin
2026-09-24 16:35 ` sashiko-bot
2026-09-25 5:17 ` [PATCH 0/8] virtio-usb: add dual-role virtio USB driver Greg Kroah-Hartman
2026-09-28 13:55 ` Igor Skalkin
2026-09-28 14:44 ` Greg Kroah-Hartman
2026-09-28 15:56 ` Igor Skalkin
2026-09-28 16:10 ` Greg Kroah-Hartman
2026-09-29 9:47 ` Michael S. Tsirkin
2026-09-29 16:01 ` Greg Kroah-Hartman
2026-09-29 19:02 ` Vasilii Ianikeev
2026-09-29 19:58 ` Vasilii Ianikeev
2026-12-01 17:35 ` [RFC PATCH v2 0/7] " Igor Skalkin
2026-12-01 17:35 ` [RFC PATCH v2 1/7] uapi: virtio_ids: reserve ID for virtio USB device Igor Skalkin
2026-12-01 17:35 ` [RFC PATCH v2 2/7] virtio-usb: add protocol header and skeleton dual-role driver Igor Skalkin
2026-12-01 17:52 ` sashiko-bot [this message]
2026-12-01 17:35 ` [RFC PATCH v2 3/7] virtio-usb: add host role (USB Host Controller) support Igor Skalkin
2026-12-01 18:09 ` sashiko-bot
2026-12-01 17:35 ` [RFC PATCH v2 4/7] virtio-usb: add device role (USB Device " Igor Skalkin
2026-12-01 18:13 ` sashiko-bot
2026-12-01 17:35 ` [RFC PATCH v2 5/7] virtio-usb: add per-port role query support Igor Skalkin
2026-12-01 17:54 ` sashiko-bot
2026-12-01 17:35 ` [RFC PATCH v2 6/7] virtio-usb: add host/device role switch support Igor Skalkin
2026-12-01 18:00 ` sashiko-bot
2026-12-01 17:35 ` [RFC PATCH v2 7/7] virtio-usb: support a guest UDC name prefix from the bind event Igor Skalkin
2026-12-01 17:50 ` sashiko-bot
2026-12-01 17:49 ` [RFC PATCH v2 0/7] virtio-usb: add dual-role virtio USB driver Michael S. Tsirkin
2026-12-01 18:14 ` sashiko-bot
2026-12-01 20:09 ` Greg Kroah-Hartman
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-243909@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=eperezma@redhat.com \
--cc=igor.skalkin@oss.qualcomm.com \
--cc=linux-usb@vger.kernel.org \
--cc=mst@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=virtualization@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.