[PATCH v2 3/3] drm/sprd: check the platform_get_resource() return value
Kevin Tang
kevin3.tang at gmail.com
Mon Jan 17 08:41:56 UTC 2022
platform_get_resource() may fail and return NULL, so check it's value
before using it.
Reported-by: Zou Wei <zou_wei at huawei.com>
Signed-off-by: Kevin Tang <kevin.tang at unisoc.com>
Reviewed-by: Javier Martinez Canillas <javierm at redhat.com>
Acked-by: Thomas Zimmermann <tzimmermann at suse.de>
v1 -> v2:
- new patch
---
drivers/gpu/drm/sprd/sprd_dpu.c | 5 +++++
drivers/gpu/drm/sprd/sprd_dsi.c | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/drivers/gpu/drm/sprd/sprd_dpu.c b/drivers/gpu/drm/sprd/sprd_dpu.c
index 06a3414ee..1637203ea 100644
--- a/drivers/gpu/drm/sprd/sprd_dpu.c
+++ b/drivers/gpu/drm/sprd/sprd_dpu.c
@@ -790,6 +790,11 @@ static int sprd_dpu_context_init(struct sprd_dpu *dpu,
int ret;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res) {
+ dev_err(dev, "failed to get I/O resource\n");
+ 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_dsi.c b/drivers/gpu/drm/sprd/sprd_dsi.c
index 911b3cddc..12b67a5d5 100644
--- a/drivers/gpu/drm/sprd/sprd_dsi.c
+++ b/drivers/gpu/drm/sprd/sprd_dsi.c
@@ -907,6 +907,11 @@ static int sprd_dsi_context_init(struct sprd_dsi *dsi,
struct resource *res;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res) {
+ dev_err(dev, "failed to get I/O resource\n");
+ 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
More information about the dri-devel
mailing list