From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796402014; b=T3tkCJLnnQQbYBxU8U4MJb5TxOoxl3WkNJQlpDuj9Udm8GT4r3LLvsCngJAuDRfl3Uxy xT1odrExJfKMKrecPD6TKnsufLiPPciH0rUP7yxJnfgAN9LM5a0Pac4wJAc9SOC+ELS2z KdSYw+ViSNJ5qBxRq7esZsruWh53cR68IgXJxxsJ8SgU011tEmoaK0qEqVskv6ivI2AfH AY5WXY4iBBbDYMcFNIawolyabYmvDZwBIKm0+OM0gWTFChtqJeID5W3hzie7BV+3Cxu54 CYBw5UUAK1Ss11EFP/CiBfPwnUMdZAWLAWvqm8vx/SsF3zkzucVA+04w4dUp4SwqgOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796402014; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=04Vlmn69xbudZfAHzrGjjA3EH1GIhR2GBe5aFkzXaj0=; b=UFFtHLq1ulCm8T5ppbaFHGr9apESPzcjCOqWqt1zdju9YMW3Yia1OQCvP6Bi3O4W62ir tU+cghXqoFt61S+oqpK1qyVc5CaUrB6vgbmUDSi+ZeBDuHUscFowVrVJ4JJtiGBMazFl/ XLHV/Qu+vPfSB4GFjt75KSbmzW25gXTcCAzb/vJKabuylG7HNb2sWR/wlEyk/ODn9hFjE ofG5zLwumXDEIJ4o9WtiJSSGKS3/u5ar9JlRKqPP4xXc5v41iii6SuyIpMqmlXGVonQDh 3SBn6HrYpaHiYuJocBUgIcA/oonaKkBF4G63Q+e01KxMqpz3eE+yWNi5FY2x2R6Ri+A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=CMtdzpfp; arc=none smtp.remote-ip=74.125.82.47 Received: from mail-dl1-f47.google.com (mail-dl1-f47.google.com [74.125.82.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41988606A322 for ; Fri, 4 Dec 2026 16:33:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 41988606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=CMtdzpfp Received: by mail-dl1-f47.google.com with SMTP id a92af1059eb24-1b59dfe466bso1723804c88.1 for ; Fri, 04 Dec 2026 08:33:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796402013; x=1797006813; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=04Vlmn69xbudZfAHzrGjjA3EH1GIhR2GBe5aFkzXaj0=; b=CMtdzpfp8IHOupRWcNx+w/DL3/ExYE8uF3wl5C+ZnPedJL5V4XOrrn95PwtJelTGSl XJo7PXaTQQlO6Ff+Ie93qht0tjS8vbCUpQ2b9cxq0bNpxyXvwROT0cc24g9/YamuVqqq +KjHuxGLww/13i+zMK0grAF4lVYjvbPKFAihyt7UCs2umIrWIc7ccc2kYaa3YfWEMWzh zRyvgkeiWhl0qKXxHkJSVBcvomQ/sA4LfXc0E+jetLDR/MEXmMr2RQ4UMw+Du7HNL02m 1w+GO0VC7nmYMaxkyn80oEns4FhcnIlJSyLVcF6qGeXyg22eyGPDpYlvKHlRt/eV6nBv 0uew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796402013; x=1797006813; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=04Vlmn69xbudZfAHzrGjjA3EH1GIhR2GBe5aFkzXaj0=; b=ZRrOc41ojIdSbPG/xjMrGIPSvCbay5iGZGIpsJ04WNsXyfBMHvUm+SxV3R9ZEO2j/c i9qomlHORXjRKvz5RoNtNomvqk01pxTRwBWt5ydEI1XXkGu2iuE2Ba78nECwHFF24yoG MRCsDfPEfMvUbuupkm6AvAlddA739PeKjzRInhcPCgIUBzLk3O6AUCCdct3XW0eP4GQS Mio2v+MG+YPJK4JE1DlYPE/9PGFHo3n/7XwU/gGFL/dUV7JCYtTE2wC7U5mM/pPfMqq0 zuhA/EgJVKuzzcRe5fMz/ab1qViFQc3W+NZTHDkns1OCUwCA22F19/neco+fa8BXBb/9 cqKg== X-Forwarded-Encrypted: i=1; AL+hErGQc72oa3rYI4ZGhVxjrFN6nejaDXuCw5o3tSmxKJTiib+NB3owjZeCg4Kczc74aKS8IzjulhKwMoucEsk=@vger.kernel.org X-Gm-Message-State: APuU4Z9NfSY6zf8fdWY/kEmw84U8bt3M4xhyl2I4Q5ztjwI5qnuIF9Rr vAI7cPJ8SrgsMWiDCd2X2m71AdwNb96aqG8xxNAQnw/tQcsubHepNPvVAMIjFGbH8cEFjw== X-Gm-Gg: AZFdTZepXcLn8ICNzzlmJ3jtWk7N3gWbqMnVinO6OHYQRPbX9XhztzkOhwkygNSn0lU DNsg9sgKxgdg+Yo/22ClzX/ID3JwWKMKLlpIztlTzPyFB/+oZXQSFTi3aTVUMo7kqgWKwx3N+pN fag+TBiEaaDZen7/DQS+WflyLBAiP9qHKBQ0/DcvbAOQ6Cf/ZBwPETsAl6y4xmRAbHInQXK24xc Zy958/XTUa2ivzhHx9zu+709M4FUbBQ48zlHbpEdKHbFSanJOj5b/7YmB/wg3AbMEvutWowD68M C61svaJAuYicTjYaJ7mg8LoxvktqdfYBAWa+E6Pw/DY5hR0BiXPAMhqj9s2Ni4fa6VskfO7yF+o vKX6h3wuLJPS2dKaMDCfBFH0TKxGQXx/JLdrxEbl7l7eL05Z7e2CF9LAl6+dXKh8UNkKiY16v8p y6qsvxh6GSanURm+fgM/FlZF7UX5GxF2MiarIilepFbON+XHtAeuFsokUD6M4vib7sytvuo136X wIy/ooXPLnLNfsBqMLkSSyDQrQdtusjOAF1N+cvr7LqRY3DKrydyVeSEknCeQkcOfXsNYuRphRd UW1Xfr2kNXiRClBDYkBf7o2cOZkhhs+eYQss6NNDzU6c50GrNeDiXZcBjPriAVxgvbBzsNmtTkS Qao4aF8HgEEQwaUc/WMcNzM1qx9x0lAy35iRVB5ownQkZjt05lmW8QB/Fn6CCne6rFVeiQ+6bmI XCZl0yCyvdUq0VKF7KtqFVfL10eOnVSKXZyR0e/sl7Mg== X-Received: by 2002:a05:7022:285:20b0:1b5:9f79:cbf5 with SMTP id a92af1059eb24-1b5d7114ea2mr2151649c88.35.1796402013409; Fri, 04 Dec 2026 08:33:33 -0800 (PST) Received: from kapoor.iiserb.ac.in ([203.18.51.239]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d642de41sm7844767c88.3.2026.12.04.08.33.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 08:33:32 -0800 (PST) From: Arnav Kapoor To: Yury Norov Cc: Rasmus Villemoes , Jonathan Cameron , Andy Shevchenko , linux-kernel@vger.kernel.org, Arnav Kapoor Subject: [PATCH 2/2] bitfield: kunit: test FIELD_FIT() with values that overflow the shift Date: Fri, 4 Dec 2026 22:03:12 +0530 Message-ID: <20261204163317.924658-3-kapoorarnav43@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261204163317.924658-1-kapoorarnav43@gmail.com> References: <20261204163317.924658-1-kapoorarnav43@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Check that FIELD_FIT() rejects values that are only too big once they are shifted into the field: BIT(24) and S32_MIN against a 2-bit field at bit 8, as a u32 mask and as GENMASK() (an unsigned long, so 32 bits on 32-bit architectures), and BIT(24) against a field at the top of a u32. The old implementation shifted their high bits out and accepted them. Also cover the plain cases: the largest value that fits, the next one, and -1. Signed-off-by: Arnav Kapoor --- lib/tests/bitfield_kunit.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/tests/bitfield_kunit.c b/lib/tests/bitfield_kunit.c index 5ccd86f61896..3fdc8f997ddb 100644 --- a/lib/tests/bitfield_kunit.c +++ b/lib/tests/bitfield_kunit.c @@ -125,6 +125,30 @@ static void __init test_bitfields_variables(struct kunit *context) CHECK(u64, 0x0000001f8000000ull); } +#define CHECK_FIT(mask, val, res) do { \ + bool fit = FIELD_FIT(mask, val); \ + \ + KUNIT_EXPECT_EQ_MSG(context, fit, res, \ + "FIELD_FIT(%s, %s)", #mask, #val); \ + } while (0) + +static void __init test_bitfields_fit(struct kunit *context) +{ + s32 big = BIT(24), neg = -1, min = S32_MIN; + u32 three = 3, four = 4; + + CHECK_FIT((u32)0x00000300, three, true); + CHECK_FIT((u32)0x00000300, four, false); + CHECK_FIT((u32)0x00000300, neg, false); + /* These must not pass by having their high bits shifted out */ + CHECK_FIT((u32)0x00000300, big, false); + CHECK_FIT((u32)0x00000300, min, false); + CHECK_FIT((u32)0xf0000000, big, false); + + CHECK_FIT(GENMASK(9, 8), big, false); + CHECK_FIT(GENMASK(9, 8), min, false); +} + #ifdef TEST_BITFIELD_COMPILE static void __init test_bitfields_compile(struct kunit *context) { @@ -140,6 +164,7 @@ static void __init test_bitfields_compile(struct kunit *context) static struct kunit_case __refdata bitfields_test_cases[] = { KUNIT_CASE(test_bitfields_constants), KUNIT_CASE(test_bitfields_variables), + KUNIT_CASE(test_bitfields_fit), {} }; -- 2.53.0