Skip to content

Commit

Permalink
mtd: sm_ftl: fix NULL pointer warning
Browse files Browse the repository at this point in the history
With gcc -O3, we get a new warning:

In file included from arch/arm64/include/asm/processor.h:28,
                 from drivers/mtd/sm_ftl.c:8:
In function 'memset',
    inlined from 'sm_read_sector.constprop' at drivers/mtd/sm_ftl.c:250:3:
include/linux/string.h:411:9: error: argument 1 null where non-null expected [-Werror=nonnull]
  return __builtin_memset(p, c, size);

>From all I can tell, this cannot happen (the function is called
either with a NULL buffer or with a -1 block number but not both),
but adding a check makes it more robust and avoids the warning.

Fixes: mmtom ("init/Kconfig: enable -O3 for all arches")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
  • Loading branch information
Arnd Bergmann authored and Miquel Raynal committed Jan 9, 2020
1 parent 8bcef0d commit de08b5a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/mtd/sm_ftl.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ static int sm_read_sector(struct sm_ftl *ftl,

/* FTL can contain -1 entries that are by default filled with bits */
if (block == -1) {
memset(buffer, 0xFF, SM_SECTOR_SIZE);
if (buffer)
memset(buffer, 0xFF, SM_SECTOR_SIZE);
return 0;
}

Expand Down

0 comments on commit de08b5a

Please sign in to comment.