linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: sm_ftl: fix NULL pointer warning
@ 2020-01-07 21:24 Arnd Bergmann
  2020-01-08  8:15 ` Miquel Raynal
  2020-01-09 19:14 ` Miquel Raynal
  0 siblings, 2 replies; 4+ messages in thread
From: Arnd Bergmann @ 2020-01-07 21:24 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra
  Cc: Oleksandr Natalenko, Arnd Bergmann, Wenwen Wang, linux-mtd, linux-kernel

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>
---
 drivers/mtd/sm_ftl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
index 4744bf94ad9a..b9f272408c4d 100644
--- a/drivers/mtd/sm_ftl.c
+++ b/drivers/mtd/sm_ftl.c
@@ -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;
 	}
 
-- 
2.20.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mtd: sm_ftl: fix NULL pointer warning
  2020-01-07 21:24 [PATCH] mtd: sm_ftl: fix NULL pointer warning Arnd Bergmann
@ 2020-01-08  8:15 ` Miquel Raynal
  2020-01-08  8:18   ` Arnd Bergmann
  2020-01-09 19:14 ` Miquel Raynal
  1 sibling, 1 reply; 4+ messages in thread
From: Miquel Raynal @ 2020-01-08  8:15 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Richard Weinberger, Vignesh Raghavendra, Oleksandr Natalenko,
	Wenwen Wang, linux-mtd, linux-kernel

Hi Arnd,

Arnd Bergmann <arnd@arndb.de> wrote on Tue,  7 Jan 2020 22:24:52 +0100:

> 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>
> ---
>  drivers/mtd/sm_ftl.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
> index 4744bf94ad9a..b9f272408c4d 100644
> --- a/drivers/mtd/sm_ftl.c
> +++ b/drivers/mtd/sm_ftl.c
> @@ -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;
>  	}
>  

What about a simpler form:

        if (buffer && block == -1) { ...

Instead of an additional indentation level? 

Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mtd: sm_ftl: fix NULL pointer warning
  2020-01-08  8:15 ` Miquel Raynal
@ 2020-01-08  8:18   ` Arnd Bergmann
  0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2020-01-08  8:18 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Richard Weinberger, Vignesh Raghavendra, Oleksandr Natalenko,
	Wenwen Wang, linux-mtd, linux-kernel

On Wed, Jan 8, 2020 at 9:15 AM Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>
> Hi Arnd,
>
> Arnd Bergmann <arnd@arndb.de> wrote on Tue,  7 Jan 2020 22:24:52 +0100:
>
> > 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>
> > ---
> >  drivers/mtd/sm_ftl.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
> > index 4744bf94ad9a..b9f272408c4d 100644
> > --- a/drivers/mtd/sm_ftl.c
> > +++ b/drivers/mtd/sm_ftl.c
> > @@ -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;
> >       }
> >
>
> What about a simpler form:
>
>         if (buffer && block == -1) { ...
>
> Instead of an additional indentation level?

That would fail to return early from the function if we ever get block==-1
and buffer==NULL, probably resulting is worse problems later.

       Arnd

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mtd: sm_ftl: fix NULL pointer warning
  2020-01-07 21:24 [PATCH] mtd: sm_ftl: fix NULL pointer warning Arnd Bergmann
  2020-01-08  8:15 ` Miquel Raynal
@ 2020-01-09 19:14 ` Miquel Raynal
  1 sibling, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2020-01-09 19:14 UTC (permalink / raw)
  To: Arnd Bergmann, Miquel Raynal, Richard Weinberger, Vignesh Raghavendra
  Cc: Oleksandr Natalenko, Wenwen Wang, linux-mtd, linux-kernel

On Tue, 2020-01-07 at 21:24:52 UTC, Arnd Bergmann wrote:
> 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>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/fixes, thanks.

Miquel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-01-09 19:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-07 21:24 [PATCH] mtd: sm_ftl: fix NULL pointer warning Arnd Bergmann
2020-01-08  8:15 ` Miquel Raynal
2020-01-08  8:18   ` Arnd Bergmann
2020-01-09 19:14 ` Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).