2008-12-16 15:16:09

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 10/11] drivers/spi: Move a dereference below a NULL test

From: Julia Lawall <[email protected]>

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 <[email protected]>

---
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);


2008-12-17 20:22:36

by David Brownell

[permalink] [raw]
Subject: Re: [PATCH 10/11] drivers/spi: Move a dereference below a NULL test

On Tuesday 16 December 2008, Julia Lawall wrote:
> From: Julia Lawall <[email protected]>
>
> 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 <[email protected]>

Acked-by: David Brownell <[email protected]>

... 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);
>
>