Skip to contentSkip to conversation

drm: vkms: check status of alloc_ordered_workqueue

PATCH Superseded Kangjie Lu 3 participants 6 messages Mar 9, 2019 – Mar 25, 2019

Subsystems (3)
lore
Share & tools
lore

Kangjie Lu

author
#0 lore raw

PATCH 1/1 drm: vkms: check status of alloc_ordered_workqueue

alloc_ordered_workqueue may fail and return NULL. The fix returns ENOMEM when it fails to avoid potential NULL pointer dereference.

---
 drivers/gpu/drm/vkms/vkms_crtc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/vkms/vkms_crtc.c +2 -0
index 8a9aeb0a9ea8..bb66dbcd5e3f 100644
@@ -219,6 +219,8 @@ int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
 	spin_lock_init(&vkms_out->state_lock);
 
 	vkms_out->crc_workq = alloc_ordered_workqueue("vkms_crc_workq", 0);
+	if (!vkms_out->crc_workq)
+		return -ENOMEM;
 
 	return ret;
 }
Signature · 1 line
2.17.1
author
#1 lore raw
Quoted 18 lines · Kangjie Lu

alloc_ordered_workqueue may fail and return NULL. The fix returns ENOMEM when it fails to avoid potential NULL pointer dereference.

---
drivers/gpu/drm/vkms/vkms_crtc.c | 2 ++

1 file changed, 2 insertions(+)
drivers/gpu/drm/vkms/vkms_crtc.c +0 -0
index 8a9aeb0a9ea8..bb66dbcd5e3f 100644

drivers/gpu/drm/vkms/vkms_crtc.c int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, · line 223

Quoted 5 lines
drivers/gpu/drm/vkms/vkms_crtc.c +2 -0
@@ -219,6 +219,8 @@ int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
 	spin_lock_init(&vkms_out->state_lock);
 
 	vkms_out->crc_workq = alloc_ordered_workqueue("vkms_crc_workq", 0);
+	if (!vkms_out->crc_workq)
+		return -ENOMEM;

Is this a reasonable patch?

Quoted 6 lines
drivers/gpu/drm/vkms/vkms_crtc.c +0 -0
 	return ret;
 }
Signature · 1 line
2.17.1
#2 lore raw
Quoted 20 lines · Kangjie Lu
Quoted 20 lines · Kangjie Lu

alloc_ordered_workqueue may fail and return NULL. The fix returns ENOMEM when it fails to avoid potential NULL pointer dereference.

---
drivers/gpu/drm/vkms/vkms_crtc.c | 2 ++

1 file changed, 2 insertions(+)
drivers/gpu/drm/vkms/vkms_crtc.c +0 -0
index 8a9aeb0a9ea8..bb66dbcd5e3f 100644
@@ -219,6 +219,8 @@ int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
 	spin_lock_init(&vkms_out->state_lock);
 
Quoted 5 lines

drivers/gpu/drm/vkms/vkms_crtc.c int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, · line 223

Quoted 3 lines
drivers/gpu/drm/vkms/vkms_crtc.c +2 -0
 	vkms_out->crc_workq = alloc_ordered_workqueue("vkms_crc_workq", 0);
+	if (!vkms_out->crc_workq)
+		return -ENOMEM;

Is this a reasonable patch?

lgtm, applied and thanks for your patch.
-Daniel

Quoted 8 lines
Quoted 7 lines
drivers/gpu/drm/vkms/vkms_crtc.c +0 -0
 	return ret;
 }
Signature · 1 line
2.17.1
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw
In reply to Kangjie Lu
Quoted 14 lines · Kangjie Lu

alloc_ordered_workqueue may fail and return NULL. The fix returns ENOMEM when it fails to avoid potential NULL pointer dereference.

---
  drivers/gpu/drm/vkms/vkms_crtc.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/gpu/drm/vkms/vkms_crtc.c +0 -0
index 8a9aeb0a9ea8..bb66dbcd5e3f 100644

drivers/gpu/drm/vkms/vkms_crtc.c int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, · line 226

Quoted 8 lines
drivers/gpu/drm/vkms/vkms_crtc.c +2 -0
@@ -219,6 +219,8 @@ int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
  	spin_lock_init(&vkms_out->state_lock);
 
  	vkms_out->crc_workq = alloc_ordered_workqueue("vkms_crc_workq", 0);
+	if (!vkms_out->crc_workq)
+		return -ENOMEM;
 
  	return ret;
  }

Check the clean up path more carefully, you have undo which you have done successfully in drm_crtc_init_with_planes.

Thanks,
 Mukesh

author
#4 lore raw

PATCH v2 1/1 drm: vkms: check status of alloc_ordered_workqueue

alloc_ordered_workqueue may fail and return NULL.
The fix cleans up drm plans and returns ENOMEM when it fails to avoid potential NULL pointer dereference.

---
V2: clean up resources

---
 drivers/gpu/drm/vkms/vkms_crtc.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/gpu/drm/vkms/vkms_crtc.c +11 -0
index 8a9aeb0a9ea8..018b52dd953a 100644
@@ -219,6 +219,17 @@ int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
 	spin_lock_init(&vkms_out->state_lock);
 
 	vkms_out->crc_workq = alloc_ordered_workqueue("vkms_crc_workq", 0);
+	if (!vkms_out->crc_workq) {
+		ret = -ENOMEM;
+		goto cleanup;
+	}
+
+	return ret;
 
+cleanup:
+	if (!IS_ERR_OR_NULL(cursor))
+		drm_plane_cleanup(cursor);
+	if (!IS_ERR(primary))
+		drm_plane_cleanup(primary);
 	return ret;
 }
Signature · 1 line
2.17.1
#5 lore raw
Quoted 17 lines · Kangjie Lu

alloc_ordered_workqueue may fail and return NULL.
The fix cleans up drm plans and returns ENOMEM when it fails to avoid potential NULL pointer dereference.

---
V2: clean up resources

---
 drivers/gpu/drm/vkms/vkms_crtc.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/gpu/drm/vkms/vkms_crtc.c +0 -0
index 8a9aeb0a9ea8..018b52dd953a 100644
@@ -219,6 +219,17 @@ int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
 	spin_lock_init(&vkms_out->state_lock);

drivers/gpu/drm/vkms/vkms_crtc.c int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, · line 229

Quoted 10 lines
drivers/gpu/drm/vkms/vkms_crtc.c +7 -0
 
 	vkms_out->crc_workq = alloc_ordered_workqueue("vkms_crc_workq", 0);
+	if (!vkms_out->crc_workq) {
+		ret = -ENOMEM;
+		goto cleanup;
+	}
+
+	return ret;
 
+cleanup:

Style nit for the future, for clarity I'd label this err:, since this path is only taken for failures, and not to do cleanup for all cases.

Aside from that, I think your v1 was correct, vkms_crtc_init only sets up the crtc, it doesn't allocate the cursor/planes. That's done from vkms_output_init, which already has the cleanup code to handle this case. -Daniel

Quoted 9 lines
drivers/gpu/drm/vkms/vkms_crtc.c +4 -0
+	if (!IS_ERR_OR_NULL(cursor))
+		drm_plane_cleanup(cursor);
+	if (!IS_ERR(primary))
+		drm_plane_cleanup(primary);
 	return ret;
 }
Signature · 1 line
2.17.1
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel