All of lore.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; 8+ 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] 8+ messages in thread
* Re: [mfd] question about potential null pointer dereference
@ 2017-05-24  8:19 Gustavo A. R. Silva
  2017-05-24  8:27 ` [PATCH] mfd: add null check before " Gustavo A. R. Silva
  0 siblings, 1 reply; 8+ messages in thread
From: Gustavo A. R. Silva @ 2017-05-24  8:19 UTC (permalink / raw)
  To: Charles Keepax; +Cc: Lee Jones, patches, linux-kernel

Hi guys,

Quoting Charles Keepax <ckeepax@opensource.wolfsonmicro.com>:

> On Wed, May 24, 2017 at 08:22:58AM +0100, Lee Jones wrote:
>> On Tue, 23 May 2017, Gustavo A. R. Silva wrote:
>> > The issue here is that there is a potential NULL pointer  
>> dereference at line
>> > 37, in case function of_match_device() returns NULL.
>> >
>> > Maybe a patch like the following could be applied in order to avoid any
>> > chance of a NULL pointer dereference:
>>
>> I do not believe it's possible for of_match_device() to return NULL in
>> this case.
>>
>> However, if you wanted to submit a patch checking for it, it would not
>> be rejected.
>
> Personally I would prefer to have a NULL pointer check in there.
>

I'll send a patch shortly.

Thank you both.
--
Gustavo A. R. Silva

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

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

Thread overview: 8+ 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:19 [mfd] question about potential null " Gustavo A. R. Silva
2017-05-24  8:27 ` [PATCH] mfd: add null check before " Gustavo A. R. Silva
2017-05-24  8:41   ` Charles Keepax
2017-05-24  8:43   ` Lee Jones
2017-05-24  8:50     ` Gustavo A. R. Silva

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.