[PATCH] drm: check for allocation failure of kstrdup_const()

Li Qiong liqiong at nfschina.com
Wed Jun 15 07:53:09 UTC 2022


As the possible failure of the kstrdup_const(), it should
be better to check it and handle it.

Signed-off-by: Li Qiong <liqiong at nfschina.com>
---
 drivers/gpu/drm/drm_managed.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/drm_managed.c b/drivers/gpu/drm/drm_managed.c
index 4cf214de50c4..d9bd4a9da559 100644
--- a/drivers/gpu/drm/drm_managed.c
+++ b/drivers/gpu/drm/drm_managed.c
@@ -151,6 +151,8 @@ int __drmm_add_action(struct drm_device *dev,
 	}
 
 	dr->node.name = kstrdup_const(name, GFP_KERNEL);
+	if (!dr->node.name)
+		return -ENOMEM;
 	if (data) {
 		void_ptr = (void **)&dr->data;
 		*void_ptr = data;
@@ -197,6 +199,8 @@ void *drmm_kmalloc(struct drm_device *dev, size_t size, gfp_t gfp)
 		return NULL;
 	}
 	dr->node.name = kstrdup_const("kmalloc", GFP_KERNEL);
+	if (!dr->node.name)
+		return NULL;
 
 	add_dr(dev, dr);
 
-- 
2.25.1



More information about the dri-devel mailing list