From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796147548; b=zULiGHVHkZFxCLeHwKHyWILNG+E8a7NrRsIwJ7f7A7mzujiE2o+Rly/Kt/l06yBe6tfH JOzwgYvArwsNZ83WXElFJ2P49+SL9o1puG0swlh2eqnQrqF+FWngiE1PDru60jffOlt1D gILd6Fu+8QMhWzADje0+qthTWFBf36IQZ3lCBkU3+qz5aW43x9J2CTSMrwC53/ATaksfC iVjjzxfsHvDthwQze/V3s+TDVS9sxtwx+c9yuhSlRDbpOlcnDH1zatCumW79J+n6UkkH6 5G56CCeFyipegLWOJb6dEBoQkAVfrLtFe/h9U5AETn7qV2WOa8+0RilOaHn3KIla2jw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796147548; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=uzP/IunBe4lq6PPsktx3BcTfzEEPXpt8nqZNLVwWDPw=; b=l9ciFXG0m46ItQGne3ZnR4MezR18oCJtGGYtqrR+Ujoq2hMs7XcVdfCkfQxE6R2bTbca 4zMKLN5enes0ANl/ksBWZdYAQSLKu0Np5eb2RPe34d8qg6qt14J1mxCPRYiTjuHWHcCx9 bPdPhmZHnO9/g8u992X9/7U2CVUEvuBE40M4oupjYqUmnnvRVKMYqWRsA+RkpbTqXOOGH D8AexgQYExsJtqPLTvjZyKGoUb6hBa4rqwG6S9zPxXu8w68yrx63xqJsn6NmMsxRd1BDX +YI1BoXFom+ETDlmyv24w2E1KPqqSQABdMpnCTEMWabtrd1pJS3ZmoPMm6/HvPDeKOw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=j7FlgH6w; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE75C606A31A; Tue, 1 Dec 2026 17:52:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=j7FlgH6w Received: by smtp.kernel.org (Postfix) with ESMTPSA id 671D81F000C1; Tue, 1 Dec 2026 17:52:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796147548; bh=uzP/IunBe4lq6PPsktx3BcTfzEEPXpt8nqZNLVwWDPw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=j7FlgH6waN5VupBDX3CNttN+kUBqI1y2Vxjvg46/rYDJX+1dsJcMiSYuC4BRjCCwi D79PwDhwJK1HO366CiwFwxJCjIdXuq+4U8/eRhdR1th8c5Ey8U8FD3YMzvbax49Cbr WB0PvqWmpmIPUwVoIUzzacUcvAdn5Rh5ThikaHlkvSQJnY47yUOfLzDpQxjWDka6rr YTq0Y2biclreiy1USMRluPJdUF6fd+eaWIP4ufucALmFl7FfOsOaz2CrUVACLK267m jEOEl6oQzA1+rnGceI0XUuzA/qTtQJn4SGC74Z0/OVUeXRysm6xNSXdxa1DgEN/v42 kGVzgGwpp4daw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH v2 2/7] virtio-usb: add protocol header and skeleton dual-role driver Reply-To: sashiko-reviews@lists.linux.dev To: "Igor Skalkin" Cc: virtualization@lists.linux.dev, linux-usb@vger.kernel.org, "Michael S. Tsirkin" , "Eugenio Perez" In-Reply-To: <50920b37d1ea7344ca50350c2bf795beec0c927c.1796144390.git.igor.skalkin@oss.qualcomm.com> References: <20260924160907.145405-1-igor.skalkin@oss.qualcomm.com> <50920b37d1ea7344ca50350c2bf795beec0c927c.1796144390.git.igor.skalkin@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 17:52:27 +0000 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 =3D vusb->nvqs, i; > + struct virtqueue **vqs =3D NULL; > + int rc =3D -ENOMEM; > + > + vqs =3D kcalloc(nvqs, sizeof(void *), GFP_KERNEL); > + if (!vqs) > + return -ENOMEM; > + > + struct virtqueue_info *vqs_info =3D > + kcalloc(nvqs, sizeof(*vqs_info), GFP_KERNEL); > + if (!vqs_info) { > + rc =3D -ENOMEM; > + goto on_exit; > + } > + for (i =3D 0; i < nvqs; i++) { > + vqs_info[i].name =3D vusb->vqueues[i].name; > + vqs_info[i].callback =3D vusb->vqueues[i].callback; > + } > + rc =3D virtio_find_vqs(vusb->vdev, nvqs, vqs, vqs_info, NULL); > + > + kfree(vqs_info); > + > + for (i =3D 0; i < nvqs; i++) { > + vusb->vqueues[i].vqueue =3D 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 =3D 0; > + int rc =3D 0; > + > + vusb =3D devm_kzalloc(&vdev->dev, sizeof(*vusb), GFP_KERNEL); > + if (!vusb) > + return -ENOMEM; > + > + vusb->vdev =3D vdev; > + vdev->priv =3D vusb; > + > + virtio_cread_le(vdev, struct virtio_usb_config, ports, &vusb->nports); > + > + vusb->vports =3D 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(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796144390.gi= t.igor.skalkin@oss.qualcomm.com?part=3D2