[PATCH xf86-video-mga] remove redundant NULL checks for free() v2

Ian Romanick idr at freedesktop.org
Sun May 29 11:23:50 PDT 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 05/29/2011 02:47 AM, Nicolas Kaiser wrote:
> Based on a suggestion from Cyril Brulebois.
> free() can handle NULL.
> 
> Signed-off-by: Nicolas Kaiser <nikai at nikai.net>

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

A assume at this point you're mostly waiting for someone with commit
rights to push your patches?

> ---
> This patch depends on patch "replace deprecated X*alloc functions v2".
> 
>  src/mga_dri.c    |   30 ++++++++----------------
>  src/mga_driver.c |   66 ++++++++++++++++++------------------------------------
>  src/mga_merge.c  |    6 +---
>  src/mga_video.c  |    3 +-
>  4 files changed, 35 insertions(+), 70 deletions(-)
> 
> diff --git a/src/mga_dri.c b/src/mga_dri.c
> index b3a1bb8..d78f279 100644
> --- a/src/mga_dri.c
> +++ b/src/mga_dri.c
> @@ -1012,12 +1012,10 @@ static void MGADRIMoveBuffersXAA(WindowPtr pParent, DDXPointRec ptOldOrg,
>  	    pboxNew2 = (BoxPtr)malloc(sizeof(BoxRec)*nbox);
>  	    pptNew2 = (DDXPointPtr)malloc(sizeof(DDXPointRec)*nbox);
>  	    if (!pboxNew2 || !pptNew2) {
> -	        if (pptNew2) free(pptNew2);
> -	        if (pboxNew2) free(pboxNew2);
> -	        if (pboxNew1) {
> -		    free(pptNew1);
> -		    free(pboxNew1);
> -		}
> +	       free(pptNew2);
> +	       free(pboxNew2);
> +	       free(pptNew1);
> +	       free(pboxNew1);
>  	       return;
>  	    }
>  	    pboxBase = pboxNext = pbox;
> @@ -1066,14 +1064,10 @@ static void MGADRIMoveBuffersXAA(WindowPtr pParent, DDXPointRec ptOldOrg,
>      }
>      MGASelectBuffer(pScrn, MGA_FRONT);
>  
> -    if (pboxNew2) {
> -        free(pptNew2);
> -        free(pboxNew2);
> -    }
> -    if (pboxNew1) {
> -        free(pptNew1);
> -        free(pboxNew1);
> -    }
> +    free(pptNew2);
> +    free(pboxNew2);
> +    free(pptNew1);
> +    free(pboxNew1);
>  
>      pMga->AccelInfoRec->NeedToSync = TRUE;
>  
> @@ -1506,10 +1500,6 @@ void MGADRICloseScreen( ScreenPtr pScreen )
>        free( pMga->DRIServerInfo );
>        pMga->DRIServerInfo = 0;
>     }
> -   if ( pMga->pVisualConfigs ) {
> -      free( pMga->pVisualConfigs );
> -   }
> -   if ( pMga->pVisualConfigsPriv ) {
> -      free( pMga->pVisualConfigsPriv );
> -   }
> +   free( pMga->pVisualConfigs );
> +   free( pMga->pVisualConfigsPriv );
>  }
> diff --git a/src/mga_driver.c b/src/mga_driver.c
> index 01bec70..e5fdec2 100644
> --- a/src/mga_driver.c
> +++ b/src/mga_driver.c
> @@ -2490,8 +2490,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags)
>  			      pMga->FbMapSize,
>  			      LOOKUP_BEST_REFRESH);
>        
> -	if (linePitches)
> -	   free(linePitches);
> +	free(linePitches);
>      }
>  
>      if (i < 1 && pMga->FBDev) {
> @@ -2804,27 +2803,19 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags)
>  	      /* Both boards have done there initialization */
>  	      MGACloseLibrary(pMga->pBoard);
>  
> -	      if (pMga->pBoard)
> -	        free(pMga->pBoard);
> -	      if (pMga->pClientStruct)
> -	        free(pMga->pClientStruct);
> -	      if (pMga->pMgaModeInfo)
> -	        free(pMga->pMgaModeInfo);
> -	      if (pMga->pMgaHwInfo)
> -	        free(pMga->pMgaHwInfo);
> +	      free(pMga->pBoard);
> +	      free(pMga->pClientStruct);
> +	      free(pMga->pMgaModeInfo);
> +	      free(pMga->pMgaHwInfo);
>  	      pMgaEnt->refCount = 0;
>  	  }
>        } else {
>  	  MGACloseLibrary(pMga->pBoard);
>  
> -	  if (pMga->pBoard)
> -	    free(pMga->pBoard);
> -	  if (pMga->pClientStruct)
> -	    free(pMga->pClientStruct);
> -	  if (pMga->pMgaModeInfo)
> -	    free(pMga->pMgaModeInfo);
> -	  if (pMga->pMgaHwInfo)
> -	    free(pMga->pMgaHwInfo);
> +	  free(pMga->pBoard);
> +	  free(pMga->pClientStruct);
> +	  free(pMga->pMgaModeInfo);
> +	  free(pMga->pMgaHwInfo);
>        }
>  
>      );	/* MGA_HAL */
> @@ -4240,26 +4231,18 @@ MGACloseScreen(int scrnIndex, ScreenPtr pScreen)
>  	 /* Both boards have closed there screen */
>  	 MGACloseLibrary(pMga->pBoard);
>  
> -	 if (pMga->pBoard)
> -	   free(pMga->pBoard);
> -	 if (pMga->pClientStruct)
> -	   free(pMga->pClientStruct);
> -	 if (pMga->pMgaModeInfo)
> -	   free(pMga->pMgaModeInfo);
> -	 if (pMga->pMgaHwInfo)
> -	   free(pMga->pMgaHwInfo);
> +	 free(pMga->pBoard);
> +	 free(pMga->pClientStruct);
> +	 free(pMga->pMgaModeInfo);
> +	 free(pMga->pMgaHwInfo);
>        }
>     } else {
>        MGACloseLibrary(pMga->pBoard);
>  
> -      if (pMga->pBoard)
> -	free(pMga->pBoard);
> -      if (pMga->pClientStruct)
> -	free(pMga->pClientStruct);
> -      if (pMga->pMgaModeInfo)
> -	free(pMga->pMgaModeInfo);
> -      if (pMga->pMgaHwInfo)
> -	free(pMga->pMgaHwInfo);
> +      free(pMga->pBoard);
> +      free(pMga->pClientStruct);
> +      free(pMga->pMgaModeInfo);
> +      free(pMga->pMgaHwInfo);
>     }
>     );	/* MGA_HAL */
>  #endif
> @@ -4276,16 +4259,11 @@ MGACloseScreen(int scrnIndex, ScreenPtr pScreen)
>  #endif
>      if (pMga->CursorInfoRec)
>      	xf86DestroyCursorInfoRec(pMga->CursorInfoRec);
> -    if (pMga->ShadowPtr)
> -	free(pMga->ShadowPtr);
> -    if (pMga->DGAModes)
> -	free(pMga->DGAModes);
> -    if (pMga->adaptor)
> -	free(pMga->adaptor);
> -    if (pMga->portPrivate)
> -	free(pMga->portPrivate);
> -    if (pMga->ScratchBuffer)
> -	free(pMga->ScratchBuffer);
> +    free(pMga->ShadowPtr);
> +    free(pMga->DGAModes);
> +    free(pMga->adaptor);
> +    free(pMga->portPrivate);
> +    free(pMga->ScratchBuffer);
>  
>      pScrn->vtSema = FALSE;
>  
> diff --git a/src/mga_merge.c b/src/mga_merge.c
> index 7121d05..4c7d900 100644
> --- a/src/mga_merge.c
> +++ b/src/mga_merge.c
> @@ -538,8 +538,7 @@ MGAPreInitMergedFB(ScrnInfoPtr pScrn1, int flags)
>  			      pMga->FbMapSize,
>  			      LOOKUP_BEST_REFRESH);
>          
> -	if (linePitches)
> -	   free(linePitches);
> +	free(linePitches);
>      }
>  
>  
> @@ -929,8 +928,7 @@ MGACloseScreenMerged(int scrnIndex, ScreenPtr pScreen) {
>          pScrn1->currentMode = pScrn1->modes;
>          do {
>              DisplayModePtr p = pScrn1->currentMode->next; 
> -            if(pScrn1->currentMode->Private) 
> -                free(pScrn1->currentMode->Private);
> +            free(pScrn1->currentMode->Private);
>              free(pScrn1->currentMode);
>              pScrn1->currentMode = p;
>          }while( pScrn1->currentMode != pScrn1->modes);
> diff --git a/src/mga_video.c b/src/mga_video.c
> index d251370..3c21b45 100644
> --- a/src/mga_video.c
> +++ b/src/mga_video.c
> @@ -146,8 +146,7 @@ void MGAInitVideo(ScreenPtr pScreen)
>      if(num_adaptors)
>          xf86XVScreenInit(pScreen, adaptors, num_adaptors);
>  
> -    if(newAdaptors)
> -	free(newAdaptors);
> +    free(newAdaptors);
>  }
>  
>  /* client libraries expect an encoding */

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk3ijzYACgkQX1gOwKyEAw/FRwCfdE8QreKJx7zklYEfgpWNorhC
lV4An2OXG89fW4+9YzL8GwNUHVclVCtl
=tU1e
-----END PGP SIGNATURE-----


More information about the xorg-devel mailing list