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


Groups > linux.kernel > #1569384 > unrolled thread

[PATCH] pwm - Fix possible NULL derefrence.

Started byShailendra Verma <shailendra.v@samsung.com>
First post2017-01-30 06:00 +0100
Last post2017-01-30 08:20 +0100
Articles 2 — 2 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] pwm - Fix possible NULL derefrence. Shailendra Verma <shailendra.v@samsung.com> - 2017-01-30 06:00 +0100
    Re: [PATCH] pwm - Fix possible NULL derefrence. Thierry Reding <thierry.reding@gmail.com> - 2017-01-30 08:20 +0100

#1569384 — [PATCH] pwm - Fix possible NULL derefrence.

FromShailendra Verma <shailendra.v@samsung.com>
Date2017-01-30 06:00 +0100
Subject[PATCH] pwm - Fix possible NULL derefrence.
Message-ID<t5cel-804-7@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1569432

FromThierry Reding <thierry.reding@gmail.com>
Date2017-01-30 08:20 +0100
Message-ID<t5epP-15B-7@gated-at.bofh.it>
In reply to#1569384

[Multipart message — attachments visible in raw view] — view raw

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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web