Re: [PATCH 1/3] spi: Add helper functions for setting up transfers

2013-01-10 Thread Julia Lawall
 +@r1@
 +identifier fn;
 +identifier xfers;
 +@@
 +fn(...)
 +{
 + ...
 +(
 + struct spi_transfer xfers[...];
 +|
 + struct spi_transfer xfers[];
 +)
 + ...
 +}

Can it happen that there would be more than one spi_transfer or spi_message
variable per function?  This semantic patch will only treat the case where
there is only one, because the ... before an after the variable declaration
won't match another declaration of the same form.

julia

--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
___
spi-devel-general mailing list
spi-devel-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spi-devel-general


Re: [PATCH 1/3] spi: Add helper functions for setting up transfers

2013-01-10 Thread Julia Lawall
On Thu, 10 Jan 2013, Lars-Peter Clausen wrote:

 On 01/10/2013 09:53 AM, Julia Lawall wrote:
  +@r1@
  +identifier fn;
  +identifier xfers;
  +@@
  +fn(...)
  +{
  +  ...
  +(
  +  struct spi_transfer xfers[...];
  +|
  +  struct spi_transfer xfers[];
  +)
  +  ...
  +}
  
  Can it happen that there would be more than one spi_transfer or spi_message
  variable per function?  This semantic patch will only treat the case where
  there is only one, because the ... before an after the variable declaration
  won't match another declaration of the same form.
  
  julia
 
 I guess it could happen, but I would consider it to be very rare. There are
 a few examples of multiple transfers in the kernel. But most of them look like
 
 struct spi_message msg;
 struct spi_transfer xfer_foo;
 struct spi_transfer xfer_bar;
 
 ...
 spi_message_add_tail(xfer_foo, msg);
 spi_message_add_tail(xfer_bar, msg);
 
 So the transformation can't be applied here anyway.
 
 Do you have an idea how to change the rule to work with multiple
 transfers/messages per function? If it would make the cocci file more
 complex I wouldn't bother to take care of it, since it basically has no
 practical use.

Probably the simplest thing is to put when any on all of the ...s
It might get slower, though.

Alternatively you could have a rule at the end that prints a warning for 
any cases that are not transformed.

julia

--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
___
spi-devel-general mailing list
spi-devel-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spi-devel-general


[PATCH 1/4] drivers/spi/spi-sh-hspi.c: drop frees of devm_ alloc'd data

2012-09-01 Thread Julia Lawall
From: Julia Lawall julia.law...@lip6.fr

devm free functions should not have to be explicitly used.

A semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// smpl
@@
@@

(
* devm_kfree(...);
|
* devm_free_irq(...);
|
* devm_iounmap(...);
|
* devm_release_region(...);
|
* devm_release_mem_region(...);
)
// /smpl

Signed-off-by: Julia Lawall julia.law...@lip6.fr

---
 drivers/spi/spi-sh-hspi.c |5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/spi/spi-sh-hspi.c b/drivers/spi/spi-sh-hspi.c
index 934138c..796c077 100644
--- a/drivers/spi/spi-sh-hspi.c
+++ b/drivers/spi/spi-sh-hspi.c
@@ -283,7 +283,7 @@ static int __devinit hspi_probe(struct platform_device 
*pdev)
ret = spi_register_master(master);
if (ret  0) {
dev_err(pdev-dev, spi_register_master error.\n);
-   goto error2;
+   goto error1;
}
 
pm_runtime_enable(pdev-dev);
@@ -292,8 +292,6 @@ static int __devinit hspi_probe(struct platform_device 
*pdev)
 
return 0;
 
- error2:
-   devm_iounmap(hspi-dev, hspi-addr);
  error1:
clk_put(clk);
  error0:
@@ -310,7 +308,6 @@ static int __devexit hspi_remove(struct platform_device 
*pdev)
 
clk_put(hspi-clk);
spi_unregister_master(hspi-master);
-   devm_iounmap(hspi-dev, hspi-addr);
 
return 0;
 }


--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
spi-devel-general mailing list
spi-devel-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spi-devel-general


[PATCH 2/13] drivers/spi/spi-{orion, pl022}.c: use clk_prepare_enable and clk_disable_unprepare

2012-08-26 Thread Julia Lawall
From: Julia Lawall julia.law...@lip6.fr

Clk_prepare_enable and clk_disable_unprepare combine clk_prepare and
clk_enable, and clk_disable and clk_unprepare.  They make the code more
concise, and ensure that clk_unprepare is called when clk_enable fails.

