Skip to contentSkip to conversation

memstick: avoid out-of-range warning

PATCH In review Arnd Bergmann 2 participants 2 messages Sep 27, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memstick: avoid out-of-range warning

From: Arnd Bergmann <[email protected]>

clang-14 complains about a sanity check that always passes when the page size is 64KB or larger:

drivers/memstick/core/ms_block.c:1739:21: error: result of comparison of constant 65536 with expression of type 'unsigned short' is always false [-Werror,-Wtautological-constant-out-of-range-compare]

        if (msb->page_size > PAGE_SIZE) {
            ~~~~~~~~~~~~~~ ^ ~~~~~~~~~

This is fine, it will still work on all architectures, so just shut up that warning with a cast.

Fixes 0ab30494bc4f ("memstick: add support for legacy memorysticks")
---
 drivers/memstick/core/ms_block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/memstick/core/ms_block.c +1 -1
index acf36676e388..487e4cc2951e 100644
@@ -1736,7 +1736,7 @@ static int msb_init_card(struct memstick_dev *card)
 	msb->pages_in_block = boot_block->attr.block_size * 2;
 	msb->block_size = msb->page_size * msb->pages_in_block;
 
-	if (msb->page_size > PAGE_SIZE) {
+	if ((size_t)msb->page_size > PAGE_SIZE) {
 		/* this isn't supported by linux at all, anyway*/
 		dbg("device page %d size isn't supported", msb->page_size);
 		return -EINVAL;
Signature · 1 line
2.29.2
#1 lore raw
Quoted 7 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

clang-14 complains about a sanity check that always passes when the page size is 64KB or larger:

drivers/memstick/core/ms_block.c:1739:21: error: result of comparison of constant 65536 with expression of type 'unsigned short' is always false [-Werror,-Wtautological-constant-out-of-range-compare]

Quoted 8 lines
        if (msb->page_size > PAGE_SIZE) {
            ~~~~~~~~~~~~~~ ^ ~~~~~~~~~

This is fine, it will still work on all architectures, so just shut up that warning with a cast.

Fixes 0ab30494bc4f ("memstick: add support for legacy memorysticks")

Applied for next, thanks!

Kind regards
Uffe

Quoted 20 lines
---
 drivers/memstick/core/ms_block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/memstick/core/ms_block.c +1 -2
index acf36676e388..487e4cc2951e 100644
@@ -1736,7 +1736,7 @@ static int msb_init_card(struct memstick_dev *card)
        msb->pages_in_block = boot_block->attr.block_size * 2;
        msb->block_size = msb->page_size * msb->pages_in_block;
 
-       if (msb->page_size > PAGE_SIZE) {
+       if ((size_t)msb->page_size > PAGE_SIZE) {
                /* this isn't supported by linux at all, anyway*/
                dbg("device page %d size isn't supported", msb->page_size);
                return -EINVAL;
--

2.29.2