linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 10/11] drivers/spi: Move a dereference below a NULL test
@ 2008-12-16 15:15 Julia Lawall
       [not found] ` <Pine.LNX.4.64.0812161615090.20444-h8frIrHk2441Y/6SN6b7/w@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Julia Lawall @ 2008-12-16 15:15 UTC (permalink / raw)
  To: dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA

From: Julia Lawall <julia-dAYI7NvHqcQ@public.gmane.org>

In each case, if the NULL test is necessary, then the dereference should be
moved below the NULL test.

The semantic patch that makes this change is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@@
type T;
expression E;
identifier i,fld;
statement S;
@@

- T i = E->fld;
+ T i;
  ... when != E
      when != i
  if (E == NULL) S
+ i = E->fld;
// </smpl>

Signed-off-by: Julia Lawall <julia-dAYI7NvHqcQ@public.gmane.org>

---
 drivers/spi/pxa2xx_spi.c            |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/spi/pxa2xx_spi.c b/drivers/spi/pxa2xx_spi.c
index cf12f2d..fbad7e4 100644
--- a/drivers/spi/pxa2xx_spi.c
+++ b/drivers/spi/pxa2xx_spi.c
@@ -1561,11 +1561,12 @@ out_error_master_alloc:
 static int pxa2xx_spi_remove(struct platform_device *pdev)
 {
 	struct driver_data *drv_data = platform_get_drvdata(pdev);
-	struct ssp_device *ssp = drv_data->ssp;
+	struct ssp_device *ssp;
 	int status = 0;
 
 	if (!drv_data)
 		return 0;
+	ssp = drv_data->ssp;
 
 	/* Remove the queue */
 	status = destroy_queue(drv_data);

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 10/11] drivers/spi: Move a dereference below a NULL test
       [not found] ` <Pine.LNX.4.64.0812161615090.20444-h8frIrHk2441Y/6SN6b7/w@public.gmane.org>
@ 2008-12-17 20:22   ` David Brownell
  0 siblings, 0 replies; 2+ messages in thread
From: David Brownell @ 2008-12-17 20:22 UTC (permalink / raw)
  To: Julia Lawall
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	kernel-janitors-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On Tuesday 16 December 2008, Julia Lawall wrote:
> From: Julia Lawall <julia-dAYI7NvHqcQ@public.gmane.org>
> 
> In each case, if the NULL test is necessary, then the dereference should be
> moved below the NULL test.
> 
> The semantic patch that makes this change is as follows:
> (http://www.emn.fr/x-info/coccinelle/)
> 
> // <smpl>
> @@
> type T;
> expression E;
> identifier i,fld;
> statement S;
> @@
> 
> - T i = E->fld;
> + T i;
>   ... when != E
>       when != i
>   if (E == NULL) S
> + i = E->fld;
> // </smpl>
> 
> Signed-off-by: Julia Lawall <julia-dAYI7NvHqcQ@public.gmane.org>

Acked-by: David Brownell <dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>

... and I'm *still* glad to see tools shaking loose
goofage like this.  :)


> 
> ---
>  drivers/spi/pxa2xx_spi.c            |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/spi/pxa2xx_spi.c b/drivers/spi/pxa2xx_spi.c
> index cf12f2d..fbad7e4 100644
> --- a/drivers/spi/pxa2xx_spi.c
> +++ b/drivers/spi/pxa2xx_spi.c
> @@ -1561,11 +1561,12 @@ out_error_master_alloc:
>  static int pxa2xx_spi_remove(struct platform_device *pdev)
>  {
>  	struct driver_data *drv_data = platform_get_drvdata(pdev);
> -	struct ssp_device *ssp = drv_data->ssp;
> +	struct ssp_device *ssp;
>  	int status = 0;
>  
>  	if (!drv_data)
>  		return 0;
> +	ssp = drv_data->ssp;
>  
>  	/* Remove the queue */
>  	status = destroy_queue(drv_data);
> 
> 



------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-12-17 20:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-16 15:15 [PATCH 10/11] drivers/spi: Move a dereference below a NULL test Julia Lawall
     [not found] ` <Pine.LNX.4.64.0812161615090.20444-h8frIrHk2441Y/6SN6b7/w@public.gmane.org>
2008-12-17 20:22   ` David Brownell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).