All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] drivers: base: swnode: check if swnode is null before dereferencing it
@ 2018-12-22 12:43 Colin King
  2018-12-27  8:59   ` Rafael J. Wysocki
  2019-01-02 12:01   ` Dan Carpenter
  0 siblings, 2 replies; 5+ messages in thread
From: Colin King @ 2018-12-22 12:43 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman, Rafael J . Wysocki
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The macro to_software_mode can potentially return NULL, so also add
a null check on the swnode before dereferencing it to avoid any null
pointer dereferences.

Detected by CoverityScan, CID#1476052 ("Explicit null dereferenced")

Fixes: 59abd83672f7 ("drivers: base: Introducing software nodes to the firmware node framework")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/base/swnode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index 306bb93287af..204aa7d049e0 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -477,7 +477,8 @@ software_node_get_parent(const struct fwnode_handle *fwnode)
 {
 	struct software_node *swnode = to_software_node(fwnode);
 
-	return swnode->parent ? &swnode->parent->fwnode : NULL;
+	return swnode ? (swnode->parent ? &swnode->parent->fwnode : NULL) :
+			NULL;
 }
 
 struct fwnode_handle *
-- 
2.19.1


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

* Re: [PATCH][next] drivers: base: swnode: check if swnode is null before dereferencing it
  2018-12-22 12:43 [PATCH][next] drivers: base: swnode: check if swnode is null before dereferencing it Colin King
@ 2018-12-27  8:59   ` Rafael J. Wysocki
  2019-01-02 12:01   ` Dan Carpenter
  1 sibling, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2018-12-27  8:59 UTC (permalink / raw)
  To: Colin King
  Cc: Heikki Krogerus, Greg Kroah-Hartman, Rafael J . Wysocki,
	kernel-janitors, Linux Kernel Mailing List

On Sat, Dec 22, 2018 at 1:43 PM Colin King <colin.king@canonical.com> wrote:
>
> From: Colin Ian King <colin.king@canonical.com>
>
> The macro to_software_mode can potentially return NULL, so also add
> a null check on the swnode before dereferencing it to avoid any null
> pointer dereferences.
>
> Detected by CoverityScan, CID#1476052 ("Explicit null dereferenced")
>
> Fixes: 59abd83672f7 ("drivers: base: Introducing software nodes to the firmware node framework")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/base/swnode.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
> index 306bb93287af..204aa7d049e0 100644
> --- a/drivers/base/swnode.c
> +++ b/drivers/base/swnode.c
> @@ -477,7 +477,8 @@ software_node_get_parent(const struct fwnode_handle *fwnode)
>  {
>         struct software_node *swnode = to_software_node(fwnode);
>
> -       return swnode->parent ? &swnode->parent->fwnode : NULL;
> +       return swnode ? (swnode->parent ? &swnode->parent->fwnode : NULL) :
> +                       NULL;
>  }
>
>  struct fwnode_handle *
> --

Applied, thanks!

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

* Re: [PATCH][next] drivers: base: swnode: check if swnode is null before dereferencing it
@ 2018-12-27  8:59   ` Rafael J. Wysocki
  0 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2018-12-27  8:59 UTC (permalink / raw)
  To: Colin King
  Cc: Heikki Krogerus, Greg Kroah-Hartman, Rafael J . Wysocki,
	kernel-janitors, Linux Kernel Mailing List

On Sat, Dec 22, 2018 at 1:43 PM Colin King <colin.king@canonical.com> wrote:
>
> From: Colin Ian King <colin.king@canonical.com>
>
> The macro to_software_mode can potentially return NULL, so also add
> a null check on the swnode before dereferencing it to avoid any null
> pointer dereferences.
>
> Detected by CoverityScan, CID#1476052 ("Explicit null dereferenced")
>
> Fixes: 59abd83672f7 ("drivers: base: Introducing software nodes to the firmware node framework")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/base/swnode.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
> index 306bb93287af..204aa7d049e0 100644
> --- a/drivers/base/swnode.c
> +++ b/drivers/base/swnode.c
> @@ -477,7 +477,8 @@ software_node_get_parent(const struct fwnode_handle *fwnode)
>  {
>         struct software_node *swnode = to_software_node(fwnode);
>
> -       return swnode->parent ? &swnode->parent->fwnode : NULL;
> +       return swnode ? (swnode->parent ? &swnode->parent->fwnode : NULL) :
> +                       NULL;
>  }
>
>  struct fwnode_handle *
> --

Applied, thanks!

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

* Re: [PATCH][next] drivers: base: swnode: check if swnode is null before dereferencing it
  2018-12-22 12:43 [PATCH][next] drivers: base: swnode: check if swnode is null before dereferencing it Colin King
@ 2019-01-02 12:01   ` Dan Carpenter
  2019-01-02 12:01   ` Dan Carpenter
  1 sibling, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2019-01-02 12:01 UTC (permalink / raw)
  To: Colin King
  Cc: Heikki Krogerus, Greg Kroah-Hartman, Rafael J . Wysocki,
	kernel-janitors, linux-kernel

On Sat, Dec 22, 2018 at 12:43:33PM +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The macro to_software_mode can potentially return NULL, so also add
> a null check on the swnode before dereferencing it to avoid any null
> pointer dereferences.
> 
> Detected by CoverityScan, CID#1476052 ("Explicit null dereferenced")
> 
> Fixes: 59abd83672f7 ("drivers: base: Introducing software nodes to the firmware node framework")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

to_software_mode() can't return NULL though...

We shouldn't change the code just to make the static checker happy.

Sometimes if we just silence every static checker warning maybe we will
fix some bugs in the middle of silencing all the false positive, but
Smatch is almost at the stage of being able to parse this code
correctly.  Maybe by the end of the year.  So let's hold off and then
think about taking the fix everything approach next year.

regards,
dan carpenter


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

* Re: [PATCH][next] drivers: base: swnode: check if swnode is null before dereferencing it
@ 2019-01-02 12:01   ` Dan Carpenter
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2019-01-02 12:01 UTC (permalink / raw)
  To: Colin King
  Cc: Heikki Krogerus, Greg Kroah-Hartman, Rafael J . Wysocki,
	kernel-janitors, linux-kernel

On Sat, Dec 22, 2018 at 12:43:33PM +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The macro to_software_mode can potentially return NULL, so also add
> a null check on the swnode before dereferencing it to avoid any null
> pointer dereferences.
> 
> Detected by CoverityScan, CID#1476052 ("Explicit null dereferenced")
> 
> Fixes: 59abd83672f7 ("drivers: base: Introducing software nodes to the firmware node framework")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

to_software_mode() can't return NULL though...

We shouldn't change the code just to make the static checker happy.

Sometimes if we just silence every static checker warning maybe we will
fix some bugs in the middle of silencing all the false positive, but
Smatch is almost at the stage of being able to parse this code
correctly.  Maybe by the end of the year.  So let's hold off and then
think about taking the fix everything approach next year.

regards,
dan carpenter

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

end of thread, other threads:[~2019-01-02 12:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-22 12:43 [PATCH][next] drivers: base: swnode: check if swnode is null before dereferencing it Colin King
2018-12-27  8:59 ` Rafael J. Wysocki
2018-12-27  8:59   ` Rafael J. Wysocki
2019-01-02 12:01 ` Dan Carpenter
2019-01-02 12:01   ` Dan Carpenter

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.