From nobody Fri Nov 21 22:44:38 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dCqzC2Wrrz6HtBs for ; Fri, 21 Nov 2025 22:44:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dCqzB6tjrz46Kt for ; Fri, 21 Nov 2025 22:44:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763765079; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QcbMtXMpv+XbBCyC3DQoJ+/gvBw1itJjiABGdT9u1f8=; b=w6M4C6ile9lrs/c6ygV5qeBK3xnsPFIe8ZZJG2cfyoVGN3ZP2DDsufZOKFAJ//W7tro+Wb BbMFb7zeRf+8KFj4Wo7fWz14675bSyn57ccTYn7yshNo9Qyv5t+EX62NZKj/Ndf127U21P w0PEDmsV4bGR/4v03UvtjtLTZjbq2wODemyUV0UY5DwqjUbqasolP1ZyiUZPFVc3C9rgYb 63hGV4IphOWzb8mlEEOAPhMwXS6L3Ad0LsyYQfU6AZQ3jIh2ZMMsMlTY8pTsiD/UKyYMur teZIt3GpynRN9XUnLL7coFolWdgwju+Kbs2bVKlN4tCu+J3GYjWqPc0W+fnjEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763765079; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QcbMtXMpv+XbBCyC3DQoJ+/gvBw1itJjiABGdT9u1f8=; b=ugxZjdDomkfvj5fii0maXt9FcZ6SmGQBcKXoo2Y5r41GH5+njtopVLJPTXplzUBgzyJLr7 /Xbp3lfnqDrtFO3N6FiyTYNMlzH6OiMsgLaNvzYWt6FFchjJTrhiGUsI248CfXhzOGGMiA T1kdxLwvz6xSEwLmbWJCNBap+4NV2SmfQQ/W+ki56K2HUU5ZC0fJQts8dHACznwTpKHBhF 38+5r4Ty5MMVNaRtZEV1ef2HQHIwklJRlzkuv0YQsaFDWtwKuiuyIlCGWR7kWF8UwdaHxF sdgWAkJFFMbHdW5l6ELK9vELd7uODG32YCQd47HiN8KaIlLbVDAFOEpYYLG03Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1763765079; a=rsa-sha256; cv=none; b=it76t4Mm3/JiGOc7cfFv7VkAQgaQLPhQ9qtRjqpA3SdRa1lgf5hUrdoOvZVE3PtUpfRJcx 4WC1FPFm6R1fNVRFnFCt19pVy5JsQtDjuxYw/Hn/Dnlcmu72yryBZMTJ+ls6tnLtGFqEcB g3pIlyvDZJ9GnpLkIezZaArBqInLN1QREj3QQFCsW3eOm+daVlQ9TC5M01t0a9QFwGzm2/ 2LkANSEVMPMHCPPi+uNMcI2e+CAO/abp8hZDALKOhamFBVkkcm+3ok53SKocWxoFMQkEI5 GLf4ifCiY7MKXKB1txDUJvzD25aZUx9UQkkQzlov3bDx2lR2vmzu31qH0H4k2A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dCqzB6DcMzWq1 for ; Fri, 21 Nov 2025 22:44:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3dbe0 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 21 Nov 2025 22:44:38 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: ff3ccf6f1a02 - main - bpf: refactor buffer pre-allocation for BIOCSETIF List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ff3ccf6f1a020800605bca1bec66985eb7be56d3 Auto-Submitted: auto-generated Date: Fri, 21 Nov 2025 22:44:38 +0000 Message-Id: <6920eb56.3dbe0.595b3eac@gitrepo.freebsd.org> The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=ff3ccf6f1a020800605bca1bec66985eb7be56d3 commit ff3ccf6f1a020800605bca1bec66985eb7be56d3 Author: Gleb Smirnoff AuthorDate: 2025-11-21 22:43:47 +0000 Commit: Gleb Smirnoff CommitDate: 2025-11-21 22:43:47 +0000 bpf: refactor buffer pre-allocation for BIOCSETIF This basically refactors 4f42daa4a326f to use less indentation and variables. The code is still not race proof. --- sys/net/bpf.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/sys/net/bpf.c b/sys/net/bpf.c index d80eb8b80016..0ce823412b91 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -1609,33 +1609,28 @@ bpfioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, * Set interface. */ case BIOCSETIF: - { - int alloc_buf, size; + /* + * Behavior here depends on the buffering model. If we're + * using kernel memory buffers, then we can allocate them here. + * If we're using zero-copy, then the user process must have + * registered buffers by the time we get here. + */ + BPFD_LOCK(d); + if (d->bd_bufmode == BPF_BUFMODE_BUFFER && + d->bd_sbuf == NULL) { + u_int size; - /* - * Behavior here depends on the buffering model. If - * we're using kernel memory buffers, then we can - * allocate them here. If we're using zero-copy, - * then the user process must have registered buffers - * by the time we get here. - */ - alloc_buf = 0; - BPFD_LOCK(d); - if (d->bd_bufmode == BPF_BUFMODE_BUFFER && - d->bd_sbuf == NULL) - alloc_buf = 1; + size = d->bd_bufsize; BPFD_UNLOCK(d); - if (alloc_buf) { - size = d->bd_bufsize; - error = bpf_buffer_ioctl_sblen(d, &size); - if (error != 0) - break; - } - BPF_LOCK(); - error = bpf_setif(d, (struct ifreq *)addr); - BPF_UNLOCK(); - break; - } + error = bpf_buffer_ioctl_sblen(d, &size); + if (error != 0) + break; + } else + BPFD_UNLOCK(d); + BPF_LOCK(); + error = bpf_setif(d, (struct ifreq *)addr); + BPF_UNLOCK(); + break; /* * Set read timeout.