All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Tang <kevin3.tang@gmail.com>
To: maarten.lankhorst@linux.intel.com, mripard@kernel.org,
	sean@poorly.run, airlied@linux.ie, daniel@ffwll.ch,
	robh+dt@kernel.org, mark.rutland@arm.com
Cc: kevin3.tang@gmail.com, pony1.wu@gmail.com, orsonzhai@gmail.com,
	dan.carpenter@oracle.com, zou_wei@huawei.com,
	lukas.bulwahn@gmail.com, zhang.lyra@gmail.com,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	devicetree@vger.kernel.org
Subject: [PATCH v1 2/2] drm/sprd: fix potential NULL dereference
Date: Fri, 24 Dec 2021 22:12:13 +0800	[thread overview]
Message-ID: <20211224141213.27612-3-kevin3.tang@gmail.com> (raw)
In-Reply-To: <20211224141213.27612-1-kevin3.tang@gmail.com>

platform_get_resource() may fail and return NULL, so check it's value
before using it.

'drm' could be null in sprd_drm_shutdown, and drm_warn maybe dereference
it, remove this warning log.

Cc: Orson Zhai <orsonzhai@gmail.com>
Cc: Chunyan Zhang <zhang.lyra@gmail.com>
Signed-off-by: Kevin Tang <kevin.tang@unisoc.com>
---
 drivers/gpu/drm/sprd/sprd_dpu.c | 3 +++
 drivers/gpu/drm/sprd/sprd_drm.c | 8 ++------
 drivers/gpu/drm/sprd/sprd_dsi.c | 3 +++
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/sprd/sprd_dpu.c b/drivers/gpu/drm/sprd/sprd_dpu.c
index 06a3414ee..69683b7ba 100644
--- a/drivers/gpu/drm/sprd/sprd_dpu.c
+++ b/drivers/gpu/drm/sprd/sprd_dpu.c
@@ -790,6 +790,9 @@ static int sprd_dpu_context_init(struct sprd_dpu *dpu,
 	int ret;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
+
 	ctx->base = devm_ioremap(dev, res->start, resource_size(res));
 	if (!ctx->base) {
 		dev_err(dev, "failed to map dpu registers\n");
diff --git a/drivers/gpu/drm/sprd/sprd_drm.c b/drivers/gpu/drm/sprd/sprd_drm.c
index a077e2d4d..54030839e 100644
--- a/drivers/gpu/drm/sprd/sprd_drm.c
+++ b/drivers/gpu/drm/sprd/sprd_drm.c
@@ -154,12 +154,8 @@ static void sprd_drm_shutdown(struct platform_device *pdev)
 {
 	struct drm_device *drm = platform_get_drvdata(pdev);
 
-	if (!drm) {
-		drm_warn(drm, "drm device is not available, no shutdown\n");
-		return;
-	}
-
-	drm_atomic_helper_shutdown(drm);
+	if (drm)
+		drm_atomic_helper_shutdown(drm);
 }
 
 static const struct of_device_id drm_match_table[] = {
diff --git a/drivers/gpu/drm/sprd/sprd_dsi.c b/drivers/gpu/drm/sprd/sprd_dsi.c
index 911b3cddc..955c5995a 100644
--- a/drivers/gpu/drm/sprd/sprd_dsi.c
+++ b/drivers/gpu/drm/sprd/sprd_dsi.c
@@ -907,6 +907,9 @@ static int sprd_dsi_context_init(struct sprd_dsi *dsi,
 	struct resource *res;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
+
 	ctx->base = devm_ioremap(dev, res->start, resource_size(res));
 	if (!ctx->base) {
 		drm_err(dsi->drm, "failed to map dsi host registers\n");
-- 
2.29.0


WARNING: multiple messages have this Message-ID (diff)
From: Kevin Tang <kevin3.tang@gmail.com>
To: maarten.lankhorst@linux.intel.com, mripard@kernel.org,
	sean@poorly.run, airlied@linux.ie, daniel@ffwll.ch,
	robh+dt@kernel.org, mark.rutland@arm.com
Cc: devicetree@vger.kernel.org, kevin3.tang@gmail.com,
	zhang.lyra@gmail.com, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org, lukas.bulwahn@gmail.com,
	orsonzhai@gmail.com, zou_wei@huawei.com, pony1.wu@gmail.com,
	dan.carpenter@oracle.com
Subject: [PATCH v1 2/2] drm/sprd: fix potential NULL dereference
Date: Fri, 24 Dec 2021 22:12:13 +0800	[thread overview]
Message-ID: <20211224141213.27612-3-kevin3.tang@gmail.com> (raw)
In-Reply-To: <20211224141213.27612-1-kevin3.tang@gmail.com>

platform_get_resource() may fail and return NULL, so check it's value
before using it.

'drm' could be null in sprd_drm_shutdown, and drm_warn maybe dereference
it, remove this warning log.

Cc: Orson Zhai <orsonzhai@gmail.com>
Cc: Chunyan Zhang <zhang.lyra@gmail.com>
Signed-off-by: Kevin Tang <kevin.tang@unisoc.com>
---
 drivers/gpu/drm/sprd/sprd_dpu.c | 3 +++
 drivers/gpu/drm/sprd/sprd_drm.c | 8 ++------
 drivers/gpu/drm/sprd/sprd_dsi.c | 3 +++
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/sprd/sprd_dpu.c b/drivers/gpu/drm/sprd/sprd_dpu.c
index 06a3414ee..69683b7ba 100644
--- a/drivers/gpu/drm/sprd/sprd_dpu.c
+++ b/drivers/gpu/drm/sprd/sprd_dpu.c
@@ -790,6 +790,9 @@ static int sprd_dpu_context_init(struct sprd_dpu *dpu,
 	int ret;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
+
 	ctx->base = devm_ioremap(dev, res->start, resource_size(res));
 	if (!ctx->base) {
 		dev_err(dev, "failed to map dpu registers\n");
diff --git a/drivers/gpu/drm/sprd/sprd_drm.c b/drivers/gpu/drm/sprd/sprd_drm.c
index a077e2d4d..54030839e 100644
--- a/drivers/gpu/drm/sprd/sprd_drm.c
+++ b/drivers/gpu/drm/sprd/sprd_drm.c
@@ -154,12 +154,8 @@ static void sprd_drm_shutdown(struct platform_device *pdev)
 {
 	struct drm_device *drm = platform_get_drvdata(pdev);
 
-	if (!drm) {
-		drm_warn(drm, "drm device is not available, no shutdown\n");
-		return;
-	}
-
-	drm_atomic_helper_shutdown(drm);
+	if (drm)
+		drm_atomic_helper_shutdown(drm);
 }
 
 static const struct of_device_id drm_match_table[] = {
diff --git a/drivers/gpu/drm/sprd/sprd_dsi.c b/drivers/gpu/drm/sprd/sprd_dsi.c
index 911b3cddc..955c5995a 100644
--- a/drivers/gpu/drm/sprd/sprd_dsi.c
+++ b/drivers/gpu/drm/sprd/sprd_dsi.c
@@ -907,6 +907,9 @@ static int sprd_dsi_context_init(struct sprd_dsi *dsi,
 	struct resource *res;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
+
 	ctx->base = devm_ioremap(dev, res->start, resource_size(res));
 	if (!ctx->base) {
 		drm_err(dsi->drm, "failed to map dsi host registers\n");
-- 
2.29.0


  parent reply	other threads:[~2021-12-24 14:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-24 14:12 [PATCH v1 0/2] sprd drm cover letter Kevin Tang
2021-12-24 14:12 ` Kevin Tang
2021-12-24 14:12 ` [PATCH v1 1/2] drm/sprd: remove the selected DRM_KMS_CMA_HELPER in kconfig Kevin Tang
2021-12-24 14:12   ` Kevin Tang
2022-01-11  9:11   ` Javier Martinez Canillas
2022-01-11  9:11     ` Javier Martinez Canillas
2022-01-11  9:20   ` Thomas Zimmermann
2022-01-11  9:20     ` Thomas Zimmermann
2022-01-11  9:24   ` Lukas Bulwahn
2022-01-11  9:24     ` Lukas Bulwahn
2021-12-24 14:12 ` Kevin Tang [this message]
2021-12-24 14:12   ` [PATCH v1 2/2] drm/sprd: fix potential NULL dereference Kevin Tang
2022-01-11  9:18   ` Javier Martinez Canillas
2022-01-11  9:18     ` Javier Martinez Canillas
2022-01-11  9:31   ` Thomas Zimmermann
2022-01-11  9:31     ` Thomas Zimmermann

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=20211224141213.27612-3-kevin3.tang@gmail.com \
    --to=kevin3.tang@gmail.com \
    --cc=airlied@linux.ie \
    --cc=dan.carpenter@oracle.com \
    --cc=daniel@ffwll.ch \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mark.rutland@arm.com \
    --cc=mripard@kernel.org \
    --cc=orsonzhai@gmail.com \
    --cc=pony1.wu@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=sean@poorly.run \
    --cc=zhang.lyra@gmail.com \
    --cc=zou_wei@huawei.com \
    /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.