drm/sprd: fix potential NULL dereference
Subsystems (3)
PATCH 1/1 drm/sprd: fix potential NULL dereference
platform_get_resource() may fail and return NULL, so we should better check it's return value to avoid a NULL pointer dereference a bit later in the code.
Reported-by Hulk Robot <[email protected]>
Signed-off-by Zou Wei <[email protected]>
--- drivers/gpu/drm/sprd/sprd_dpu.c | 2 ++ drivers/gpu/drm/sprd/sprd_dsi.c | 2 ++ 2 files changed, 4 insertions(+)
drivers/gpu/drm/sprd/sprd_dpu.c +2 -0
@@ -790,6 +790,8 @@ 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" );
drivers/gpu/drm/sprd/sprd_dsi.c +2 -0
@@ -907,6 +907,8 @@ 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" );
Signature · 1 line
2.6.2
Dear Wei,
Thank you for your notice. I have received it. I will be fix it later.
Best wishes
Quoted 41 lines · Zou Wei <[email protected]> 于2021年12月14日周二 17:11写道:
platform_get_resource()may fail and return NULL, so we should better check it's return value to avoid a NULL pointer dereference a bit later in the code.Reported-by Hulk Robot <[email protected]>Signed-off-by Zou Wei <[email protected]>--- drivers/gpu/drm/sprd/sprd_dpu.c | 2 ++ drivers/gpu/drm/sprd/sprd_dsi.c | 2 ++ 2 files changed, 4 insertions(+)drivers/gpu/drm/sprd/sprd_dpu.c +2
-0@@ -790,6 +790,8 @@ 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" );drivers/gpu/drm/sprd/sprd_dsi.c +2
-1@@ -907,6 +907,8 @@ 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.6.2