All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: fix ifnullfree.cocci warnings (fwd)
@ 2018-03-30  6:32 ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2018-03-30  6:32 UTC (permalink / raw)
  Cc: Linus Walleij, kbuild-all, Kees Cook, Lukas Wunner, Laura Abbott,
	linux-gpio, linux-kernel, kernel-hardening, Rasmus Villemoes

From: Fengguang Wu <fengguang.wu@intel.com>

NULL check before kfree is not needed.

Generated by: scripts/coccinelle/free/ifnullfree.cocci

Fixes: ad85ae608fe0 ("gpio: Remove VLA from gpiolib")
CC: Laura Abbott <labbott@redhat.com>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Julia Lawall <julia.lawall@lip6.fr>

---

url:
https://github.com/0day-ci/linux/commits/Laura-Abbott/gpio-Remove-VLA-from-gpiolib/20180330-065639
base:
https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git
for-next

 gpiolib.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2758,8 +2758,7 @@ int gpiod_get_array_value_complex(bool r

 		ret = gpio_chip_get_multiple(chip, mask, bits);
 		if (ret) {
-			if (slowpath)
-				kfree(slowpath);
+			kfree(slowpath);
 			return ret;
 		}

@@ -2774,8 +2773,7 @@ int gpiod_get_array_value_complex(bool r
 			trace_gpio_value(desc_to_gpio(desc), 1, value);
 		}

-		if (slowpath)
-			kfree(slowpath);
+		kfree(slowpath);
 	}
 	return 0;
 }
@@ -3020,8 +3018,7 @@ int gpiod_set_array_value_complex(bool r
 		if (count != 0)
 			gpio_chip_set_multiple(chip, mask, bits);

-		if (slowpath)
-			kfree(slowpath);
+		kfree(slowpath);
 	}
 	return 0;
 }

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

* [PATCH] gpio: fix ifnullfree.cocci warnings (fwd)
@ 2018-03-30  6:32 ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2018-03-30  6:32 UTC (permalink / raw)
  To: Laura Abbott
  Cc: Linus Walleij, kbuild-all, Kees Cook, Lukas Wunner, Laura Abbott,
	linux-gpio, linux-kernel, kernel-hardening, Rasmus Villemoes

From: Fengguang Wu <fengguang.wu@intel.com>

NULL check before kfree is not needed.

Generated by: scripts/coccinelle/free/ifnullfree.cocci

Fixes: ad85ae608fe0 ("gpio: Remove VLA from gpiolib")
CC: Laura Abbott <labbott@redhat.com>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Julia Lawall <julia.lawall@lip6.fr>

---

url:
https://github.com/0day-ci/linux/commits/Laura-Abbott/gpio-Remove-VLA-from-gpiolib/20180330-065639
base:
https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git
for-next

 gpiolib.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2758,8 +2758,7 @@ int gpiod_get_array_value_complex(bool r

 		ret = gpio_chip_get_multiple(chip, mask, bits);
 		if (ret) {
-			if (slowpath)
-				kfree(slowpath);
+			kfree(slowpath);
 			return ret;
 		}

@@ -2774,8 +2773,7 @@ int gpiod_get_array_value_complex(bool r
 			trace_gpio_value(desc_to_gpio(desc), 1, value);
 		}

-		if (slowpath)
-			kfree(slowpath);
+		kfree(slowpath);
 	}
 	return 0;
 }
@@ -3020,8 +3018,7 @@ int gpiod_set_array_value_complex(bool r
 		if (count != 0)
 			gpio_chip_set_multiple(chip, mask, bits);

-		if (slowpath)
-			kfree(slowpath);
+		kfree(slowpath);
 	}
 	return 0;
 }

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

* [PATCH] gpio: fix ifnullfree.cocci warnings (fwd)
@ 2018-03-30  6:32 ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2018-03-30  6:32 UTC (permalink / raw)
  To: Laura Abbott
  Cc: Linus Walleij, kbuild-all, Kees Cook, Lukas Wunner, linux-gpio,
	linux-kernel, kernel-hardening, Rasmus Villemoes

From: Fengguang Wu <fengguang.wu@intel.com>

NULL check before kfree is not needed.

Generated by: scripts/coccinelle/free/ifnullfree.cocci

Fixes: ad85ae608fe0 ("gpio: Remove VLA from gpiolib")
CC: Laura Abbott <labbott@redhat.com>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Julia Lawall <julia.lawall@lip6.fr>

---

url:
https://github.com/0day-ci/linux/commits/Laura-Abbott/gpio-Remove-VLA-from-gpiolib/20180330-065639
base:
https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git
for-next

 gpiolib.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2758,8 +2758,7 @@ int gpiod_get_array_value_complex(bool r

 		ret = gpio_chip_get_multiple(chip, mask, bits);
 		if (ret) {
-			if (slowpath)
-				kfree(slowpath);
+			kfree(slowpath);
 			return ret;
 		}

@@ -2774,8 +2773,7 @@ int gpiod_get_array_value_complex(bool r
 			trace_gpio_value(desc_to_gpio(desc), 1, value);
 		}

-		if (slowpath)
-			kfree(slowpath);
+		kfree(slowpath);
 	}
 	return 0;
 }
@@ -3020,8 +3018,7 @@ int gpiod_set_array_value_complex(bool r
 		if (count != 0)
 			gpio_chip_set_multiple(chip, mask, bits);

-		if (slowpath)
-			kfree(slowpath);
+		kfree(slowpath);
 	}
 	return 0;
 }

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

