modesetting: simplify bailing on calloc fail

Submitted by Konstantin Kharlamov on Dec. 17, 2017, 8:23 p.m.

Details

Message ID 20171217202302.18429-1-Hi-Angel@yandex.ru
State New
Headers show
Series "modesetting: simplify bailing on calloc fail" ( rev: 1 ) in X.org

Not browsing as part of any series.

Commit Message

Konstantin Kharlamov Dec. 17, 2017, 8:23 p.m.
The "done" label restores crtc-> {x,y,rotation,mode}, frees output_id.
Doing the calloc() before writing to those values frees us from
necessity to restore them if calloc fails, and allows to merge
"if (mode)" block.

Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
---

P.S. I don't have commit rights.

 hw/xfree86/drivers/modesetting/drmmode_display.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

Patch hide | download patch | download mbox

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index a51722b58..5b8e4fa1b 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -592,31 +592,27 @@  drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
     int output_count = 0;
     Bool ret = TRUE;
     int i;
     uint32_t fb_id = 0;
     drmModeModeInfo kmode;
 
+    output_ids = calloc(sizeof(uint32_t), xf86_config->num_output);
+    if (!output_ids)
+        return FALSE;
+
     saved_mode = crtc->mode;
     saved_x = crtc->x;
     saved_y = crtc->y;
     saved_rotation = crtc->rotation;
 
     if (mode) {
         crtc->mode = *mode;
         crtc->x = x;
         crtc->y = y;
         crtc->rotation = rotation;
-    }
 
-    output_ids = calloc(sizeof(uint32_t), xf86_config->num_output);
-    if (!output_ids) {
-        ret = FALSE;
-        goto done;
-    }
-
-    if (mode) {
         for (i = 0; i < xf86_config->num_output; i++) {
             xf86OutputPtr output = xf86_config->output[i];
             drmmode_output_private_ptr drmmode_output;
 
             if (output->crtc != crtc)
                 continue;

Comments

On Sun, Dec 17, 2017 at 11:23:02PM +0300, Konstantin Kharlamov wrote:
> The "done" label restores crtc-> {x,y,rotation,mode}, frees output_id.
> Doing the calloc() before writing to those values frees us from
> necessity to restore them if calloc fails, and allows to merge
> "if (mode)" block.
> 
> Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
> ---
> 
> P.S. I don't have commit rights.

But I do :)

   c2954b16c..c72049530  master -> master

Thanks

Cheers,
  Peter


>  hw/xfree86/drivers/modesetting/drmmode_display.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
> index a51722b58..5b8e4fa1b 100644
> --- a/hw/xfree86/drivers/modesetting/drmmode_display.c
> +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
> @@ -592,31 +592,27 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
>      int output_count = 0;
>      Bool ret = TRUE;
>      int i;
>      uint32_t fb_id = 0;
>      drmModeModeInfo kmode;
>  
> +    output_ids = calloc(sizeof(uint32_t), xf86_config->num_output);
> +    if (!output_ids)
> +        return FALSE;
> +
>      saved_mode = crtc->mode;
>      saved_x = crtc->x;
>      saved_y = crtc->y;
>      saved_rotation = crtc->rotation;
>  
>      if (mode) {
>          crtc->mode = *mode;
>          crtc->x = x;
>          crtc->y = y;
>          crtc->rotation = rotation;
> -    }
>  
> -    output_ids = calloc(sizeof(uint32_t), xf86_config->num_output);
> -    if (!output_ids) {
> -        ret = FALSE;
> -        goto done;
> -    }
> -
> -    if (mode) {
>          for (i = 0; i < xf86_config->num_output; i++) {
>              xf86OutputPtr output = xf86_config->output[i];
>              drmmode_output_private_ptr drmmode_output;
>  
>              if (output->crtc != crtc)
>                  continue;
> -- 
> 2.15.1
> 
> _______________________________________________
> xorg-devel@lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: https://lists.x.org/mailman/listinfo/xorg-devel
>