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 9BE3143C7AE; Tue, 21 Jul 2026 22:58:05 +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=1784674688; cv=none; b=MnTa2FIlZdeAPxM36R3bb2vvejqpzhEWs9VWmilZOLB+cgIpldaAUY1AbFvpi2WZWHnBMVVwqZhDjVh8vqThSBjrBtAt3ecuXmLQwqY4jvxtWK4lvW639D9RMMrt/adDxLh/AvJpUgx7RyaWUEkmQMrisG4w82l97KGOYs2gozI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784674688; c=relaxed/simple; bh=w/ycbZfGu9cliiBYUlNLl67ivHUy6pCaZFFcQFNvp7k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TdASVrFy8MJypUdThK5tn15mCqneVJP7AxU9ZMX6wuRdf6/xqTa22mIekdcjpu/u6Ebp0HVrJ1oSNlQlxwNO7iWkAXwX7QwW0Ksgn1w8Mj2JxfB0SvbbV5fIeMoZI4+d64PmMEa8bYDncWoo5lLseqrOlDse7UtoQ5VBnYOWWr8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=N/eCMSNZ; 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="N/eCMSNZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CE211F000E9; Tue, 21 Jul 2026 22:58:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784674684; bh=oVUYI2NwwGdp9diFaPuXfA9W/i45jZ7qkeicbPw7lK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=N/eCMSNZyjUaLU+y3JfXkApoba2vNLTXUNVzjnuoHgPSi1ssUSV4J56q6+dIdBe6t rSbPgt0CK3cwve0RZhK+dDpFHpC1/WfISD1EZdKQuILiy28qPgm8U31EopkKvHmxvT eaLG4SpOZWdoYL7+fx3VwmbyffXTLac1zGmikim8= 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 5.10 592/699] bitops: make BYTES_TO_BITS() treewide-available Date: Tue, 21 Jul 2026 17:25:51 +0200 Message-ID: <20260721152409.085265257@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152355.667394603@linuxfoundation.org> References: <20260721152355.667394603@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 5.10-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 @@ -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); --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -503,8 +503,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 @@ -299,8 +299,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) @@ -330,7 +328,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; }