Skip to contentSkip to conversation

drm/loongson: Add a check for lsdc_bo_create() errors

PATCH In review Dan Carpenter 2 participants 2 messages Jul 19, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/loongson: Add a check for lsdc_bo_create() errors

This code doesn't check for lsdc_bo_create() failure and it could lead to a crash. It can fail for a variety of reasons, but the most common cause would be low memory. Add a check.

Fixes f39db26c5428 ("drm: Add kms driver for loongson display controller")

---
v2: change subject and re-word the commit message

 drivers/gpu/drm/loongson/lsdc_ttm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/loongson/lsdc_ttm.c +2 -0
index bb0c8fd43a75..bf79dc55afa4 100644
@@ -496,6 +496,8 @@ struct lsdc_bo *lsdc_bo_create_kernel_pinned(struct drm_device *ddev,
 	int ret;
 
 	lbo = lsdc_bo_create(ddev, domain, size, true, NULL, NULL);
+	if (IS_ERR(lbo))
+		return ERR_CAST(lbo);
 
 	ret = lsdc_bo_reserve(lbo);
 	if (unlikely(ret)) {
Signature · 1 line
2.39.2
#1 lore raw

Hi,

This version is ok, I'll apply this patch within a few days.

Quoted 26 lines · Dan Carpenter

This code doesn't check for lsdc_bo_create() failure and it could lead to a crash. It can fail for a variety of reasons, but the most common cause would be low memory. Add a check.

Fixes f39db26c5428 ("drm: Add kms driver for loongson display controller")

---
v2: change subject and re-word the commit message

  drivers/gpu/drm/loongson/lsdc_ttm.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/gpu/drm/loongson/lsdc_ttm.c +2 -0
index bb0c8fd43a75..bf79dc55afa4 100644
@@ -496,6 +496,8 @@ struct lsdc_bo *lsdc_bo_create_kernel_pinned(struct drm_device *ddev,
  	int ret;
 
  	lbo = lsdc_bo_create(ddev, domain, size, true, NULL, NULL);
+	if (IS_ERR(lbo))
+		return ERR_CAST(lbo);
 
  	ret = lsdc_bo_reserve(lbo);
  	if (unlikely(ret)) {