A simplified version of the semantic patch that introduces calls to these
functions is as follows: (http://coccinelle.lip6.fr/)

// smpl
@@
expression e;
@@

- clk_prepare(e);
- clk_enable(e);
+ clk_prepare_enable(e);

@@
expression e;
@@

- clk_disable(e);
- clk_unprepare(e);
+ clk_disable_unprepare(e);
// /smpl

Signed-off-by: Julia Lawall julia.law...@lip6.fr

---
 drivers/spi/spi-orion.c |3 +--
 drivers/spi/spi-pl022.c |   17 -
 2 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c
index b17c09c..b2a7199 100644
--- a/drivers/spi/spi-orion.c
+++ b/drivers/spi/spi-orion.c
@@ -416,8 +416,7 @@ static int __init orion_spi_probe(struct platform_device 
*pdev)
goto out;
}
 
-   clk_prepare(spi-clk);
-   clk_enable(spi-clk);
+   clk_prepare_enable(spi-clk);
tclk_hz = clk_get_rate(spi-clk);
spi-max_speed = DIV_ROUND_UP(tclk_hz, 4);
spi-min_speed = DIV_ROUND_UP(tclk_hz, 30);
diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
index b0fec03..0d235d4 100644
--- a/drivers/spi/spi-pl022.c
+++ b/drivers/spi/spi-pl022.c
@@ -2142,16 +2142,10 @@ pl022_probe(struct amba_device *adev, const struct 
amba_id *id)
goto err_no_clk;
}
 
-   status = clk_prepare(pl022-clk);
-   if (status) {
-   dev_err(adev-dev, could not prepare SSP/SPI bus clock\n);
-   goto  err_clk_prep;
-   }
-
-   status = clk_enable(pl022-clk);
+   status = clk_prepare_enable(pl022-clk);
if (status) {
dev_err(adev-dev, could not enable SSP/SPI bus clock\n);
-   goto err_no_clk_en;
+   goto err_clk_prep;
}
 
/* Initialize transfer pump */
@@ -2207,9 +2201,7 @@ pl022_probe(struct amba_device *adev, const struct 
amba_id *id)
 
free_irq(adev-irq[0], pl022);
  err_no_irq:
-   clk_disable(pl022-clk);
- err_no_clk_en:
-   clk_unprepare(pl022-clk);
+   clk_disable_unprepare(pl022-clk);
  err_clk_prep:
clk_put(pl022-clk);
  err_no_clk:
@@ -2243,8 +2235,7 @@ pl022_remove(struct amba_device *adev)
pl022_dma_remove(pl022);
 
free_irq(adev-irq[0], pl022);
-   clk_disable(pl022-clk);
-   clk_unprepare(pl022-clk);
+   clk_disable_unprepare(pl022-clk);
clk_put(pl022-clk);
pm_runtime_disable(adev-dev);
iounmap(pl022-virtbase);


--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
spi-devel-general mailing list
spi-devel-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spi-devel-general


[PATCH 12/14] drivers/spi/spi-coldfire-qspi.c: fix error return code

2012-08-19 Thread Julia Lawall
From: Julia Lawall julia.law...@lip6.fr

Initialize return variable before exiting on an error path.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// smpl
(
if@p1 (\(ret  0\|ret != 0\))
 { ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1
when != ret
*if(...)
{
  ... when != ret = e2
  when forall
 return ret;
}

// /smpl

Signed-off-by: Julia Lawall julia.law...@lip6.fr

---
 drivers/spi/spi-coldfire-qspi.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/spi/spi-coldfire-qspi.c b/drivers/spi/spi-coldfire-qspi.c
index b2d4b9e..7889796 100644
--- a/drivers/spi/spi-coldfire-qspi.c
+++ b/drivers/spi/spi-coldfire-qspi.c
@@ -462,6 +462,7 @@ static int __devinit mcfqspi_probe(struct platform_device 
*pdev)
pdata = pdev-dev.platform_data;
if (!pdata) {
dev_dbg(pdev-dev, platform data is missing\n);
+   status = -EINVAL;
goto fail4;
}
master-bus_num = pdata-bus_num;


--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
spi-devel-general mailing list
spi-devel-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spi-devel-general


[PATCH 10/14] drivers/spi/spi-ep93xx.c: fix error return code

2012-08-19 Thread Julia Lawall
From: Julia Lawall julia.law...@lip6.fr

Initialize return variable before exiting on an error path.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// smpl
(
if@p1 (\(ret  0\|ret != 0\))
 { ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1
when != ret
*if(...)
{
  ... when != ret = e2
  when forall
 return ret;
}

// /smpl

Signed-off-by: Julia Lawall julia.law...@lip6.fr

---
 drivers/spi/spi-ep93xx.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/spi/spi-ep93xx.c b/drivers/spi/spi-ep93xx.c
index f97f1d2..9e7fdfd 100644
--- a/drivers/spi/spi-ep93xx.c
+++ b/drivers/spi/spi-ep93xx.c
@@ -1105,6 +1105,7 @@ static int __devinit ep93xx_spi_probe(struct 
platform_device *pdev)
espi-wq = create_singlethread_workqueue(ep93xx_spid);
if (!espi-wq) {
dev_err(pdev-dev, unable to create workqueue\n);
+   error = -ENOMEM;
goto fail_free_dma;
}
INIT_WORK(espi-msg_work, ep93xx_spi_work);


--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
spi-devel-general mailing list
spi-devel-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spi-devel-general


[PATCH 11/14] drivers/spi/spi-orion.c: fix error return code

2012-08-19 Thread Julia Lawall
From: Julia Lawall julia.law...@lip6.fr

Initialize return variable before exiting on an error path.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// smpl
(
if@p1 (\(ret  0\|ret != 0\))
 { ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1
when != ret
*if(...)
{
  ... when != ret = e2
  when forall
 return ret;
}

// /smpl

Signed-off-by: Julia Lawall julia.law...@lip6.fr

---
Actually, orion_spi_reset currently always returns 0, so the test is
never true.  Perhaps this should be taken into account in some other way.

 drivers/spi/spi-orion.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c
index b17c09c..cc12803 100644
--- a/drivers/spi/spi-orion.c
+++ b/drivers/spi/spi-orion.c
@@ -435,7 +435,8 @@ static int __init orion_spi_probe(struct platform_device 
*pdev)
}
spi-base = ioremap(r-start, SZ_1K);
 
-   if (orion_spi_reset(spi)  0)
+   status = orion_spi_reset(spi);
+   if (status  0)
goto out_rel_mem;
 
master-dev.of_node = pdev-dev.of_node;


--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
spi-devel-general mailing list
spi-devel-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spi-devel-general


[PATCH 9/14] drivers/spi/spi-omap-100k.c: fix error return code

2012-08-19 Thread Julia Lawall
From: Julia Lawall julia.law...@lip6.fr

Initialize return variable before exiting on an error path.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// smpl
(
if@p1 (\(ret  0\|ret != 0\))
 { ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1
when != ret
*if(...)
{
  ... when != ret = e2
  when forall
 return ret;
}

// /smpl

Signed-off-by: Julia Lawall julia.law...@lip6.fr

---
Actually, omap1_spi100k_reset currently always returns 0, so the test is
never true.  Perhaps this should be taken into account in some other way.

 drivers/spi/spi-omap-100k.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-omap-100k.c b/drivers/spi/spi-omap-100k.c
index 9bd1c92..b581107 100644
--- a/drivers/spi/spi-omap-100k.c
+++ b/drivers/spi/spi-omap-100k.c
@@ -542,7 +542,8 @@ static int __devinit omap1_spi100k_probe(struct 
platform_device *pdev)
goto err2;
}
 
-   if (omap1_spi100k_reset(spi100k)  0)
+   status = omap1_spi100k_reset(spi100k);
+   if (status  0)
goto err3;
 
status = spi_register_master(master);


--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
spi-devel-general mailing list
spi-devel-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spi-devel-general


[PATCH 14/14] drivers/spi/spi-s3c24xx.c: fix error return code

2012-08-19 Thread Julia Lawall
From: Julia Lawall julia.law...@lip6.fr

Initialize return variable before exiting on an error path.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// smpl
(
if@p1 (\(ret  0\|ret != 0\))
 { ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1
when != ret
*if(...)
{
  ... when != ret = e2
  when forall
 return ret;
}

// /smpl

Signed-off-by: Julia Lawall julia.law...@lip6.fr

---
Perhaps -EINVAL is not the right value in this case.

 drivers/spi/spi-s3c24xx.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/spi/spi-s3c24xx.c b/drivers/spi/spi-s3c24xx.c
index 8ee7d79..a2a080b 100644
--- a/drivers/spi/spi-s3c24xx.c
+++ b/drivers/spi/spi-s3c24xx.c
@@ -611,6 +611,7 @@ static int __devinit s3c24xx_spi_probe(struct 
platform_device *pdev)
if (!pdata-set_cs) {
if (pdata-pin_cs  0) {
dev_err(pdev-dev, No chipselect pin\n);
+   err = -EINVAL;
goto err_register;
}
 


--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
spi-devel-general mailing list
spi-devel-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spi-devel-general


[spi-devel-general] [PATCH 26/42] drivers/spi: Adjust confusing if indentation

2010-08-05 Thread Julia Lawall
From: Julia Lawall ju...@diku.dk

The return -EINVAL appears to only make sense if the if branch that it is
aligned with is taken, so move it into that branch

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// smpl
@r disable braces4@
position p1,p2;
statement S1,S2;
@@

(
if (...) { ... }
|
if (...) s...@p1 s...@p2
)

@script:python@
p1  r.p1;
p2  r.p2;
@@

if (p1[0].column == p2[0].column):
  cocci.print_main(branch,p1)
  cocci.print_secs(after,p2)
// /smpl

Signed-off-by: Julia Lawall ju...@diku.dk

---
This patch changes the semantics, and the change might not be correct.

 drivers/spi/amba-pl022.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/amba-pl022.c b/drivers/spi/amba-pl022.c
index f0a1418..4de50de 100644
--- a/drivers/spi/amba-pl022.c
+++ b/drivers/spi/amba-pl022.c
@@ -1348,10 +1348,11 @@ static int verify_controller_parameters(struct pl022 
*pl022,
if ((chip_info-duplex !=
 SSP_MICROWIRE_CHANNEL_FULL_DUPLEX)
 (chip_info-duplex !=
-   SSP_MICROWIRE_CHANNEL_HALF_DUPLEX))
+   SSP_MICROWIRE_CHANNEL_HALF_DUPLEX)) {
dev_err(chip_info-dev,
Microwire duplex mode is configured 
incorrectly\n);
return -EINVAL;
+   }
} else {
if (chip_info-duplex != 
SSP_MICROWIRE_CHANNEL_FULL_DUPLEX)
dev_err(chip_info-dev,

--
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
___
spi-devel-general mailing list
spi-devel-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spi-devel-general


[spi-devel-general] [PATCH 26/42] drivers/spi/amba-pl022.c: Adjust confusing if indentation

2010-08-05 Thread Julia Lawall
From: Julia Lawall ju...@diku.dk

The return -EINVAL appears to only make sense if the if branch that it is
aligned with is taken, so move it into that branch

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// smpl
@r disable braces4@
position p1,p2;
statement S1,S2;
@@

(
if (...) { ... }
|
if (...) s...@p1 s...@p2
)

@script:python@
p1  r.p1;
p2  r.p2;
@@

if (p1[0].column == p2[0].column):
  cocci.print_main(branch,p1)
  cocci.print_secs(after,p2)
// /smpl

Signed-off-by: Julia Lawall ju...@diku.dk

---
This patch changes the semantics, and the change might not be correct.

 drivers/spi/amba-pl022.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/amba-pl022.c b/drivers/spi/amba-pl022.c
index f0a1418..4de50de 100644
--- a/drivers/spi/amba-pl022.c
+++ b/drivers/spi/amba-pl022.c
@@ -1348,10 +1348,11 @@ static int verify_controller_parameters(struct pl022 
*pl022,
if ((chip_info-duplex !=
 SSP_MICROWIRE_CHANNEL_FULL_DUPLEX)
 (chip_info-duplex !=
-   SSP_MICROWIRE_CHANNEL_HALF_DUPLEX))
+   SSP_MICROWIRE_CHANNEL_HALF_DUPLEX)) {
dev_err(chip_info-dev,
Microwire duplex mode is configured 
incorrectly\n);
return -EINVAL;
+   }
} else {
if (chip_info-duplex != 
SSP_MICROWIRE_CHANNEL_FULL_DUPLEX)
dev_err(chip_info-dev,

--
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
___
spi-devel-general mailing list
spi-devel-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spi-devel-general


[spi-devel-general] [PATCH 10/11] drivers/spi: Move a dereference below a NULL test

2008-12-16 Thread Julia Lawall
From: Julia Lawall ju...@diku.dk

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 ju...@diku.dk

---
 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/
___
spi-devel-general mailing list
spi-devel-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spi-devel-general