From nobody Wed Apr 30 06:01:12 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 4ZnRQ04X37z5tvLp; Wed, 30 Apr 2025 06:01:12 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZnRQ01z0gz3lSD; Wed, 30 Apr 2025 06:01:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745992872; 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=mcnVavJHLuGVBYo6Ycy1unEybr0NDHxpIdFMQCAdwE8=; b=o4L9+G43tDZkK4M0MUqpvnwIzmbCuoAq1HCl9zgxhHeoIWPzRmdfjjiB5ge1UKpAJV4x53 U3P43EVre90DNudbBTRHNqQLyoht7i5ImaQf/Gps5CuO2XefDAi8AbltVVSi66o0T7Hea3 K657+EqJC7jxOvjJplzkL/uzxtTSLhwhtkFSvkbTFDaDibbDzycLrpWiyaA63pb5BMiGAU OLjO5kmW5rF0O64Iy4QPkRxlTGzQRtcEyBV68V0D5/sk7b3hV3wQSzrxR899/AJeLrnBBW 4KWfo3terM1rBPQzbG2aC36g3O42ujjxb6N5pGpk49hqOgCdMzDBNZB4+onfRg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1745992872; a=rsa-sha256; cv=none; b=CU6mZ9Sn7oFuD2twaMDOTQULymHyHQRIJnVvKTtJ+ORNUZrex7VTbQg4G9yc9hVNyZ+aEX Tvw4Gc7qrIKQv/i57MSOdmmjEHum6xEvZmuxSeb/kilOxiwibWWDxWBqNah0BRkEW26S/n /6k2tTu+rPV+jy6eDNjIzHAH2LjjvlINq2JKDldoBUOewK5aKHMT6uuVcdZ8jJQNs3dBFr /VnuzGPEehh3427uiFYGX77qTgxqUhxQaQH32XFvZCd88wG3v7oaTi9UisHrM6DRcVCid0 /H4batPn5WtfX1Wp/Qh2cZCfxfwZSH8fxeWN4yw9u+/TqNBZHYfg49sl+pHOEQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745992872; 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=mcnVavJHLuGVBYo6Ycy1unEybr0NDHxpIdFMQCAdwE8=; b=JbgCgPodH1h+kF7Q0Dwcy8NvtDRkFUCIFWIBkkIrkikSnaiC49vOZz9Q9EqDCwaL3vjrSJ cs14n9jQb2MQJNHTHP0/yiVyiQUZoASMAHBJ2ce0DINMv6LtRxn4MmkUyiOY/AW+Qd58tp fAh9003APPPYbEJwF2b2maTZXTcYCyzJ0HG9VSVpF1pjX3xKZRtY1U2QAA1/R2zi3ooA95 VtQmo1yFjDrGFRyCjEBI9prX/RgL3ctE7rM0HR+8/ME2PpjcKakuejF38XNpJemBaqbrKX jADsRtFjtLvUyamWIW4xsQiHr7x/qTb80emOilMMz1T6npXXp0700L9IeXNMIQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4ZnRQ01KnSztfM; Wed, 30 Apr 2025 06:01:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 53U61C79017696; Wed, 30 Apr 2025 06:01:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53U61Cap017679; Wed, 30 Apr 2025 06:01:12 GMT (envelope-from git) Date: Wed, 30 Apr 2025 06:01:12 GMT Message-Id: <202504300601.53U61Cap017679@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 2e891fce9de5 - main - mbufs: let mc_get() and mc_uiotomc() return a consistent mc when failed 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: 2e891fce9de5f7b1521060916082e1a38ba8920d Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=2e891fce9de5f7b1521060916082e1a38ba8920d commit 2e891fce9de5f7b1521060916082e1a38ba8920d Author: Gleb Smirnoff AuthorDate: 2025-04-30 05:31:41 +0000 Commit: Gleb Smirnoff CommitDate: 2025-04-30 05:31:41 +0000 mbufs: let mc_get() and mc_uiotomc() return a consistent mc when failed This was a documented behavior when functions were introduced, but on second thought it seems easier to do extra work in the leaf functions, instead of putting the burden on KPI users, even if some of the KPI users may not care about consistency. --- sys/kern/kern_mbuf.c | 6 +++--- sys/kern/uipc_mbuf.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_mbuf.c b/sys/kern/kern_mbuf.c index 2b2b032e644c..48886c1e5b0c 100644 --- a/sys/kern/kern_mbuf.c +++ b/sys/kern/kern_mbuf.c @@ -1462,8 +1462,7 @@ m_getjcl(int how, short type, int flags, int size) /* * Allocate mchain of a given length of mbufs and/or clusters (whatever fits - * best). May fail due to ENOMEM. In case of failure state of mchain is - * inconsistent. + * best). May fail due to ENOMEM. */ int mc_get(struct mchain *mc, u_int length, int how, short type, int flags) @@ -1501,8 +1500,9 @@ mc_get(struct mchain *mc, u_int length, int how, short type, int flags) * Fail the whole operation if one mbuf can't be * allocated. */ - if (mb == NULL) { + if (__predict_false(mb == NULL)) { m_freem(mc_first(mc)); + *mc = MCHAIN_INITIALIZER(mc); return (ENOMEM); } } diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index f3e2f13e89ec..377a36287e3e 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -1986,7 +1986,6 @@ m_uiotombuf(struct uio *uio, int how, int len, int lspace, int flags) /* * Copy the contents of uio into a properly sized mbuf chain. - * In case of failure state of mchain is inconsistent. * @param length Limit copyout length. If 0 entire uio_resid is copied. * @param lspace Provide leading space in the first mbuf in the chain. */ @@ -2032,6 +2031,7 @@ mc_uiotomc(struct mchain *mc, struct uio *uio, u_int length, u_int lspace, error = uiomove(mtod(mb, void *), mlen, uio); if (__predict_false(error)) { mc_freem(mc); + *mc = MCHAIN_INITIALIZER(mc); return (error); } mb->m_len = mlen;