drm/mgag200: Fix error handling paths in fbdev driver
Subsystems (3)
PATCH 1/2 drm/mgag200: Fix error handling paths in fbdev driver
Set up error handling in mgag200_fbdev_init and mgag200fb_create such that they release the things they allocate, rather than relying on someone calling mga_fbdev_destroy.
Based on a patch by Sudip Mukherjee <[email protected]>
Reported-by Ingo Molnar <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Dave Airlie <[email protected]>
Cc David Airlie <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Sudip Mukherjee <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc dri-devel <[email protected]>
Signed-off-by Archit Taneja <[email protected]>
--- drivers/gpu/drm/mgag200/mgag200_fb.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)
drivers/gpu/drm/mgag200/mgag200_fb.c +23 -8
@@ -186,17 +186,19 @@ static int mgag200fb_create(struct drm_fb_helper *helper, sysram =vmalloc (size);if (!sysram) -return -ENOMEM ; + goto err_sysram; info =drm_fb_helper_alloc_fbi (helper); -if (IS_ERR (info)) -return PTR_ERR (info); +if (IS_ERR (info)) { + ret =PTR_ERR (info); + goto err_alloc_fbi; + } info->par = mfbdev; ret =mgag200_framebuffer_init (dev, &mfbdev->mfb, &mode_cmd, gobj);if (ret) -return ret; + goto err_framebuffer_init; mfbdev->sysram = sysram; mfbdev->size = size;
@@ -225,7 +227,17 @@ static int mgag200fb_create(struct drm_fb_helper *helper,DRM_DEBUG_KMS ("allocated %dx%d\n" , fb->width, fb->height); +return 0 ; + +err_framebuffer_init: +drm_fb_helper_release_fbi (helper); +err_alloc_fbi: +vfree (sysram); +err_sysram: +drm_gem_object_unreference_unlocked (gobj); + +return ret; } static int mga_fbdev_destroy(struct drm_device *dev,
@@ -276,23 +288,26 @@ int mgag200_fbdev_init(struct mga_device *mdev) ret =drm_fb_helper_init (mdev->dev, &mfbdev->helper, mdev->num_crtc,MGAG200FB_CONN_LIMIT );if (ret) -return ret; + goto err_fb_helper; ret =drm_fb_helper_single_add_all_connectors (&mfbdev->helper);if (ret) - goto fini; + goto err_fb_setup;/* disable all the possible outputs/crtcs before entering KMS mode */ drm_helper_disable_unused_functions (mdev->dev); ret =drm_fb_helper_initial_config (&mfbdev->helper, bpp_sel);if (ret) - goto fini; + goto err_fb_setup;return 0 ; -fini: +err_fb_setup:drm_fb_helper_fini (&mfbdev->helper); +err_fb_helper: + mdev->mfbdev =NULL ; +return ret; }
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/2 drm/mgag200: Fix driver_load error handling
mgag200_driver_load's error path just calls the drm driver's driver_unload op. It isn't safe to call this because it doesn't handle things well if driver_load fails somewhere mid way.
Replace the call to mgag200_driver_unload with a more finegrained error handling path.
Reported-by Ingo Molnar <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Dave Airlie <[email protected]>
Cc David Airlie <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Sudip Mukherjee <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc dri-devel <[email protected]>
Signed-off-by Archit Taneja <[email protected]>
--- drivers/gpu/drm/mgag200/mgag200_main.c | 36 +++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 16 deletions(-)
drivers/gpu/drm/mgag200/mgag200_main.c +20 -16
@@ -220,7 +220,7 @@ int mgag200_driver_load(struct drm_device *dev, unsigned long flags) } r =mgag200_mm_init (mdev);if (r) - goto out; + goto err_mm;drm_mode_config_init (dev); dev->mode_config.funcs = (void *)&mga_mode_funcs;
@@ -233,7 +233,7 @@ int mgag200_driver_load(struct drm_device *dev, unsigned long flags) r =mgag200_modeset_init (mdev);if (r) {dev_err (&dev->pdev->dev,"Fatal error during modeset init: %d\n" , r); - goto out; + goto err_modeset; }/* Make small buffers to store a hardware cursor (double buffered icon updates) */
@@ -241,20 +241,24 @@ int mgag200_driver_load(struct drm_device *dev, unsigned long flags) &mdev->cursor.pixels_1);mgag200_bo_create (dev,roundup (48 *64 ,PAGE_SIZE ),0 ,0 , &mdev->cursor.pixels_2); -if (!mdev->cursor.pixels_2 || !mdev->cursor.pixels_1) - goto cursor_nospace; - mdev->cursor.pixels_current = mdev->cursor.pixels_1; - mdev->cursor.pixels_prev = mdev->cursor.pixels_2; - goto cursor_done; - cursor_nospace: - mdev->cursor.pixels_1 =NULL ; - mdev->cursor.pixels_2 =NULL ; -dev_warn (&dev->pdev->dev,"Could not allocate space for cursors. Not doing hardware cursors.\n" ); - cursor_done: - -out: -if (r) -mgag200_driver_unload (dev); +if (!mdev->cursor.pixels_2 || !mdev->cursor.pixels_1) { + mdev->cursor.pixels_1 =NULL ; + mdev->cursor.pixels_2 =NULL ; +dev_warn (&dev->pdev->dev, +"Could not allocate space for cursors. Not doing hardware cursors.\n" ); + }else { + mdev->cursor.pixels_current = mdev->cursor.pixels_1; + mdev->cursor.pixels_prev = mdev->cursor.pixels_2; + } + +return 0 ; + +err_modeset: +drm_mode_config_cleanup (dev); +mgag200_mm_fini (mdev); +err_mm: + dev->dev_private =NULL ; +return r; }
Signature · 7 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel