All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aditya Pakki <pakki001@umn.edu>
To: pakki001@umn.edu
Cc: kjlu@umn.edu, Jaehoon Chung <jh80.chung@samsung.com>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Kukjin Kim <kgene@kernel.org>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	Heiko Stuebner <heiko@sntech.de>, Jun Nie <jun.nie@linaro.org>,
	Shawn Guo <shawnguo@kernel.org>,
	linux-mmc@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-rockchip@lists.infradead.org
Subject: [PATCH v2] mmc: dw_mmc: Fix to avoid potential NULL pointer dereference
Date: Mon, 18 Mar 2019 20:45:51 -0500	[thread overview]
Message-ID: <20190319014551.16559-1-pakki001@umn.edu> (raw)

of_match_node can fail and return NULL in case no matching structure.
The patches checks for such a scenario and returns -ENXIO.

---
V1: Added files dw_mmc-zx.c and dw_mmc-rockchip.c

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
 drivers/mmc/host/dw_mmc-exynos.c   | 2 ++
 drivers/mmc/host/dw_mmc-k3.c       | 2 ++
 drivers/mmc/host/dw_mmc-pltfm.c    | 2 ++
 drivers/mmc/host/dw_mmc-rockchip.c | 2 ++
 drivers/mmc/host/dw_mmc-zx.c       | 2 ++
 5 files changed, 10 insertions(+)

diff --git a/drivers/mmc/host/dw_mmc-exynos.c b/drivers/mmc/host/dw_mmc-exynos.c
index d46c3439b508..8a75d7314606 100644
--- a/drivers/mmc/host/dw_mmc-exynos.c
+++ b/drivers/mmc/host/dw_mmc-exynos.c
@@ -554,6 +554,8 @@ static int dw_mci_exynos_probe(struct platform_device *pdev)
 	int ret;
 
 	match = of_match_node(dw_mci_exynos_match, pdev->dev.of_node);
+	if (!match)
+		return -ENXIO;
 	drv_data = match->data;
 
 	pm_runtime_get_noresume(&pdev->dev);
diff --git a/drivers/mmc/host/dw_mmc-k3.c b/drivers/mmc/host/dw_mmc-k3.c
index 89cdb3d533bb..cc50b7546a20 100644
--- a/drivers/mmc/host/dw_mmc-k3.c
+++ b/drivers/mmc/host/dw_mmc-k3.c
@@ -459,6 +459,8 @@ static int dw_mci_k3_probe(struct platform_device *pdev)
 	const struct of_device_id *match;
 
 	match = of_match_node(dw_mci_k3_match, pdev->dev.of_node);
+	if (!match)
+		return -ENXIO;
 	drv_data = match->data;
 
 	return dw_mci_pltfm_register(pdev, drv_data);
diff --git a/drivers/mmc/host/dw_mmc-pltfm.c b/drivers/mmc/host/dw_mmc-pltfm.c
index 58c13e21bd5a..b1948989f617 100644
--- a/drivers/mmc/host/dw_mmc-pltfm.c
+++ b/drivers/mmc/host/dw_mmc-pltfm.c
@@ -82,6 +82,8 @@ static int dw_mci_pltfm_probe(struct platform_device *pdev)
 
 	if (pdev->dev.of_node) {
 		match = of_match_node(dw_mci_pltfm_match, pdev->dev.of_node);
+		if (!match)
+			return -ENXIO;
 		drv_data = match->data;
 	}
 
diff --git a/drivers/mmc/host/dw_mmc-rockchip.c b/drivers/mmc/host/dw_mmc-rockchip.c
index 8c86a800a8fd..20e3471260ea 100644
--- a/drivers/mmc/host/dw_mmc-rockchip.c
+++ b/drivers/mmc/host/dw_mmc-rockchip.c
@@ -344,6 +344,8 @@ static int dw_mci_rockchip_probe(struct platform_device *pdev)
 		return -ENODEV;
 
 	match = of_match_node(dw_mci_rockchip_match, pdev->dev.of_node);
+	if (!match)
+		return -ENXIO;
 	drv_data = match->data;
 
 	pm_runtime_get_noresume(&pdev->dev);
diff --git a/drivers/mmc/host/dw_mmc-zx.c b/drivers/mmc/host/dw_mmc-zx.c
index c06b5393312f..abea35431045 100644
--- a/drivers/mmc/host/dw_mmc-zx.c
+++ b/drivers/mmc/host/dw_mmc-zx.c
@@ -213,6 +213,8 @@ static int dw_mci_zx_probe(struct platform_device *pdev)
 	const struct of_device_id *match;
 
 	match = of_match_node(dw_mci_zx_match, pdev->dev.of_node);
+	if (!match)
+		return -ENXIO;
 	drv_data = match->data;
 
 	return dw_mci_pltfm_register(pdev, drv_data);
-- 
2.17.1


WARNING: multiple messages have this Message-ID
From: Aditya Pakki <pakki001@umn.edu>
To: pakki001@umn.edu
Cc: Ulf Hansson <ulf.hansson@linaro.org>,
	linux-samsung-soc@vger.kernel.org,
	Heiko Stuebner <heiko@sntech.de>,
	linux-mmc@vger.kernel.org, kjlu@umn.edu,
	linux-kernel@vger.kernel.org,
	Krzysztof Kozlowski <krzk@kernel.org>,
	Jaehoon Chung <jh80.chung@samsung.com>,
	linux-rockchip@lists.infradead.org, Kukjin Kim <kgene@kernel.org>,
	Jun Nie <jun.nie@linaro.org>, Shawn Guo <shawnguo@kernel.org>,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2] mmc: dw_mmc: Fix to avoid potential NULL pointer dereference