* Re: [PATCH] gpio: fix ifnullfree.cocci warnings
  2018-03-30  6:32 ` Julia Lawall
  (?)
  (?)
@ 2018-04-02  8:31 ` Lukas Wunner
  2018-04-02  9:04   ` Julia Lawall
  -1 siblings, 1 reply; 5+ messages in thread
From: Lukas Wunner @ 2018-04-02  8:31 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Laura Abbott, Linus Walleij, kbuild-all, Kees Cook, linux-gpio,
	linux-kernel, kernel-hardening, Rasmus Villemoes,
	Andy Shevchenko

On Fri, Mar 30, 2018 at 08:32:56AM +0200, Julia Lawall wrote:
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -2774,8 +2773,7 @@ int gpiod_get_array_value_complex(bool r
>  			trace_gpio_value(desc_to_gpio(desc), 1, value);
>  		}
> 
> -		if (slowpath)
> -			kfree(slowpath);
> +		kfree(slowpath);
>  	}
>  	return 0;
>  }
> @@ -3020,8 +3018,7 @@ int gpiod_set_array_value_complex(bool r
>  		if (count != 0)
>  			gpio_chip_set_multiple(chip, mask, bits);
> 
> -		if (slowpath)
> -			kfree(slowpath);
> +		kfree(slowpath);
>  	}
>  	return 0;
>  }

The problem I see here is that kfree may not be in L1 cache,
and in that case checking for non-NULL locally in this function
should actually be cheaper.

Note that kfree() need only be called in the slowpath, which
is the *unlikely* case.  Letting the branch predictor assume
that kfree() is not called is the right thing to do here.

The function is a hot path, on the Revolution Pi open source PLCs
we're calling it every 250 usec to poll digital inputs and update
digital outputs.

Would "if (unlikely(slowpath))" be sufficient to make coccinelle
happy?  That's what I'd suggest then.

Otherwise "if (unlikely(chip->ngpio > FASTPATH_NGPIO))" could be used,
though that might be minimally slower due to the pointer chasing.


> @@ -2758,8 +2758,7 @@ int gpiod_get_array_value_complex(bool r
> 
>  		ret = gpio_chip_get_multiple(chip, mask, bits);
>  		if (ret) {
> -			if (slowpath)
> -				kfree(slowpath);
> +			kfree(slowpath);
>  			return ret;
>  		}
> 

This particular change on the other hand is fine because the kfree()
is occurring in an error path, which we'll normally not enter anyway.

Thanks,

Lukas

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

* Re: [PATCH] gpio: fix ifnullfree.cocci warnings
  2018-04-02  8:31 ` [PATCH] gpio: fix ifnullfree.cocci warnings Lukas Wunner
@ 2018-04-02  9:04   ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2018-04-02  9:04 UTC (permalink / raw)
  To: Lukas Wunner
  Cc: Laura Abbott, Linus Walleij, kbuild-all, Kees Cook, linux-gpio,
	linux-kernel, kernel-hardening, Rasmus Villemoes,
	Andy Shevchenko



On Mon, 2 Apr 2018, Lukas Wunner wrote:

> On Fri, Mar 30, 2018 at 08:32:56AM +0200, Julia Lawall wrote:
> > --- a/drivers/gpio/gpiolib.c
> > +++ b/drivers/gpio/gpiolib.c
> > @@ -2774,8 +2773,7 @@ int gpiod_get_array_value_complex(bool r
> >  			trace_gpio_value(desc_to_gpio(desc), 1, value);
> >  		}
> >
> > -		if (slowpath)
> > -			kfree(slowpath);
> > +		kfree(slowpath);
> >  	}
> >  	return 0;
> >  }
> > @@ -3020,8 +3018,7 @@ int gpiod_set_array_value_complex(bool r
> >  		if (count != 0)
> >  			gpio_chip_set_multiple(chip, mask, bits);
> >
> > -		if (slowpath)
> > -			kfree(slowpath);
> > +		kfree(slowpath);
> >  	}
> >  	return 0;
> >  }
>
> The problem I see here is that kfree may not be in L1 cache,
> and in that case checking for non-NULL locally in this function
> should actually be cheaper.
>
> Note that kfree() need only be called in the slowpath, which
> is the *unlikely* case.  Letting the branch predictor assume
> that kfree() is not called is the right thing to do here.
>
> The function is a hot path, on the Revolution Pi open source PLCs
> we're calling it every 250 usec to poll digital inputs and update
> digital outputs.
>
> Would "if (unlikely(slowpath))" be sufficient to make coccinelle
> happy?  That's what I'd suggest then.

I think that indeed it would not complain any more in this case.  But at
least from kbuild, you shouldn't get another report on this, even if you
don't change it.  Of course, someone else running the script could find
the issue again.  If it would seem appropriate to you, adding a comment
would also at least capture the knowledge that the change is not wanted.

julia

>
> Otherwise "if (unlikely(chip->ngpio > FASTPATH_NGPIO))" could be used,
> though that might be minimally slower due to the pointer chasing.
>
>
> > @@ -2758,8 +2758,7 @@ int gpiod_get_array_value_complex(bool r
> >
> >  		ret = gpio_chip_get_multiple(chip, mask, bits);
> >  		if (ret) {
> > -			if (slowpath)
> > -				kfree(slowpath);
> > +			kfree(slowpath);
> >  			return ret;
> >  		}
> >
>
> This particular change on the other hand is fine because the kfree()
> is occurring in an error path, which we'll normally not enter anyway.
>
> Thanks,
>
> Lukas
>

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

end of thread, other threads:[~2018-04-02  9:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-30  6:32 [PATCH] gpio: fix ifnullfree.cocci warnings (fwd) Julia Lawall
2018-03-30  6:32 ` Julia Lawall
2018-03-30  6:32 ` Julia Lawall
2018-04-02  8:31 ` [PATCH] gpio: fix ifnullfree.cocci warnings Lukas Wunner
2018-04-02  9:04   ` Julia Lawall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.