drm: vkms: check status of alloc_ordered_workqueue
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
@@ -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
Quoted 18 lines · Kangjie Lu
alloc_ordered_workqueuemay fail and return NULL. The fix returns ENOMEM when it fails to avoid potential NULL pointer dereference.Signed-off-by Kangjie Lu <[email protected]>---
drivers/gpu/drm/vkms/vkms_crtc.c| 2 ++1 file changed, 2 insertions(+)drivers/gpu/drm/vkms/vkms_crtc.c +0
-0
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
-0return ret; }Signature · 1 line
2.17.1
Quoted 20 lines · Kangjie Lu
Quoted 20 lines · Kangjie Lu
alloc_ordered_workqueuemay fail and return NULL. The fix returns ENOMEM when it fails to avoid potential NULL pointer dereference.Signed-off-by Kangjie Lu <[email protected]>---
drivers/gpu/drm/vkms/vkms_crtc.c| 2 ++1 file changed, 2 insertions(+)drivers/gpu/drm/vkms/vkms_crtc.c +0
-0@@ -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
-0vkms_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
-0return 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
Quoted 14 lines · Kangjie Lu
alloc_ordered_workqueuemay fail and return NULL. The fix returns ENOMEM when it fails to avoid potential NULL pointer dereference.Signed-off-by Kangjie Lu <[email protected]>--- drivers/gpu/drm/vkms/vkms_crtc.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/vkms/vkms_crtc.c +0
-0
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
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
@@ -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
Quoted 17 lines · Kangjie Lu
alloc_ordered_workqueuemay fail and return NULL.
The fix cleans up drm plans and returns ENOMEM when it fails to avoid potential NULL pointer dereference.Signed-off-by Kangjie Lu <[email protected]>---
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@@ -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
-0vkms_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