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 2761238E5D7 for ; Tue, 14 Jul 2026 03:04:53 +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=1783998294; cv=none; b=P9hjELVrQDlfEVwOmdCgF+9X4pkMwwYEjg6gpq37T4BKS1lp9OrKtJokCHmOZWyWpSK65NM9+237pMzrzV7/bKn9JJVy7o3uxh2xLWTCnB3xg1p6DKtl306I0TLF4roK/gpmZSK8DSvM2ohn8nXYqMfadC0dQ3UswUqEaUkZoDg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783998294; c=relaxed/simple; bh=qH7AzihBoFOxViVe9V4fvifxGNQbrqsc41GBcv40VGo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Avyake3yBO2aV+bbRQGifwpK7/FLaGxvoJL3vNNhH8TmFLOQizfAHKw/sGLRtQRa3Qu/TfsExo+oovsT1sAowUQKWa+C+vXNV9yWBI8/us7xp7ZrnPLQBJTWcjo6Eh1e0Bxu0NR9b6QDm+Tj+NIQj1o+IPiTdF2RQYvmhj31SxY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AsiZDiwl; 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="AsiZDiwl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 516121F000E9; Tue, 14 Jul 2026 03:04:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783998293; bh=XPa19kAf2Mdxd9fM1mfykmkI6GCr/J34SLA7meouvK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AsiZDiwl47OCtVdBiIrv4cAKLCAhA1uV3i3g/2ZHIxLql/iYyggAZnZwzMnBTTMy1 UvtpgqpF4JJbNeDmw8/oLKK/txHpxfZ61BFgs8eypUpjRazrXXZNXIEXzP41/wUbVU /GWlHNqGk1w4UiRveueK3eic3YLDk+GgpKgTolocBnjL0AgJ1Q3r6B+D1NnX3Lfaqs 7XKpGricR4hIhP2I+R5H5VGL0iXX9sxC0SXSKAy+djha7XkQ6Exa8rXqzAL+iB2Afb s/Se3x40QIlDyLTGL1bVmsSvA+hq6R3rQ26JXsYsq0dKiB2pHCpLVHriwJ/WCThGZy NR4nnTPUGz7/Q== 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.10.y 1/2] bitops: make BYTES_TO_BITS() treewide-available Date: Mon, 13 Jul 2026 23:04:47 -0400 Message-ID: <20260714030448.2382602-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026071351-cheating-unrented-98cd@gregkh> References: <2026071351-cheating-unrented-98cd@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 5b74bdf159d6f2..e2930a990ea4aa 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -17,6 +17,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/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 48f5ca60c68dd1..6a879f395084d8 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -502,8 +502,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 8a98673fea380a..45c0c1d6b6aa65 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c @@ -299,8 +299,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) @@ -330,7 +328,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