linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm: mali-dp: check the return value of kzalloc()
@ 2022-03-24  6:43 xkernel.wang
  2022-03-24  7:52 ` Xiaoke Wang
  0 siblings, 1 reply; 2+ messages in thread
From: xkernel.wang @ 2022-03-24  6:43 UTC (permalink / raw)
  To: liviu.dudau, brian.starkey, airlied, daniel
  Cc: dri-devel, linux-kernel, Xiaoke Wang

From: Xiaoke Wang <xkernel.wang@foxmail.com>

kzalloc() is a memory allocation function which can return NULL when
some internal memory errors happen. So it is better to check it to
prevent potential wrong memory access.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
 drivers/gpu/drm/arm/malidp_mw.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arm/malidp_mw.c b/drivers/gpu/drm/arm/malidp_mw.c
index f5847a7..0720b21 100644
--- a/drivers/gpu/drm/arm/malidp_mw.c
+++ b/drivers/gpu/drm/arm/malidp_mw.c
@@ -70,7 +70,10 @@ static void malidp_mw_connector_reset(struct drm_connector *connector)
 		__drm_atomic_helper_connector_destroy_state(connector->state);
 
 	kfree(connector->state);
-	__drm_atomic_helper_connector_reset(connector, &mw_state->base);
+	connector->state = NULL;
+
+	if (mw_state)
+		__drm_atomic_helper_connector_reset(connector, &mw_state->base);
 }
 
 static enum drm_connector_status
-- 

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

* Re:[PATCH] drm: mali-dp: check the return value of kzalloc()
  2022-03-24  6:43 [PATCH] drm: mali-dp: check the return value of kzalloc() xkernel.wang
@ 2022-03-24  7:52 ` Xiaoke Wang
  0 siblings, 0 replies; 2+ messages in thread
From: Xiaoke Wang @ 2022-03-24  7:52 UTC (permalink / raw)
  To: xkernel.wang
  Cc: liviu.dudau, brian.starkey, airlied, daniel, dri-devel, linux-kernel

Thu, 24 Mar 2022 14:43:17 +0800, xkernel.wang@foxmail.com wrote:

&gt; kzalloc() is a memory allocation function which can return NULL when
&gt; some internal memory errors happen. So it is better to check it to
&gt; prevent potential wrong memory access.

Withdraw this. The original code is also fine since there is a valid check
inside __drm_atomic_helper_connector_reset() but I missed to track it.

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

end of thread, other threads:[~2022-03-24  7:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24  6:43 [PATCH] drm: mali-dp: check the return value of kzalloc() xkernel.wang
2022-03-24  7:52 ` Xiaoke Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).