Article View: muc.lists.netbsd.source-changes
Article #5Re: CVS commit: src/sys/dev/usb
From: Taylor R Campbell
Date: Fri, 23 Oct 2026 02:23
Date: Fri, 23 Oct 2026 02:23
70 lines
4200 bytes
4200 bytes
> Module Name: src
> Committed By: joe
> Date: Thu Oct 22 17:17:47 UTC 2026
>
> Modified Files:
> src/sys/dev/usb: ohci.c
>
> Log Message:
> use PR_ZERO on on pool allcoated memory and get rid of memset.
>
> currently, xfer is zeroed using the wrong size.
> remove it and simplify code.
I think this change may not be correct. I don't think pool_cache_get
respects PR_ZERO. Perhaps we should add an assertion about this and
audit the system for it (or make it work by judiciously adding a
memset if PR_ZERO is passed).
I also suspect there was not a bug here before. The code was
confusing because of the declared types, but correct:
--- ohci.c 31 Mar 2025 14:46:42 -0000 1.330
+++ ohci.c 22 Oct 2026 17:17:47 -0000 1.331
@@ -1112,14 +1112,12 @@ ohci_allocx(struct usbd_bus *bus, unsign
ohci_softc_t *sc = OHCI_BUS2SC(bus);
struct usbd_xfer *xfer;
- xfer = pool_cache_get(sc->sc_xferpool, PR_WAITOK);
- if (xfer != NULL) {
- memset(xfer, 0, sizeof(struct ohci_xfer));
-
+ xfer = pool_cache_get(sc->sc_xferpool, PR_WAITOK | PR_ZERO);
#ifdef DIAGNOSTIC
+ if (xfer != NULL) {
xfer->ux_state = XFER_BUSY;
-#endif
}
+#endif
Note that the declared type of xfer is struct usbd_xfer *, so with
this context it looks like memset(xfer, 0, sizeof(struct ohci_xfer))
is wrong and maybe should have been memset(xfer, 0, sizeof(*xfer)).
But the object allocated from sc->sc_xferpool actually sized for
struct ohci_xfer, so the original memset was fine:
sc->sc_xferpool = pool_cache_init(sizeof(struct ohci_xfer), 0, 0, 0,
"ohcixfer", NULL, IPL_USB, NULL, NULL, NULL);
So I think this change did not fix a bug -- it actually _introduced_ a
bug by not zeroing the object, and should be reverted.
Perhaps we should rephrase this code to make it clearer (note that
pool_cache_get(sc->sc_xferpool PR_WAITOK) never fails, so there is no
need for a null test):
struct ohci_xfer *ox;
struct usbd_xfer *xfer;
ox = pool_cache_get(sc->sc_xferpool, PR_WAITOK);
memset(ox, 0, sizeof(*ox));
xfer = &ox->xfer;
#ifdef DIAGNOSTIC
xfer->ux_state = XFER_BUSY;
#endif
return xfer;
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID:
<20261023022326.D40FA84E80@mail.netbsd.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mailReferences:
<20261022171747.B3FEBFA2D@cvs.NetBSD.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail From: Taylor R Campbell <riastradh@NetBSD.org> Newsgroups: muc.lists.netbsd.source-changes Subject: Re: CVS commit: src/sys/dev/usb Date: Fri, 23 Oct 2026 02:23:25 +0000 Organization: Newsgate at muc.de e.V. Sender: source-changes-d-owner@NetBSD.org Approved: news-admin@muc.de Distribution: world Message-ID: <20261023022326.D40FA84E80@mail.netbsd.org> References: <20261022171747.B3FEBFA2D@cvs.NetBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2"; logging-data="75345"; mail-complaints-to="news-admin@muc.de" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netbsd.org; s=20240131; t=1792722211; bh=XUJAyEzkygR1Az8PuCjjz7c4gxAx6iJnKTSUhUYuOWE=; h=To:CC:Subject:In-reply-to:Date:From:List-Id:List-Unsubscribe; b=c3QJBn6jNZgZiMWiOh7Ba3LgDiVgPsg7Onk8bo1tLiCCQCLBopldU6P/B4PHXNxpc TOvjpRM8r8edm1vELQCARNHFxxyA33zNilZ9a/dJndFQCWAsh/Pm4IhcjFXG+yyPFx hHEnw5eS26F6hQ4M7nTW4+J2v4k97ThHqZrLoay8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netbsd.org; s=20240131; t=1792722206; bh=XUJAyEzkygR1Az8PuCjjz7c4gxAx6iJnKTSUhUYuOWE=; h=To:CC:Subject:In-reply-to:Date:From; b=rYULhQzk2vXOVSCFoAOrOgabQ6uajTsXGlJhRbjQ0jJGJF0L52vzD4hsdXvlsvbNu 6AyzPfNKYxML7cSVu8Uk87881IXM/HBXW0+hdfW76md2QrPg3KvU2R4dosCr9on9dA 9A8YBugBQ9e43VKXMYnNBECNZVkOSzNyrHmO6f7I= In-reply-to: <20261022171747.B3FEBFA2D@cvs.NetBSD.org> (joe@NetBSD.org) Precedence: bulk X-Newsgate-Id: f02c70b8849f+ X-No-Archive: Yes