Date: Mon, 18 Mar 2019 20:45:51 -0500	[thread overview]
Message-ID: <20190319014551.16559-1-pakki001@umn.edu> (raw)

of_match_node can fail and return NULL in case no matching structure.
The patches checks for such a scenario and returns -ENXIO.

---
V1: Added files dw_mmc-zx.c and dw_mmc-rockchip.c

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
 drivers/mmc/host/dw_mmc-exynos.c   | 2 ++
 drivers/mmc/host/dw_mmc-k3.c       | 2 ++
 drivers/mmc/host/dw_mmc-pltfm.c    | 2 ++
 drivers/mmc/host/dw_mmc-rockchip.c | 2 ++
 drivers/mmc/host/dw_mmc-zx.c       | 2 ++
 5 files changed, 10 insertions(+)

diff --git a/drivers/mmc/host/dw_mmc-exynos.c b/drivers/mmc/host/dw_mmc-exynos.c
index d46c3439b508..8a75d7314606 100644
--- a/drivers/mmc/host/dw_mmc-exynos.c
+++ b/drivers/mmc/host/dw_mmc-exynos.c
@@ -554,6 +554,8 @@ static int dw_mci_exynos_probe(struct platform_device *pdev)
 	int ret;
 
 	match = of_match_node(dw_mci_exynos_match, pdev->dev.of_node);
+	if (!match)
+		return -ENXIO;
 	drv_data = match->data;
 
 	pm_runtime_get_noresume(&pdev->dev);
diff --git a/drivers/mmc/host/dw_mmc-k3.c b/drivers/mmc/host/dw_mmc-k3.c
index 89cdb3d533bb..cc50b7546a20 100644
--- a/drivers/mmc/host/dw_mmc-k3.c
+++ b/drivers/mmc/host/dw_mmc-k3.c
@@ -459,6 +459,8 @@ static int dw_mci_k3_probe(struct platform_device *pdev)
 	const struct of_device_id *match;
 
 	match = of_match_node(dw_mci_k3_match, pdev->dev.of_node);
+	if (!match)
+		return -ENXIO;
 	drv_data = match->data;
 
 	return dw_mci_pltfm_register(pdev, drv_data);
diff --git a/drivers/mmc/host/dw_mmc-pltfm.c b/drivers/mmc/host/dw_mmc-pltfm.c
index 58c13e21bd5a..b1948989f617 100644
--- a/drivers/mmc/host/dw_mmc-pltfm.c
+++ b/drivers/mmc/host/dw_mmc-pltfm.c
@@ -82,6 +82,8 @@ static int dw_mci_pltfm_probe(struct platform_device *pdev)
 
 	if (pdev->dev.of_node) {
 		match = of_match_node(dw_mci_pltfm_match, pdev->dev.of_node);
+		if (!match)
+			return -ENXIO;
 		drv_data = match->data;
 	}
 
diff --git a/drivers/mmc/host/dw_mmc-rockchip.c b/drivers/mmc/host/dw_mmc-rockchip.c
index 8c86a800a8fd..20e3471260ea 100644
--- a/drivers/mmc/host/dw_mmc-rockchip.c
+++ b/drivers/mmc/host/dw_mmc-rockchip.c
@@ -344,6 +344,8 @@ static int dw_mci_rockchip_probe(struct platform_device *pdev)
 		return -ENODEV;
 
 	match = of_match_node(dw_mci_rockchip_match, pdev->dev.of_node);
+	if (!match)
+		return -ENXIO;
 	drv_data = match->data;
 
 	pm_runtime_get_noresume(&pdev->dev);
diff --git a/drivers/mmc/host/dw_mmc-zx.c b/drivers/mmc/host/dw_mmc-zx.c
index c06b5393312f..abea35431045 100644
--- a/drivers/mmc/host/dw_mmc-zx.c
+++ b/drivers/mmc/host/dw_mmc-zx.c
@@ -213,6 +213,8 @@ static int dw_mci_zx_probe(struct platform_device *pdev)
 	const struct of_device_id *match;
 
 	match = of_match_node(dw_mci_zx_match, pdev->dev.of_node);
+	if (!match)
+		return -ENXIO;
 	drv_data = match->data;
 
 	return dw_mci_pltfm_register(pdev, drv_data);
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2019-03-19  1:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-19  1:45 Aditya Pakki [this message]
2019-03-19  1:45 ` [PATCH v2] mmc: dw_mmc: Fix to avoid potential NULL pointer dereference Aditya Pakki
2019-03-19 11:09 ` Robin Murphy
2019-03-19 11:09   ` Robin Murphy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190319014551.16559-1-pakki001@umn.edu \
    --to=pakki001@umn.edu \
    --cc=heiko@sntech.de \
    --cc=jh80.chung@samsung.com \
    --cc=jun.nie@linaro.org \
    --cc=kgene@kernel.org \
    --cc=kjlu@umn.edu \
    --cc=krzk@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=shawnguo@kernel.org \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.