2022-06-19 07:12:56

by Souptick Joarder

[permalink] [raw]
Subject: [PATCH] vme: Added NULL check for bridge

From: "Souptick Joarder (HPE)" <[email protected]>

Kernel test robot throws below warning ->
drivers/staging/vme_user/vme.c:662:20: warning: dereference
of NULL 'bridge' [CWE-476] [-Wanalyzer-null-dereference]

Added a NULL check.

Reported-by: Kernel test robot <[email protected]>
Signed-off-by: Souptick Joarder (HPE) <[email protected]>
---
drivers/staging/vme_user/vme.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/vme_user/vme.c b/drivers/staging/vme_user/vme.c
index b5555683a069..ede774f2fe5a 100644
--- a/drivers/staging/vme_user/vme.c
+++ b/drivers/staging/vme_user/vme.c
@@ -659,7 +659,7 @@ ssize_t vme_master_read(struct vme_resource *resource, void *buf, size_t count,
struct vme_master_resource *image;
size_t length;

- if (!bridge->master_read) {
+ if (bridge && !bridge->master_read) {
printk(KERN_WARNING "Reading from resource not supported\n");
return -EINVAL;
}
--
2.25.1


2022-06-20 08:50:54

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH] vme: Added NULL check for bridge

On Sun, Jun 19, 2022 at 12:36:45PM +0530, Souptick Joarder wrote:
> From: "Souptick Joarder (HPE)" <[email protected]>
>
> Kernel test robot throws below warning ->
> drivers/staging/vme_user/vme.c:662:20: warning: dereference
> of NULL 'bridge' [CWE-476] [-Wanalyzer-null-dereference]
>
> Added a NULL check.
>
> Reported-by: Kernel test robot <[email protected]>
> Signed-off-by: Souptick Joarder (HPE) <[email protected]>
> ---
> drivers/staging/vme_user/vme.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/vme_user/vme.c b/drivers/staging/vme_user/vme.c
> index b5555683a069..ede774f2fe5a 100644
> --- a/drivers/staging/vme_user/vme.c
> +++ b/drivers/staging/vme_user/vme.c
> @@ -659,7 +659,7 @@ ssize_t vme_master_read(struct vme_resource *resource, void *buf, size_t count,
> struct vme_master_resource *image;
> size_t length;
>
> - if (!bridge->master_read) {
> + if (bridge && !bridge->master_read) {

How can bridge ever be NULL here?

thanks,

greg k-h

2022-06-20 09:15:37

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] vme: Added NULL check for bridge

On Sun, Jun 19, 2022 at 12:36:45PM +0530, Souptick Joarder wrote:
> From: "Souptick Joarder (HPE)" <[email protected]>
>
> Kernel test robot throws below warning ->
> drivers/staging/vme_user/vme.c:662:20: warning: dereference
> of NULL 'bridge' [CWE-476] [-Wanalyzer-null-dereference]
>
> Added a NULL check.
>
> Reported-by: Kernel test robot <[email protected]>
> Signed-off-by: Souptick Joarder (HPE) <[email protected]>
> ---
> drivers/staging/vme_user/vme.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/vme_user/vme.c b/drivers/staging/vme_user/vme.c
> index b5555683a069..ede774f2fe5a 100644
> --- a/drivers/staging/vme_user/vme.c
> +++ b/drivers/staging/vme_user/vme.c
> @@ -659,7 +659,7 @@ ssize_t vme_master_read(struct vme_resource *resource, void *buf, size_t count,
> struct vme_master_resource *image;
> size_t length;
>
> - if (!bridge->master_read) {
> + if (bridge && !bridge->master_read) {

This patch does not help anything. If "bridge" is NULL here then the
kernel will just crash later in the function. Smatch complains about it
now:

drivers/staging/vme_user/vme.c:688 vme_master_read() error: we previously assumed 'bridge' could be null (see line 666)

However, I don't believe that bridge can actually be NULL here. We do
not write code just to silence that static checker false positives. Fix
the checker instead.

regards,
dan carpenter