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 0543E30C161 for ; Tue, 14 Jul 2026 02:09:10 +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=1783994952; cv=none; b=TT78uaiM3o2/hF5M0bIrj1gbQtfsO25ANweWapk0svh0NWb8pgSzGAtBBAnmIMEJik2RBkvS2ZxoC2SmzT1SEqOqwcd2i3eBLNFTSQ8xLR4WINr3jrtlfZKJ7SbzDVo8+zZakBmd3EWAKHYISU6pYQQ+OWFEQ9PsWWLUmKHgnfI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783994952; c=relaxed/simple; bh=XGjexdyGXez/DmDM17YF5A5l2trtmbm9mdeUDl3gYPs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=icdIWtSRcA1V//XEjmtJoiYcMnv9NyUYrtFQIs94adm3SaDrLBoDxjE22hUa4654N3GlYd13mFYekKt5yhuujZQyhjU2IRb2oQGYXWHp6JM28xbW3hzDPTshdoxDjFa9dOlkQ9f6oBSFkVgn0AlC26n5G30AeC0HrWw3gfHA5sE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LoR0SEDi; 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="LoR0SEDi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1584E1F00A3D; Tue, 14 Jul 2026 02:09:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783994950; bh=nR+oROq3U6lykK4quTluGOC1Ufbbty4iwZfGter6Ixs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LoR0SEDilDKlCHat500C57Jdfi2Dt6HntPMsvMnB+/WZwtyF4jZyo37eEgRJu5bDu Vdi4VtBQ2RzVWUQ9ijvWUqyUynwUcTnCsHlfyGFm4IQKqqsMMHfGGDv/efpWSCFVCK Ht/AIqqlRDb22IRcLOKQCCPUHKJmfFfyqoqqm8LpXiTPGK2vw5Ss3UbCKQLWiG60/8 Mj8hPv4981Dwjmb4cOS1U5f8bK4/7/K1NsRLaEGVEQK5JnX3xsp8OuKcJ/apMwP2zM za5UYSUCC7dBGgCvjAzqBurac+Ml22PaggyZif54VU2VYjl8+vd1eO6EiJFRG3Qg75 PQ2+CLdr57QYQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Alexander Lobakin , Andy Shevchenko , Przemek Kitszel , Yury Norov , "David S. Miller" , Sasha Levin Subject: [PATCH 5.15.y 1/2] bitops: make BYTES_TO_BITS() treewide-available Date: Mon, 13 Jul 2026 22:09:07 -0400 Message-ID: <20260714020908.2355876-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026071350-armored-aspirin-5d78@gregkh> References: <2026071350-armored-aspirin-5d78@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 5e62e2383b7f19..e8fa3439b083a6 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -21,6 +21,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 f45a31cad6b6a1..1a1eecbfd907e0 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -530,8 +530,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 5fca38fe1ba839..a92e187bd77e33 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 3c13597d0a0db7..dcd64d71e08105 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