Skip to content

Commit 21c9fb6

Browse files
arndbmiquelraynal
authored andcommitted
mtd: diskonchip: work around ubsan link failure
I ran into a randconfig build failure with UBSAN using gcc-13.2: arm-linux-gnueabi-ld: error: unplaced orphan section `.bss..Lubsan_data31' from `drivers/mtd/nand/raw/diskonchip.o' I'm not entirely sure what is going on here, but I suspect this has something to do with the check for the end of the doc_locations[] array that contains an (unsigned long)0xffffffff element, which is compared against the signed (int)0xffffffff. If this is the case, we should get a runtime check for undefined behavior, but we instead get an unexpected build-time error. I would have expected this to work fine on 32-bit architectures despite the signed integer overflow, though on 64-bit architectures this likely won't ever work. Changing the contition to instead check for the size of the array makes the code safe everywhere and avoids the ubsan check that leads to the link error. The loop code goes back to before 2.6.12. Cc: [email protected] Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent b61bb5b commit 21c9fb6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/mtd/nand/raw/diskonchip.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static unsigned long doc_locations[] __initdata = {
5353
0xe8000, 0xea000, 0xec000, 0xee000,
5454
#endif
5555
#endif
56-
0xffffffff };
56+
};
5757

5858
static struct mtd_info *doclist = NULL;
5959

@@ -1554,7 +1554,7 @@ static int __init init_nanddoc(void)
15541554
if (ret < 0)
15551555
return ret;
15561556
} else {
1557-
for (i = 0; (doc_locations[i] != 0xffffffff); i++) {
1557+
for (i = 0; i < ARRAY_SIZE(doc_locations); i++) {
15581558
doc_probe(doc_locations[i]);
15591559
}
15601560
}

0 commit comments

Comments
 (0)