The branch main has been updated by emaste:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=1efd69f933b6ad4177ecda78cf4891aa9a1e8f6b

commit 1efd69f933b6ad4177ecda78cf4891aa9a1e8f6b
Author:     Ed Maste <ema...@freebsd.org>
AuthorDate: 2024-06-24 16:21:19 +0000
Commit:     Ed Maste <ema...@freebsd.org>
CommitDate: 2024-06-24 19:36:11 +0000

    p9fs: move NULL check immediately after allocation
    
    Reported by:    Shawn Webb (HardenedBSD)
    Reviewed by:    dfr
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D45719
---
 sys/dev/virtio/p9fs/virtio_p9fs.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/sys/dev/virtio/p9fs/virtio_p9fs.c 
b/sys/dev/virtio/p9fs/virtio_p9fs.c
index 48430b4f6b67..811faff6cd93 100644
--- a/sys/dev/virtio/p9fs/virtio_p9fs.c
+++ b/sys/dev/virtio/p9fs/virtio_p9fs.c
@@ -332,6 +332,11 @@ vt9p_attach(device_t dev)
        cv_init(&chan->submit_cv, "Conditional variable for submit queue" );
        chan->max_nsegs = MAX_SUPPORTED_SGS;
        chan->vt9p_sglist = sglist_alloc(chan->max_nsegs, M_NOWAIT);
+       if (chan->vt9p_sglist == NULL) {
+               error = ENOMEM;
+               P9_DEBUG(ERROR, "%s: Cannot allocate sglist\n", __func__);
+               goto out;
+       }
 
        /* Negotiate the features from the host */
        virtio_set_feature_desc(dev, virtio_9p_feature_desc);
@@ -367,12 +372,6 @@ vt9p_attach(device_t dev)
        SYSCTL_ADD_STRING(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, 
"p9fs_mount_tag",
            CTLFLAG_RD, chan->mount_tag, 0, "Mount tag");
 
-       if (chan->vt9p_sglist == NULL) {
-               error = ENOMEM;
-               P9_DEBUG(ERROR, "%s: Cannot allocate sglist\n", __func__);
-               goto out;
-       }
-
        /* We expect one virtqueue, for requests. */
        error = vt9p_alloc_virtqueue(chan);
 

Reply via email to