Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FA7B47606D; Tue, 21 Jul 2026 21:01:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784667704; cv=none; b=l9AY9hHmP7cyKxEBEZBWEl5Xb65fxGRLm4rctTeqe7eJkUPRFq/JSegGxJFfkR9ya8tEMRlRRUqSwNQ6K5PafIQezBwo1h2DG92RrAJrLXqEiFR9iaMxNmTtKkhbweLN+fg0awHta9qlcZEBQVeU7+9z9xsymw0sDI2yZKV9CuY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784667704; c=relaxed/simple; bh=FogvgCnZ4qPURM/Bmi0QHeogwDVk34SKLl5je16EOPs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PRyHFCpbZNPJT7PKnSNbHi2jnS4KDVDs3UhkGuwm6fX+5lcdWQGjclKQ5mu0/qSGryekL4felPCLcBTV6yuvRljcgN6Yt27NnhoRV/6jm4r74VrwdOgmZVQ2+qlFKs1n/7k5cvyCSVAJs6u7XTwudcSrqbWy2ln2P2g1MpyWYOA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=NSFyc9tz; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="NSFyc9tz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4ACC51F000E9; Tue, 21 Jul 2026 21:01:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784667702; bh=b60CVYESfOskYS1YaIaKV5RMlhwKJ54ngX76GLtAH+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NSFyc9tzS/kV3jQ38iWuY6vzId57WOFxw/7ariBtNpvvqmG/ZZncRHrQxqnNJE3BB 7heFEu7T11niMyovMU+OXx9XAWDBQ364EES09T8p0dsfAH3O0a/mUxJ5AL4xcvQ44h ijaj31j6rbrIpGaikxHcxt2nK0ZC4A7GSy/UXo+8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Andy Shevchenko , Przemek Kitszel , Yury Norov , Alexander Lobakin , "David S. Miller" , Sasha Levin Subject: [PATCH 6.6 1162/1266] bitops: make BYTES_TO_BITS() treewide-available Date: Tue, 21 Jul 2026 17:26:39 +0200 Message-ID: <20260721152507.787860381@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152441.786066624@linuxfoundation.org> References: <20260721152441.786066624@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexander Lobakin [ Upstream commit 7d8296b250f2eed73f1758607926d4d258dea5d4 ] Avoid open-coding that simple expression each time by moving BYTES_TO_BITS() from the probes code to to export it to the rest of the kernel. Simplify the macro while at it. `BITS_PER_LONG / sizeof(long)` always equals to %BITS_PER_BYTE, regardless of the target architecture. Do the same for the tools ecosystem as well (incl. its version of bitops.h). The previous implementation had its implicit type of long, while the new one is int, so adjust the format literal accordingly in the perf code. Suggested-by: Andy Shevchenko Reviewed-by: Przemek Kitszel Acked-by: Yury Norov Signed-off-by: Alexander Lobakin Signed-off-by: David S. Miller Stable-dep-of: 55052184ac90 ("iio: common: st_sensors: honour channel endianness in read_axis_data") Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- include/linux/bitops.h | 2 ++ kernel/trace/trace_probe.c | 2 -- tools/include/linux/bitops.h | 2 ++ tools/perf/util/probe-finder.c | 4 +--- 4 files changed, 5 insertions(+), 5 deletions(-) --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -20,6 +20,8 @@ #define BITS_TO_U32(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u32)) #define BITS_TO_BYTES(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(char)) +#define BYTES_TO_BITS(nb) ((nb) * BITS_PER_BYTE) + extern unsigned int __sw_hweight8(unsigned int w); extern unsigned int __sw_hweight16(unsigned int w); extern unsigned int __sw_hweight32(unsigned int w); --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -1220,8 +1220,6 @@ parse_probe_arg(char *arg, const struct return ret; } -#define BYTES_TO_BITS(nb) ((BITS_PER_LONG * (nb)) / sizeof(long)) - /* Bitfield type needs to be parsed into a fetch function */ static int __parse_bitfield_probe_arg(const char *bf, const struct fetch_type *t, --- a/tools/include/linux/bitops.h +++ b/tools/include/linux/bitops.h @@ -20,6 +20,8 @@ #define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(u32)) #define BITS_TO_BYTES(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(char)) +#define BYTES_TO_BITS(nb) ((nb) * BITS_PER_BYTE) + extern unsigned int __sw_hweight8(unsigned int w); extern unsigned int __sw_hweight16(unsigned int w); extern unsigned int __sw_hweight32(unsigned int w); --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c @@ -304,8 +304,6 @@ static_var: return ret2; } -#define BYTES_TO_BITS(nb) ((nb) * BITS_PER_LONG / sizeof(long)) - static int convert_variable_type(Dwarf_Die *vr_die, struct probe_trace_arg *tvar, const char *cast, bool user_access) @@ -335,7 +333,7 @@ static int convert_variable_type(Dwarf_D total = dwarf_bytesize(vr_die); if (boffs < 0 || total < 0) return -ENOENT; - ret = snprintf(buf, 16, "b%d@%d/%zd", bsize, boffs, + ret = snprintf(buf, 16, "b%d@%d/%d", bsize, boffs, BYTES_TO_BITS(total)); goto formatted; }