public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mfd: add null check before pointer dereference
@ 2017-05-24  8:37 Gustavo A. R. Silva
  2017-05-24  8:42 ` Charles Keepax
  2017-05-24  9:26 ` [PATCH v2] mfd: wm831x: " Gustavo A. R. Silva
  0 siblings, 2 replies; 6+ messages in thread
From: Gustavo A. R. Silva @ 2017-05-24  8:37 UTC (permalink / raw)
  To: Lee Jones, Charles Keepax; +Cc: patches, linux-kernel, Gustavo A. R. Silva

Add NULL check before dereferencing pointer of_id in order to avoid
a potential NULL pointer dereference.

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

diff --git a/drivers/mfd/wm831x-i2c.c b/drivers/mfd/wm831x-i2c.c
index 781af06..2d48f41 100644
--- a/drivers/mfd/wm831x-i2c.c
+++ b/drivers/mfd/wm831x-i2c.c
@@ -37,6 +37,10 @@ static int wm831x_i2c_probe(struct i2c_client *i2c,
 
 	if (i2c->dev.of_node) {
 		of_id = of_match_device(wm831x_of_match, &i2c->dev);
+		if (!of_id) {
+			dev_err(&i2c->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

^ permalink raw reply related	[flat|nested] 6+ messages in thread
* Re: [PATCH] mfd: add null check before pointer dereference
@ 2017-05-24  8:50 Gustavo A. R. Silva
  2017-05-24  9:18 ` [PATCH v2] mfd: wm831x: " Gustavo A. R. Silva
  0 siblings, 1 reply; 6+ messages in thread
From: Gustavo A. R. Silva @ 2017-05-24  8:50 UTC (permalink / raw)
  To: Lee Jones; +Cc: Charles Keepax, patches, linux-kernel

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

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

end of thread, other threads:[~2017-05-24 10:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-24  8:37 [PATCH] mfd: add null check before pointer dereference Gustavo A. R. Silva
2017-05-24  8:42 ` Charles Keepax
2017-05-24  9:26 ` [PATCH v2] mfd: wm831x: " Gustavo A. R. Silva
2017-05-24 10:51   ` Lee Jones
  -- strict thread matches above, loose matches on Subject: below --
2017-05-24  8:50 [PATCH] mfd: " Gustavo A. R. Silva
2017-05-24  9:18 ` [PATCH v2] mfd: wm831x: " Gustavo A. R. Silva
2017-05-24 10:52   ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox