From mboxrd@z Thu Jan 1 00:00:00 1970 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 17DC334C83C for ; Mon, 13 Jul 2026 20:39:27 +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=1783975168; cv=none; b=IayuZPI3yb+75RotWL7UTO9sxiPOFjopMK0hd2ZjVLBZ/8oOxgtjcvSBvXvKMmXf18Z1ij0c14DKceIQfryPRPC+unJNP0OZ36OmW1gv4peC/ss7Alzfhmy9wcYdCHLILW5iFyOCsRHjm2axhAF90YIQtyEJpnM90Ibj9jZm87o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783975168; c=relaxed/simple; bh=0PKR9MXwh4JJvRf8LRUAlJKbRmyxrFo7WgagQgBFZXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XxFrQ2u692gfQTmdC7c21/RQLYKvZUsd2L36crHa0Go4TMscEoLd0sXC2/GweBW1DjXBGifm3vkhv4AttEOcVCKX0GfzprIdZeY4+vFQlLhEI66rtuGePOthf1pX+031mg8Vm2Gbx1sJPFQlnxjZea55vVrB5lawaMGIvsO8UWU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lxr+oYrQ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lxr+oYrQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C2FC1F000E9; Mon, 13 Jul 2026 20:39:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783975167; bh=bvLu2lhJ+/0xZUmM53MsnXyWexL/OerI+0+QR6lqSdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lxr+oYrQm4YmYAy2aXuYzhxCQ2NKCgVORwY2Qep+/imd0FdIpx0bpApZqeeWPBzyq Y8Mi88og9yVPBWFe8rnzbCbjTrev1a/TpTlKcoljoUUV36whdtfo6LRoemkUpzFGSQ KQFoNmIEvs/WRn+mDaFOTBuaLQ1DhfAuDu6Gw6GCy771iseqUdJ0gG+0oM0GChG1jf mmioGxH/YSuw54h6J71Hwh9vi772EQbNWj6F4BeITuNKDE07I3GknyU0d2c/OuY+r5 LeAaPeEhZ/cN40UhKVyhgjqce5fvHP5lzvi9sj28xwK/QSZrir4KgAExKgduKD7Qyc Nqp5Qe4q893Zg== From: Sasha Levin To: stable@vger.kernel.org Cc: Alexander Lobakin , Andy Shevchenko , Przemek Kitszel , Yury Norov , "David S. Miller" , Sasha Levin Subject: [PATCH 6.6.y 1/2] bitops: make BYTES_TO_BITS() treewide-available Date: Mon, 13 Jul 2026 16:39:23 -0400 Message-ID: <20260713203924.2143667-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026071348-glorify-lapel-3161@gregkh> References: <2026071348-glorify-lapel-3161@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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(-) diff --git a/include/linux/bitops.h b/include/linux/bitops.h index b2342eebc8d226..07729a31198ec0 100644 --- 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); diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 8f52ffd3c6bb7c..55db95db5bf6f4 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -1219,8 +1219,6 @@ parse_probe_arg(char *arg, const struct fetch_type *type, 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, diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h index f18683b95ea673..bc6600466e7b26 100644 --- 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); diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index c0c8d7f9514b04..f9c396fe81dc4b 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c @@ -304,8 +304,6 @@ static int convert_variable_location(Dwarf_Die *vr_die, Dwarf_Addr addr, 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_Die *vr_die, 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; } -- 2.53.0