diff mbox series

drm: mali-dp: check the return value of kzalloc()

Message ID tencent_92B89C12C6BF29881C73666E140718054E06@qq.com (mailing list archive)
State New, archived
Headers show
Series drm: mali-dp: check the return value of kzalloc() | expand

Commit Message

Xiaoke Wang March 24, 2022, 6:43 a.m. UTC
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(-)

--

Comments

Xiaoke Wang March 24, 2022, 7:52 a.m. UTC | #1
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.
diff mbox series

Patch

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