All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] drm/sprd: fix potential NULL dereference
@ 2021-12-14  9:11 ` Zou Wei
  0 siblings, 0 replies; 4+ messages in thread
From: Zou Wei @ 2021-12-14  9:11 UTC (permalink / raw)
  To: airlied, daniel, orsonzhai, baolin.wang7, zhang.lyra,
	maarten.lankhorst, kevin3.tang, maxime
  Cc: dri-devel, linux-kernel, Zou Wei

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 <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
---
 drivers/gpu/drm/sprd/sprd_dpu.c | 2 ++
 drivers/gpu/drm/sprd/sprd_dsi.c | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/sprd/sprd_dpu.c b/drivers/gpu/drm/sprd/sprd_dpu.c
index 06a3414..920cb7d 100644
--- a/drivers/gpu/drm/sprd/sprd_dpu.c
+++ b/drivers/gpu/drm/sprd/sprd_dpu.c
@@ -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");
diff --git a/drivers/gpu/drm/sprd/sprd_dsi.c b/drivers/gpu/drm/sprd/sprd_dsi.c
index 911b3cd..c90a950 100644
--- a/drivers/gpu/drm/sprd/sprd_dsi.c
+++ b/drivers/gpu/drm/sprd/sprd_dsi.c
@@ -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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH -next] drm/sprd: fix potential NULL dereference
@ 2021-12-14  9:11 ` Zou Wei
  0 siblings, 0 replies; 4+ messages in thread
From: Zou Wei @ 2021-12-14  9:11 UTC (permalink / raw)
  To: airlied, daniel, orsonzhai, baolin.wang7, zhang.lyra,
	maarten.lankhorst, kevin3.tang, maxime
  Cc: Zou Wei, linux-kernel, dri-devel

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 <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
---
 drivers/gpu/drm/sprd/sprd_dpu.c | 2 ++
 drivers/gpu/drm/sprd/sprd_dsi.c | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/sprd/sprd_dpu.c b/drivers/gpu/drm/sprd/sprd_dpu.c
index 06a3414..920cb7d 100644
--- a/drivers/gpu/drm/sprd/sprd_dpu.c
+++ b/drivers/gpu/drm/sprd/sprd_dpu.c
@@ -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");
diff --git a/drivers/gpu/drm/sprd/sprd_dsi.c b/drivers/gpu/drm/sprd/sprd_dsi.c
index 911b3cd..c90a950 100644
--- a/drivers/gpu/drm/sprd/sprd_dsi.c
+++ b/drivers/gpu/drm/sprd/sprd_dsi.c
@@ -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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH -next] drm/sprd: fix potential NULL dereference
  2021-12-14  9:11 ` Zou Wei
@ 2021-12-18 16:23   ` Kevin Tang
  -1 siblings, 0 replies; 4+ messages in thread
From: Kevin Tang @ 2021-12-18 16:23 UTC (permalink / raw)
  To: Zou Wei
  Cc: airlied, daniel, orsonzhai, baolin.wang7, zhang.lyra,
	maarten.lankhorst, maxime, dri-devel, linux-kernel

Dear Wei,
Thank you for your notice. I have received it. I will be fix it later.

Best wishes

Zou Wei <zou_wei@huawei.com> 于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 <hulkci@huawei.com>
> Signed-off-by: Zou Wei <zou_wei@huawei.com>
> ---
>  drivers/gpu/drm/sprd/sprd_dpu.c | 2 ++
>  drivers/gpu/drm/sprd/sprd_dsi.c | 2 ++
>  2 files changed, 4 insertions(+)
>
> diff --git a/drivers/gpu/drm/sprd/sprd_dpu.c b/drivers/gpu/drm/sprd/sprd_dpu.c
> index 06a3414..920cb7d 100644
> --- a/drivers/gpu/drm/sprd/sprd_dpu.c
> +++ b/drivers/gpu/drm/sprd/sprd_dpu.c
> @@ -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");
> diff --git a/drivers/gpu/drm/sprd/sprd_dsi.c b/drivers/gpu/drm/sprd/sprd_dsi.c
> index 911b3cd..c90a950 100644
> --- a/drivers/gpu/drm/sprd/sprd_dsi.c
> +++ b/drivers/gpu/drm/sprd/sprd_dsi.c
> @@ -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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -next] drm/sprd: fix potential NULL dereference
@ 2021-12-18 16:23   ` Kevin Tang
  0 siblings, 0 replies; 4+ messages in thread
From: Kevin Tang @ 2021-12-18 16:23 UTC (permalink / raw)
  To: Zou Wei
  Cc: airlied, zhang.lyra, linux-kernel, dri-devel, maxime,
	baolin.wang7, orsonzhai

Dear Wei,
Thank you for your notice. I have received it. I will be fix it later.

Best wishes

Zou Wei <zou_wei@huawei.com> 于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 <hulkci@huawei.com>
> Signed-off-by: Zou Wei <zou_wei@huawei.com>
> ---
>  drivers/gpu/drm/sprd/sprd_dpu.c | 2 ++
>  drivers/gpu/drm/sprd/sprd_dsi.c | 2 ++
>  2 files changed, 4 insertions(+)
>
> diff --git a/drivers/gpu/drm/sprd/sprd_dpu.c b/drivers/gpu/drm/sprd/sprd_dpu.c
> index 06a3414..920cb7d 100644
> --- a/drivers/gpu/drm/sprd/sprd_dpu.c
> +++ b/drivers/gpu/drm/sprd/sprd_dpu.c
> @@ -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");
> diff --git a/drivers/gpu/drm/sprd/sprd_dsi.c b/drivers/gpu/drm/sprd/sprd_dsi.c
> index 911b3cd..c90a950 100644
> --- a/drivers/gpu/drm/sprd/sprd_dsi.c
> +++ b/drivers/gpu/drm/sprd/sprd_dsi.c
> @@ -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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-18 16:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-14  9:11 [PATCH -next] drm/sprd: fix potential NULL dereference Zou Wei
2021-12-14  9:11 ` Zou Wei
2021-12-18 16:23 ` Kevin Tang
2021-12-18 16:23   ` Kevin Tang

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.