linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pwm - Fix possible NULL derefrence.
       [not found] <CGME20170130045241epcas1p2a5a0625327e4caab59236ec85551f95e@epcas1p2.samsung.com>
@ 2017-01-30  4:52 ` Shailendra Verma
  2017-01-30  7:10   ` Thierry Reding
  0 siblings, 1 reply; 2+ messages in thread
From: Shailendra Verma @ 2017-01-30  4:52 UTC (permalink / raw)
  To: Thierry Reding, Maxime Ripard, Chen-Yu Tsai, Stephen Warren,
	Alexandre Courbot, linux-pwm, linux-arm-kernel, linux-tegra,
	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/pwm/pwm-sun4i.c |    4 ++++
 drivers/pwm/pwm-tegra.c |    5 +++++
 2 files changed, 9 insertions(+)

diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
index b0803f6..9b5c6fe 100644
--- a/drivers/pwm/pwm-sun4i.c
+++ b/drivers/pwm/pwm-sun4i.c
@@ -321,6 +321,10 @@ static int sun4i_pwm_probe(struct platform_device *pdev)
 	const struct of_device_id *match;
 
 	match = of_match_device(sun4i_pwm_dt_ids, &pdev->dev);
+	if (!match) {
+		dev_err(&pdev->dev, "Error: No device match found\n");
+		return -ENODEV;
+	}
 
 	pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
 	if (!pwm)
diff --git a/drivers/pwm/pwm-tegra.c b/drivers/pwm/pwm-tegra.c
index e464784..a5eb224 100644
--- a/drivers/pwm/pwm-tegra.c
+++ b/drivers/pwm/pwm-tegra.c
@@ -185,6 +185,11 @@ static int tegra_pwm_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	pwm->soc = of_device_get_match_data(&pdev->dev);
+	if (!pwm->soc) {
+		dev_err(&pdev->dev, "no device match found\n");
+		return -ENODEV;
+	}
+
 	pwm->dev = &pdev->dev;
 
 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-- 
1.7.9.5

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

* Re: [PATCH] pwm - Fix possible NULL derefrence.
  2017-01-30  4:52 ` [PATCH] pwm - Fix possible NULL derefrence Shailendra Verma
@ 2017-01-30  7:10   ` Thierry Reding
  0 siblings, 0 replies; 2+ messages in thread
From: Thierry Reding @ 2017-01-30  7:10 UTC (permalink / raw)
  To: Shailendra Verma
  Cc: Maxime Ripard, Chen-Yu Tsai, Stephen Warren, Alexandre Courbot,
	linux-pwm, linux-arm-kernel, linux-tegra, linux-kernel,
	p.shailesh, ashish.kalra, Shailendra Verma

[-- Attachment #1: Type: text/plain, Size: 453 bytes --]

On Mon, Jan 30, 2017 at 10:22:33AM +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>
> ---
>  drivers/pwm/pwm-sun4i.c |    4 ++++
>  drivers/pwm/pwm-tegra.c |    5 +++++
>  2 files changed, 9 insertions(+)

Both of these drivers will only run on purely OF systems, so this check
is unnecessary.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20170130045241epcas1p2a5a0625327e4caab59236ec85551f95e@epcas1p2.samsung.com>
2017-01-30  4:52 ` [PATCH] pwm - Fix possible NULL derefrence Shailendra Verma
2017-01-30  7:10   ` Thierry Reding

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).