linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Pinctrl: mvebu - Fix possible NULL derefrence.
       [not found] <CGME20170130045153epcas3p37f0c1815f13d6701dd4da3c50c54b35a@epcas3p3.samsung.com>
@ 2017-01-30  4:51 ` Shailendra Verma
  2017-01-30  8:24   ` Thomas Petazzoni
  0 siblings, 1 reply; 3+ messages in thread
From: Shailendra Verma @ 2017-01-30  4:51 UTC (permalink / raw)
  To: Linus Walleij, Laxman Dewangan, Thomas Petazzoni,
	Andreas Klinger, Sebastian Hesselbarth, Andrew Lunn,
	Jamie Lentin, Rob Herring, linux-gpio, linux-kernel, p.shailesh,
	ashish.kalra, Shailendra Verma, Shailendra Verma

of_match_device could return NULL, and so can cause a NULL
pointer dereference later.

Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>
---
 drivers/pinctrl/mvebu/pinctrl-dove.c     |    4 ++++
 drivers/pinctrl/mvebu/pinctrl-kirkwood.c |    4 ++++
 drivers/pinctrl/mvebu/pinctrl-orion.c    |    4 ++++
 3 files changed, 12 insertions(+)

diff --git a/drivers/pinctrl/mvebu/pinctrl-dove.c b/drivers/pinctrl/mvebu/pinctrl-dove.c
index f93ae0d..f9fe6d4 100644
--- a/drivers/pinctrl/mvebu/pinctrl-dove.c
+++ b/drivers/pinctrl/mvebu/pinctrl-dove.c
@@ -769,6 +769,10 @@ static int dove_pinctrl_probe(struct platform_device *pdev)
 	struct resource fb_res;
 	const struct of_device_id *match =
 		of_match_device(dove_pinctrl_of_match, &pdev->dev);
+	if (!match) {
+		dev_err(&pdev->dev, "Error: No device match found\n");
+		return -ENODEV;
+	}
 	pdev->dev.platform_data = (void *)match->data;
 
 	/*
diff --git a/drivers/pinctrl/mvebu/pinctrl-kirkwood.c b/drivers/pinctrl/mvebu/pinctrl-kirkwood.c
index 5f89c26..75efb83 100644
--- a/drivers/pinctrl/mvebu/pinctrl-kirkwood.c
+++ b/drivers/pinctrl/mvebu/pinctrl-kirkwood.c
@@ -472,6 +472,10 @@ static int kirkwood_pinctrl_probe(struct platform_device *pdev)
 	struct resource *res;
 	const struct of_device_id *match =
 		of_match_device(kirkwood_pinctrl_of_match, &pdev->dev);
+	if (!match) {
+		dev_err(&pdev->dev, "Error: No device match found\n");
+		return -ENODEV;
+	}
 	pdev->dev.platform_data = (void *)match->data;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
diff --git a/drivers/pinctrl/mvebu/pinctrl-orion.c b/drivers/pinctrl/mvebu/pinctrl-orion.c
index 84e1441..559ac32 100644
--- a/drivers/pinctrl/mvebu/pinctrl-orion.c
+++ b/drivers/pinctrl/mvebu/pinctrl-orion.c
@@ -225,6 +225,10 @@ static int orion_pinctrl_probe(struct platform_device *pdev)
 		of_match_device(orion_pinctrl_of_match, &pdev->dev);
 	struct resource *res;
 
+	if (!match) {
+		dev_err(&pdev->dev, "Error: No device match found\n");
+		return -ENODEV;
+	}
 	pdev->dev.platform_data = (void*)match->data;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-- 
1.7.9.5

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

* Re: [PATCH] Pinctrl: mvebu - Fix possible NULL derefrence.
  2017-01-30  4:51 ` [PATCH] Pinctrl: mvebu - Fix possible NULL derefrence Shailendra Verma
@ 2017-01-30  8:24   ` Thomas Petazzoni
  2017-01-30 15:25     ` Linus Walleij
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Petazzoni @ 2017-01-30  8:24 UTC (permalink / raw)
  To: Shailendra Verma
  Cc: Linus Walleij, Laxman Dewangan, Andreas Klinger,
	Sebastian Hesselbarth, Andrew Lunn, Jamie Lentin, Rob Herring,
	linux-gpio, linux-kernel, p.shailesh, ashish.kalra,
	Shailendra Verma

Hello,

On Mon, 30 Jan 2017 10:21:43 +0530, Shailendra Verma wrote:
> of_match_device could return NULL, and so can cause a NULL
> pointer dereference later.
> 
> Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>

In practice, I don't see how of_match_device() can return NULL here.
Indeed, those drivers only support Device Tree based probing, so
of_match_device() will always return a non-NULL value.

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

* Re: [PATCH] Pinctrl: mvebu - Fix possible NULL derefrence.
  2017-01-30  8:24   ` Thomas Petazzoni
@ 2017-01-30 15:25     ` Linus Walleij
  0 siblings, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2017-01-30 15:25 UTC (permalink / raw)
  To: Thomas Petazzoni
  Cc: Shailendra Verma, Laxman Dewangan, Andreas Klinger,
	Sebastian Hesselbarth, Andrew Lunn, Jamie Lentin, Rob Herring,
	linux-gpio, linux-kernel, p.shailesh, ashish.kalra,
	Shailendra Verma

On Mon, Jan 30, 2017 at 9:24 AM, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:
> On Mon, 30 Jan 2017 10:21:43 +0530, Shailendra Verma wrote:
>> of_match_device could return NULL, and so can cause a NULL
>> pointer dereference later.
>>
>> Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>
>
> In practice, I don't see how of_match_device() can return NULL here.
> Indeed, those drivers only support Device Tree based probing, so
> of_match_device() will always return a non-NULL value.

OK you're right, this is too overly cautious.

Saliendra, sorry but I have to drop these patches.

Yours,
Linus Walleij

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

end of thread, other threads:[~2017-01-30 15:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20170130045153epcas3p37f0c1815f13d6701dd4da3c50c54b35a@epcas3p3.samsung.com>
2017-01-30  4:51 ` [PATCH] Pinctrl: mvebu - Fix possible NULL derefrence Shailendra Verma
2017-01-30  8:24   ` Thomas Petazzoni
2017-01-30 15:25     ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).