On 09/05/2012 12:42 AM, Matt Turner wrote:
Same as earlier commit, except for "FREE"

This patch has been generated by the following Coccinelle semantic
patch:

// Remove useless checks for NULL before freeing
//
// free (NULL) is a no-op, so there is no need to avoid it

@@
expression E;
@@
+ FREE (E);
+ E = NULL;
- if (unlikely (E != NULL)) {
-   FREE(E);
(
-   E = NULL;
|
-   E = 0;
)
    ...
- }

@@
expression E;
type T;
@@
+ FREE ((T) E);
+ E = NULL;
- if (unlikely (E != NULL)) {
-   FREE((T) E);
(
-   E = NULL;
|
-   E = 0;
)
    ...
- }

@@
expression E;
@@
+ FREE (E);
- if (unlikely (E != NULL)) {
-   FREE (E);
- }

@@
expression E;
type T;
@@
+ FREE ((T) E);
- if (unlikely (E != NULL)) {
-   FREE ((T) E);
- }
---
  src/gallium/auxiliary/draw/draw_gs.c               |    4 +--
  src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c    |    3 +-
  src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c  |    6 +---
  src/gallium/auxiliary/tgsi/tgsi_exec.c             |   22 +++++--------------
  src/gallium/auxiliary/util/u_draw_quad.c           |    3 +-
  src/gallium/auxiliary/util/u_format.c              |    8 +-----
  src/gallium/drivers/i915/i915_resource_texture.c   |    3 +-
  src/gallium/drivers/i915/i915_state.c              |    7 ++---
  src/gallium/drivers/llvmpipe/lp_texture.c          |    4 +--
  src/gallium/drivers/nv30/nvfx_fragprog.c           |   10 +++-----
  src/gallium/drivers/nv50/nv50_program.c            |   12 +++-------
  src/gallium/drivers/nv50/nv50_screen.c             |    6 +---
  src/gallium/drivers/nvc0/nvc0_program.c            |   12 +++-------
  src/gallium/drivers/nvc0/nvc0_screen.c             |    6 +---
  src/gallium/drivers/r300/r300_screen_buffer.c      |    3 +-
  src/gallium/drivers/r300/r300_state.c              |    3 +-
  src/gallium/state_trackers/egl/common/egl_g3d.c    |    9 ++-----
  src/gallium/state_trackers/egl/drm/modeset.c       |    6 +---
  src/gallium/state_trackers/egl/drm/native_drm.c    |    6 +---
  src/gallium/state_trackers/egl/gdi/native_gdi.c    |    3 +-
  .../state_trackers/egl/wayland/native_drm.c        |    6 +---
  .../state_trackers/egl/wayland/native_shm.c        |    3 +-
  src/gallium/state_trackers/egl/x11/native_dri2.c   |    9 ++-----
  src/gallium/state_trackers/egl/x11/native_ximage.c |    3 +-
  src/gallium/state_trackers/vega/text.c             |    3 +-
  src/gallium/state_trackers/wgl/stw_device.c        |    3 +-
  src/gallium/targets/graw-xlib/graw_xlib.c          |    3 +-
  src/gallium/winsys/sw/dri/dri_sw_winsys.c          |    4 +--
  28 files changed, 55 insertions(+), 115 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_gs.c 
