From: Nithurshen <nithurshen.dev@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: xiang@kernel.org, hsiangkao@linux.alibaba.com,
Nithurshen <nithurshen.dev@gmail.com>
Subject: [PATCH] erofs-utils: fix undefined behavior in erofs_init_devices()
Date: Thu, 5 Mar 2026 06:41:15 +0530 [thread overview]
Message-ID: <20260305011115.50506-1-nithurshen.dev@gmail.com> (raw)
Using roundup_pow_of_two() on (ondisk_extradevs + 1) triggers
a potential 64-bit shift warning because of the internal n-1 logic
in the macro.
Since ondisk_extradevs is already validated to be non-zero, use
fls_long() directly to calculate the device_id_mask. This resolves
the 'shiftTooManyBits' warning and is mathematically equivalent.
Signed-off-by: Nithurshen <nithurshen.dev@gmail.com>
---
lib/super.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/super.c b/lib/super.c
index 088c9a0..bff9b1e 100644
--- a/lib/super.c
+++ b/lib/super.c
@@ -29,7 +29,8 @@ static bool check_layout_compatibility(struct erofs_sb_info *sbi,
static int erofs_init_devices(struct erofs_sb_info *sbi,
struct erofs_super_block *dsb)
{
- unsigned int ondisk_extradevs, i;
+ unsigned int i;
+ u16 ondisk_extradevs;
erofs_off_t pos;
sbi->total_blocks = sbi->primarydevice_blocks;
@@ -49,7 +50,7 @@ static int erofs_init_devices(struct erofs_sb_info *sbi,
return 0;
sbi->extra_devices = ondisk_extradevs;
- sbi->device_id_mask = roundup_pow_of_two(ondisk_extradevs + 1) - 1;
+ sbi->device_id_mask = (1UL << fls_long(ondisk_extradevs)) - 1;
sbi->devs = calloc(ondisk_extradevs, sizeof(*sbi->devs));
if (!sbi->devs)
return -ENOMEM;
--
2.51.0
reply other threads:[~2026-03-05 1:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260305011115.50506-1-nithurshen.dev@gmail.com \
--to=nithurshen.dev@gmail.com \
--cc=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=xiang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox