Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1649241 > unrolled thread

[PATCH] mfd: add null check before pointer dereference

Started by"Gustavo A. R. Silva" <garsilva@embeddedor.com>
First post2017-05-24 10:30 +0200
Last post2017-05-24 13:00 +0200
Articles 6 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH] mfd: add null check before pointer dereference "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-05-24 10:30 +0200
    Re: [PATCH] mfd: add null check before pointer dereference Charles Keepax <ckeepax@opensource.wolfsonmicro.com> - 2017-05-24 10:50 +0200
    Re: [PATCH] mfd: add null check before pointer dereference Lee Jones <lee.jones@linaro.org> - 2017-05-24 10:50 +0200
      Re: [PATCH] mfd: add null check before pointer dereference "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-05-24 11:00 +0200
        [PATCH v2] mfd: wm831x: add null check before pointer dereference "Gustavo A. R. Silva" <garsilva@embeddedor.com> - 2017-05-24 11:20 +0200
          Re: [PATCH v2] mfd: wm831x: add null check before pointer dereference Lee Jones <lee.jones@linaro.org> - 2017-05-24 13:00 +0200

#1649241 — [PATCH] mfd: add null check before pointer dereference

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-05-24 10:30 +0200
Subject[PATCH] mfd: add null check before pointer dereference
Message-ID<tKzQ7-8hN-37@gated-at.bofh.it>
Add null check before dereferencing pointer of_id in order to avoid
a potential NULL pointer dereference.