b/src/gallium/auxiliary/draw/draw_gs.c
index b2b4087..c564726 100644
--- a/src/gallium/auxiliary/draw/draw_gs.c
+++ b/src/gallium/auxiliary/draw/draw_gs.c
@@ -435,9 +435,7 @@ int draw_geometry_shader_run(struct draw_geometry_shader 
*shader,
     shader->in_prim_idx = 0;
     shader->input_vertex_stride = input_stride;
     shader->input = input;
-   if (shader->primitive_lengths) {
-      FREE(shader->primitive_lengths);
-   }
+   FREE(shader->primitive_lengths);
     shader->primitive_lengths = MALLOC(max_out_prims * sizeof(unsigned));

     tgsi_exec_set_constant_buffers(machine, PIPE_MAX_CONSTANT_BUFFERS,
diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c 
b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
index fe96e5c..453cf45 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
+++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_mm.c
@@ -287,8 +287,7 @@ if(mm->heap)
     u_mmDestroy(mm->heap);
     if(mm->map)
        pb_unmap(mm->buffer);
-   if(mm)
-      FREE(mm);
+   FREE(mm);
     return NULL;
  }

diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c 
b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c
index a8e9a34..67a19fe 100644
--- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c
+++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_pool.c
@@ -311,13 +311,11 @@ pool_bufmgr_create(struct pb_manager *provider,
     return SUPER(pool);

  failure:
-   if(pool->bufs)
-      FREE(pool->bufs);
+   FREE(pool->bufs);
     if(pool->map)
        pb_unmap(pool->buffer);
     if(pool->buffer)
        pb_reference(&pool->buffer, NULL);
-   if(pool)
-      FREE(pool);
+   FREE(pool);
     return NULL;
  }
diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c 
b/src/gallium/auxiliary/tgsi/tgsi_exec.c
index 5e23f5d..68bb598 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
@@ -653,15 +653,11 @@ tgsi_exec_machine_bind_shader(

     if (!tokens) {
        /* unbind and free all */
-      if (mach->Declarations) {
-         FREE( mach->Declarations );
-      }
+      FREE(mach->Declarations);
        mach->Declarations = NULL;
        mach->NumDeclarations = 0;

-      if (mach->Instructions) {
-         FREE( mach->Instructions );
-      }
+      FREE(mach->Instructions);
        mach->Instructions = NULL;
        mach->NumInstructions = 0;

@@ -804,15 +800,11 @@ tgsi_exec_machine_bind_shader(
     }
     tgsi_parse_free (&parse);

-   if (mach->Declarations) {
-      FREE( mach->Declarations );
-   }
+   FREE(mach->Declarations);
     mach->Declarations = declarations;
     mach->NumDeclarations = numDeclarations;

-   if (mach->Instructions) {
-      FREE( mach->Instructions );
-   }
+   FREE(mach->Instructions);
     mach->Instructions = instructions;
     mach->NumInstructions = numInstructions;
  }
@@ -875,10 +867,8 @@ void
  tgsi_exec_machine_destroy(struct tgsi_exec_machine *mach)
  {
     if (mach) {
-      if (mach->Instructions)
-         FREE(mach->Instructions);
-      if (mach->Declarations)
-         FREE(mach->Declarations);
+      FREE(mach->Instructions);
+      FREE(mach->Declarations);

        align_free(mach->Inputs);
        align_free(mach->Outputs);
diff --git a/src/gallium/auxiliary/util/u_draw_quad.c 
b/src/gallium/auxiliary/util/u_draw_quad.c
index 469c874..81c4f10 100644
--- a/src/gallium/auxiliary/util/u_draw_quad.c
+++ b/src/gallium/auxiliary/util/u_draw_quad.c
@@ -151,6 +151,5 @@ out:
     if (vbuf)
        pipe_resource_reference(&vbuf, NULL);

-   if (v)
-      FREE(v);
+   FREE(v);
  }
diff --git a/src/gallium/auxiliary/util/u_format.c 
b/src/gallium/auxiliary/util/u_format.c
index 6f45298..a41c468 100644
--- a/src/gallium/auxiliary/util/u_format.c
+++ b/src/gallium/auxiliary/util/u_format.c
@@ -618,13 +618,9 @@ util_format_translate(enum pipe_format dst_format,
           src_row += src_step;
        }

-      if (tmp_s) {
-         FREE(tmp_s);
-      }
+      FREE(tmp_s);

-      if (tmp_z) {
-         FREE(tmp_z);
-      }
+      FREE(tmp_z);

        return;
     }
diff --git a/src/gallium/drivers/i915/i915_resource_texture.c 
b/src/gallium/drivers/i915/i915_resource_texture.c
index e60b5b4..603a379 100644
--- a/src/gallium/drivers/i915/i915_resource_texture.c
+++ b/src/gallium/drivers/i915/i915_resource_texture.c
@@ -705,8 +705,7 @@ i915_texture_destroy(struct pipe_screen *screen,
        iws->buffer_destroy(iws, tex->buffer);

     for (i = 0; i<  Elements(tex->image_offset); i++)
-      if (tex->image_offset[i])
-         FREE(tex->image_offset[i]);
+      FREE(tex->image_offset[i]);

     FREE(tex);
  }
diff --git a/src/gallium/drivers/i915/i915_state.c 
b/src/gallium/drivers/i915/i915_state.c
index fdbff8b..410615f 100644
--- a/src/gallium/drivers/i915/i915_state.c
+++ b/src/gallium/drivers/i915/i915_state.c
@@ -614,10 +614,8 @@ void i915_delete_fs_state(struct pipe_context *pipe, void 
*shader)
  {
     struct i915_fragment_shader *ifs = (struct i915_fragment_shader *) shader;

-   if (ifs->decl) {
-      FREE(ifs->decl);
-      ifs->decl = NULL;
-   }
+   FREE(ifs->decl);
+   ifs->decl = NULL;

     if (ifs->program) {
        FREE(ifs->program);
@@ -625,6 +623,7 @@ void i915_delete_fs_state(struct pipe_context *pipe, void 
*shader)
        FREE((struct tgsi_token *)ifs->state.tokens);
        ifs->state.tokens = NULL;
     }
+
     ifs->program_len = 0;
     ifs->decl_len = 0;

Needless whitespace change?  Not a big deal though.

Reviewed-by: Brian Paul <bri...@vmware.com>


_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to