Addresses-Coverity-ID: 1408830
Cc: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 drivers/mfd/wm831x-spi.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/mfd/wm831x-spi.c b/drivers/mfd/wm831x-spi.c
index c332e28..7b227c9 100644
--- a/drivers/mfd/wm831x-spi.c
+++ b/drivers/mfd/wm831x-spi.c
@@ -34,6 +34,10 @@ static int wm831x_spi_probe(struct spi_device *spi)
 
 	if (spi->dev.of_node) {
 		of_id = of_match_device(wm831x_of_match, &spi->dev);
+		if (!of_id) {
+			dev_err(&spi->dev, "Failed to find matching id\n");
+			return -EINVAL;
+		}
 		type = (enum wm831x_parent)of_id->data;
 	} else {
 		type = (enum wm831x_parent)id->driver_data;
-- 
2.5.0

[toc] | [next] | [standalone]


#1649299

FromCharles Keepax <ckeepax@opensource.wolfsonmicro.com>
Date2017-05-24 10:50 +0200
Message-ID<tKA9r-8rl-17@gated-at.bofh.it>
In reply to#1649241
On Wed, May 24, 2017 at 03:27:31AM -0500, Gustavo A. R. Silva wrote:
> Add null check before dereferencing pointer of_id in order to avoid
> a potential NULL pointer dereference.
> 
> Addresses-Coverity-ID: 1408830
> Cc: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---

Acked-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>

Looks good although is there not probably the same issue in
wm831x-i2c.c? Might be worth fixing up both of them.

Thanks,
Charles

[toc] | [prev] | [next] | [standalone]


#1649302

FromLee Jones <lee.jones@linaro.org>
Date2017-05-24 10:50 +0200
Message-ID<tKA9s-8rl-27@gated-at.bofh.it>
In reply to#1649241
Please use the $SUBJECT line expected by the subsystem.

The following command can help with this:

  `git log --oneline -- <SUBSYSTEM>`

> Add null check before dereferencing pointer of_id in order to avoid
> a potential NULL pointer dereference.
> 
> Addresses-Coverity-ID: 1408830
> Cc: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---
>  drivers/mfd/wm831x-spi.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/mfd/wm831x-spi.c b/drivers/mfd/wm831x-spi.c
> index c332e28..7b227c9 100644
> --- a/drivers/mfd/wm831x-spi.c
> +++ b/drivers/mfd/wm831x-spi.c
> @@ -34,6 +34,10 @@ static int wm831x_spi_probe(struct spi_device *spi)
>  
>  	if (spi->dev.of_node) {
>  		of_id = of_match_device(wm831x_of_match, &spi->dev);
> +		if (!of_id) {
> +			dev_err(&spi->dev, "Failed to find matching id\n");
> +			return -EINVAL;
> +		}

I already mentioned why this isn't suitable.

Please see my pre-review.

>  		type = (enum wm831x_parent)of_id->data;
>  	} else {
>  		type = (enum wm831x_parent)id->driver_data;

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

[toc] | [prev] | [next] | [standalone]


#1649319

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-05-24 11:00 +0200
Message-ID<tKAj8-8uU-3@gated-at.bofh.it>
In reply to#1649302
Hi Lee,

Quoting Lee Jones <lee.jones@linaro.org>:

> Please use the $SUBJECT line expected by the subsystem.
>
> The following command can help with this:
>
>   `git log --oneline -- <SUBSYSTEM>`
>

I get it.

>> Add null check before dereferencing pointer of_id in order to avoid
>> a potential NULL pointer dereference.
>>
>> Addresses-Coverity-ID: 1408830
>> Cc: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
>> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>> ---
>>  drivers/mfd/wm831x-spi.c | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/drivers/mfd/wm831x-spi.c b/drivers/mfd/wm831x-spi.c
>> index c332e28..7b227c9 100644
>> --- a/drivers/mfd/wm831x-spi.c
>> +++ b/drivers/mfd/wm831x-spi.c
>> @@ -34,6 +34,10 @@ static int wm831x_spi_probe(struct spi_device *spi)
>>
>>  	if (spi->dev.of_node) {
>>  		of_id = of_match_device(wm831x_of_match, &spi->dev);
>> +		if (!of_id) {
>> +			dev_err(&spi->dev, "Failed to find matching id\n");
>> +			return -EINVAL;
>> +		}
>
> I already mentioned why this isn't suitable.
>
> Please see my pre-review.
>

You are right. Let me fix that.

Thanks
--
Gustavo A. R. Silva

[toc] | [prev] | [next] | [standalone]


#1649362 — [PATCH v2] mfd: wm831x: add null check before pointer dereference

From"Gustavo A. R. Silva" <garsilva@embeddedor.com>
Date2017-05-24 11:20 +0200
Subject[PATCH v2] mfd: wm831x: add null check before pointer dereference
Message-ID<tKACt-pV-3@gated-at.bofh.it>
In reply to#1649319
Add NULL check before dereferencing pointer of_id in order to avoid
a potential NULL pointer dereference.

Addresses-Coverity-ID: 1408830
Cc: Lee Jones <lee.jones@linaro.org>
Cc: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
Changes in v2:
 Update error log and return value.

 drivers/mfd/wm831x-spi.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/mfd/wm831x-spi.c b/drivers/mfd/wm831x-spi.c
index c332e28..018ce65 100644
--- a/drivers/mfd/wm831x-spi.c
+++ b/drivers/mfd/wm831x-spi.c
@@ -34,6 +34,10 @@ static int wm831x_spi_probe(struct spi_device *spi)
 
 	if (spi->dev.of_node) {
 		of_id = of_match_device(wm831x_of_match, &spi->dev);
+		if (!of_id) {
+			dev_err(&spi->dev, "Failed to match device\n");
+			return -ENODEV;
+		}
 		type = (enum wm831x_parent)of_id->data;
 	} else {
 		type = (enum wm831x_parent)id->driver_data;
-- 
2.5.0

[toc] | [prev] | [next] | [standalone]


#1649462 — Re: [PATCH v2] mfd: wm831x: add null check before pointer dereference

FromLee Jones <lee.jones@linaro.org>
Date2017-05-24 13:00 +0200
SubjectRe: [PATCH v2] mfd: wm831x: add null check before pointer dereference
Message-ID<tKCbg-1hF-23@gated-at.bofh.it>
In reply to#1649362
On Wed, 24 May 2017, Gustavo A. R. Silva wrote:

> Add NULL check before dereferencing pointer of_id in order to avoid
> a potential NULL pointer dereference.
> 
> Addresses-Coverity-ID: 1408830
> Cc: Lee Jones <lee.jones@linaro.org>
> Cc: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---
> Changes in v2:
>  Update error log and return value.
> 
>  drivers/mfd/wm831x-spi.c | 4 ++++
>  1 file changed, 4 insertions(+)

Applied, thanks.

> diff --git a/drivers/mfd/wm831x-spi.c b/drivers/mfd/wm831x-spi.c
> index c332e28..018ce65 100644
> --- a/drivers/mfd/wm831x-spi.c
> +++ b/drivers/mfd/wm831x-spi.c
> @@ -34,6 +34,10 @@ static int wm831x_spi_probe(struct spi_device *spi)
>  
>  	if (spi->dev.of_node) {
>  		of_id = of_match_device(wm831x_of_match, &spi->dev);
> +		if (!of_id) {
> +			dev_err(&spi->dev, "Failed to match device\n");
> +			return -ENODEV;
> +		}
>  		type = (enum wm831x_parent)of_id->data;
>  	} else {
>  		type = (enum wm831x_parent)id->driver_data;

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web