2012-08-26 16:01:15

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 0/13] use clk_prepare_enable and clk_disable_unprepare

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.

The transformation is made using the following semantic patch
(http://coccinelle.lip6.fr/). This semantic patch is not really safe, in
that it doesn't check for clk_disable's that are relying on the removed
clk_unprepare's. These cases have been adjusted by hand.

// <smpl>
@@
expression e;
@@

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

@@
expression e;
identifier r;
statement S;
@@

- r = clk_prepare(e); if (r) S
- clk_enable(e);
+ r = clk_prepare_enable(e); if (r) S

@@
expression e;
expression r;
@@

- clk_prepare(e);
r =
- clk_enable
+ clk_prepare_enable
(e);
if (r) { ...
- clk_unprepare(e); // unsafe!
...
return ...;
}

@@
expression e;
expression r;
@@

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

@@
expression e;
statement S;
@@

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

@@
expression e;
@@

- clk_prepare(e);
if (
- clk_enable(e)
+ clk_prepare_enable(e)
) { ...
- clk_unprepare(e); // unsafe!
...
return ...;
}

@@
expression e;
statement S;
@@

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

@@
expression e,r2;
identifier r1;
statement S;
@@

- r1 = clk_prepare(e); if (r1) S
r2 =
- clk_enable
+ clk_prepare_enable
(e);
if (r2) { ...
- clk_unprepare(e); // unsafe!
...
return ...;
}

@@
expression e,r2;
identifier r1;
statement S;
@@

- r1 = clk_prepare(e); if (r1) S
r2 =
- clk_enable
+ clk_prepare_enable
(e);

@@
expression e;
statement S1;
@@

- if (clk_prepare(e)) S1
if (
- clk_enable
+ clk_prepare_enable
(e)) { ...
- clk_unprepare(e); // unsafe!
...
return ...;
}

@@
expression e;
statement S1,S2;
@@

- if (clk_prepare(e)) S1
if (
- clk_enable
+ clk_prepare_enable
(e)) S2

@@
expression e;
@@

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


2012-08-26 16:01:21

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 4/13] i2c: sirf: use clk_prepare_enable and clk_disable_unprepare

From: Julia Lawall <[email protected]>

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

---
drivers/i2c/busses/i2c-sirf.c | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/busses/i2c-sirf.c b/drivers/i2c/busses/i2c-sirf.c
index 5574a47..110660a 100644
--- a/drivers/i2c/busses/i2c-sirf.c
+++ b/drivers/i2c/busses/i2c-sirf.c
@@ -278,18 +278,12 @@ static int __devinit i2c_sirfsoc_probe(struct platform_device *pdev)
goto err_get_clk;
}

- err = clk_prepare(clk);
+ err = clk_prepare_enable(clk);
if (err) {
- dev_err(&pdev->dev, "Clock prepare failed\n");
+ dev_err(&pdev->dev, "Clock prepare or enable failed\n");
goto err_clk_prep;
}

- err = clk_enable(clk);
- if (err) {
- dev_err(&pdev->dev, "Clock enable failed\n");
- goto err_clk_en;
- }
-
ctrl_speed = clk_get_rate(clk);

siic = devm_kzalloc(&pdev->dev, sizeof(*siic), GFP_KERNEL);
@@ -376,9 +370,7 @@ static int __devinit i2c_sirfsoc_probe(struct platform_device *pdev)
return 0;

out:
- clk_disable(clk);
-err_clk_en:
- clk_unprepare(clk);
+ clk_disable_unprepare(clk);
err_clk_prep:
clk_put(clk);
err_get_clk:

2012-08-26 16:01:32

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 12/13] drivers/amba/bus.c: use clk_prepare_enable and clk_disable_unprepare

From: Julia Lawall <[email protected]>

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

---
drivers/amba/bus.c | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index e8eb91b..6374ee6 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -329,17 +329,9 @@ static int amba_get_enable_pclk(struct amba_device *pcdev)
if (IS_ERR(pclk))
return PTR_ERR(pclk);

- ret = clk_prepare(pclk);
- if (ret) {
- clk_put(pclk);
- return ret;
- }
-
- ret = clk_enable(pclk);
- if (ret) {
- clk_unprepare(pclk);
+ ret = clk_prepare_enable(pclk);
+ if (ret)
clk_put(pclk);
- }

return ret;
}
@@ -348,8 +340,7 @@ static void amba_put_disable_pclk(struct amba_device *pcdev)
{
struct clk *pclk = pcdev->pclk;

- clk_disable(pclk);
- clk_unprepare(pclk);
+ clk_disable_unprepare(pclk);
clk_put(pclk);
}

2012-08-26 16:01:30

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 13/13] drivers/rtc/rtc-coh901331.c: use clk_prepare_enable and clk_disable_unprepare

From: Julia Lawall <[email protected]>

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

---
I'm not sure about this. Maybe it would be better to leave the disable and
unprepare separated, since there is no matching nearby clk_prepare.

drivers/rtc/rtc-coh901331.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-coh901331.c b/drivers/rtc/rtc-coh901331.c
index 76b2156..c8115b8 100644
--- a/drivers/rtc/rtc-coh901331.c
+++ b/drivers/rtc/rtc-coh901331.c
@@ -276,8 +276,7 @@ static void coh901331_shutdown(struct platform_device *pdev)

clk_enable(rtap->clk);
writel(0, rtap->virtbase + COH901331_IRQ_MASK);
- clk_disable(rtap->clk);
- clk_unprepare(rtap->clk);
+ clk_disable_unprepare(rtap->clk);
}

static struct platform_driver coh901331_driver = {

2012-08-26 16:01:29

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 9/13] drivers/tty/serial/amba-pl0{10,11}.c: use clk_prepare_enable and clk_disable_unprepare

From: Julia Lawall <[email protected]>

Clk_prepare_enable and clk_disable_unprepare combine clk_prepare and
clk_enable, and clk_disable and clk_unprepare. The9 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 <[email protected]>

---
drivers/tty/serial/amba-pl010.c | 15 ++++-----------
drivers/tty/serial/amba-pl011.c | 15 ++++-----------
2 files changed, 8 insertions(+), 22 deletions(-)

diff --git a/drivers/tty/serial/amba-pl010.c b/drivers/tty/serial/amba-pl010.c
index 0d91a54..22317dd 100644
--- a/drivers/tty/serial/amba-pl010.c
+++ b/drivers/tty/serial/amba-pl010.c
@@ -312,16 +312,12 @@ static int pl010_startup(struct uart_port *port)
struct uart_amba_port *uap = (struct uart_amba_port *)port;
int retval;

- retval = clk_prepare(uap->clk);
- if (retval)
- goto out;
-
/*
* Try to enable the clock producer.
*/
- retval = clk_enable(uap->clk);
+ retval = clk_prepare_enable(uap->clk);
if (retval)
- goto clk_unprep;
+ goto out;

uap->port.uartclk = clk_get_rate(uap->clk);

@@ -346,9 +342,7 @@ static int pl010_startup(struct uart_port *port)
return 0;

clk_dis:
- clk_disable(uap->clk);
- clk_unprep:
- clk_unprepare(uap->clk);
+ clk_disable_unprepare(uap->clk);
out:
return retval;
}
@@ -375,8 +369,7 @@ static void pl010_shutdown(struct uart_port *port)
/*
* Shut down the clock producer
*/
- clk_disable(uap->clk);
- clk_unprepare(uap->clk);
+ clk_disable_unprepare(uap->clk);
}

static void
diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index 92b1ac8..3322023 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -1324,16 +1324,12 @@ static int pl011_startup(struct uart_port *port)
"could not set default pins\n");
}

- retval = clk_prepare(uap->clk);
- if (retval)
- goto out;
-
/*
* Try to enable the clock producer.
*/
- retval = clk_enable(uap->clk);
+ retval = clk_prepare_enable(uap->clk);
if (retval)
- goto clk_unprep;
+ goto out;

uap->port.uartclk = clk_get_rate(uap->clk);

@@ -1411,9 +1407,7 @@ static int pl011_startup(struct uart_port *port)
return 0;

clk_dis:
- clk_disable(uap->clk);
- clk_unprep:
- clk_unprepare(uap->clk);
+ clk_disable_unprepare(uap->clk);
out:
return retval;
}
@@ -1473,8 +1467,7 @@ static void pl011_shutdown(struct uart_port *port)
/*
* Shut down the clock producer
*/
- clk_disable(uap->clk);
- clk_unprepare(uap->clk);
+ clk_disable_unprepare(uap->clk);
/* Optionally let pins go into sleep states */
if (!IS_ERR(uap->pins_sleep)) {
retval = pinctrl_select_state(uap->pinctrl, uap->pins_sleep);

2012-08-26 16:01:27

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 3/13] drivers/gpio/gpio-pxa.c: use clk_prepare_enable and clk_disable_unprepare

From: Julia Lawall <[email protected]>

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

---
drivers/gpio/gpio-pxa.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index 9528779..bd8fb66 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -589,19 +589,12 @@ static int __devinit pxa_gpio_probe(struct platform_device *pdev)
iounmap(gpio_reg_base);
return PTR_ERR(clk);
}
- ret = clk_prepare(clk);
+ ret = clk_prepare_enable(clk);
if (ret) {
clk_put(clk);
iounmap(gpio_reg_base);
return ret;
}
- ret = clk_enable(clk);
- if (ret) {
- clk_unprepare(clk);
- clk_put(clk);
- iounmap(gpio_reg_base);
- return ret;
- }

/* Initialize GPIO chips */
info = dev_get_platdata(&pdev->dev);

2012-08-26 16:02:37

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 10/13] drivers/watchdog/sp805_wdt.c: use clk_prepare_enable and clk_disable_unprepare

From: Julia Lawall <[email protected]>

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

---
drivers/watchdog/sp805_wdt.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/watchdog/sp805_wdt.c b/drivers/watchdog/sp805_wdt.c
index e4841c3..cabb040 100644
--- a/drivers/watchdog/sp805_wdt.c
+++ b/drivers/watchdog/sp805_wdt.c
@@ -130,16 +130,10 @@ static int wdt_config(struct watchdog_device *wdd, bool ping)
int ret;

if (!ping) {
- ret = clk_prepare(wdt->clk);
- if (ret) {
- dev_err(&wdt->adev->dev, "clock prepare fail");
- return ret;
- }

- ret = clk_enable(wdt->clk);
+ ret = clk_prepare_enable(wdt->clk);
if (ret) {
dev_err(&wdt->adev->dev, "clock enable fail");
- clk_unprepare(wdt->clk);
return ret;
}
}
@@ -190,8 +184,7 @@ static int wdt_disable(struct watchdog_device *wdd)
readl_relaxed(wdt->base + WDTLOCK);
spin_unlock(&wdt->lock);

- clk_disable(wdt->clk);
- clk_unprepare(wdt->clk);
+ clk_disable_unprepare(wdt->clk);

return 0;
}

2012-08-26 16:02:35

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 11/13] arch/arm/mach-at91/gpio.c: use clk_prepare_enable and clk_disable_unprepare

From: Julia Lawall <[email protected]>

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

---
arch/arm/mach-at91/gpio.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/arch/arm/mach-at91/gpio.c b/arch/arm/mach-at91/gpio.c
index be42cf0..7760f35 100644
--- a/arch/arm/mach-at91/gpio.c
+++ b/arch/arm/mach-at91/gpio.c
@@ -956,19 +956,14 @@ static int __init at91_gpio_setup_clk(int idx)
goto err;
}

- if (clk_prepare(at91_gpio->clock))
- goto clk_prep_err;
-
/* enable PIO controller's clock */
- if (clk_enable(at91_gpio->clock)) {
+ if (clk_prepare_enable(at91_gpio->clock)) {
pr_err("at91_gpio.%d, failed to enable clock, ignoring.\n", idx);
- goto clk_err;
+ goto clk_prep_err;
}

return 0;

-clk_err:
- clk_unprepare(at91_gpio->clock);
clk_prep_err:
clk_put(at91_gpio->clock);
err:

2012-08-26 16:03:15

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 6/13] drivers/iio/adc/at91_adc.c: use clk_prepare_enable and clk_disable_unprepare

From: Julia Lawall <[email protected]>

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

---
drivers/iio/adc/at91_adc.c | 33 +++++++++------------------------
1 file changed, 9 insertions(+), 24 deletions(-)

diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index 98c96f9..c1e4690 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -589,18 +589,13 @@ static int __devinit at91_adc_probe(struct platform_device *pdev)
goto error_free_irq;
}

- ret = clk_prepare(st->clk);
+ ret = clk_prepare_enable(st->clk);
if (ret) {
- dev_err(&pdev->dev, "Could not prepare the clock.\n");
+ dev_err(&pdev->dev,
+ "Could not prepare or enable the clock.\n");
goto error_free_irq;
}

- ret = clk_enable(st->clk);
- if (ret) {
- dev_err(&pdev->dev, "Could not enable the clock.\n");
- goto error_unprepare_clk;
- }
-
st->adc_clk = devm_clk_get(&pdev->dev, "adc_op_clk");
if (IS_ERR(st->adc_clk)) {
dev_err(&pdev->dev, "Failed to get the ADC clock.\n");
@@ -608,18 +603,13 @@ static int __devinit at91_adc_probe(struct platform_device *pdev)
goto error_disable_clk;
}

- ret = clk_prepare(st->adc_clk);
+ ret = clk_prepare_enable(st->adc_clk);
if (ret) {
- dev_err(&pdev->dev, "Could not prepare the ADC clock.\n");
+ dev_err(&pdev->dev,
+ "Could not prepare or enable the ADC clock.\n");
goto error_disable_clk;
}

- ret = clk_enable(st->adc_clk);
- if (ret) {
- dev_err(&pdev->dev, "Could not enable the ADC clock.\n");
- goto error_unprepare_adc_clk;
- }
-
/*
* Prescaler rate computation using the formula from the Atmel's
* datasheet : ADC Clock = MCK / ((Prescaler + 1) * 2), ADC Clock being
@@ -681,13 +671,9 @@ error_remove_triggers:
error_unregister_buffer:
at91_adc_buffer_remove(idev);
error_disable_adc_clk:
- clk_disable(st->adc_clk);
-error_unprepare_adc_clk:
- clk_unprepare(st->adc_clk);
+ clk_disable_unprepare(st->adc_clk);
error_disable_clk:
- clk_disable(st->clk);
-error_unprepare_clk:
- clk_unprepare(st->clk);
+ clk_disable_unprepare(st->clk);
error_free_irq:
free_irq(st->irq, idev);
error_free_device:
@@ -705,8 +691,7 @@ static int __devexit at91_adc_remove(struct platform_device *pdev)
at91_adc_trigger_remove(idev);
at91_adc_buffer_remove(idev);
clk_disable_unprepare(st->adc_clk);
- clk_disable(st->clk);
- clk_unprepare(st->clk);
+ clk_disable_unprepare(st->clk);
free_irq(st->irq, idev);
iio_device_free(idev);

2012-08-26 16:03:13

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 8/13] i2c: mv64xxx: use clk_prepare_enable and clk_disable_unprepare

From: Julia Lawall <[email protected]>

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

---
drivers/i2c/busses/i2c-mv64xxx.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 2e9d567..046c4b5 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -633,10 +633,8 @@ mv64xxx_i2c_probe(struct platform_device *pd)
#if defined(CONFIG_HAVE_CLK)
/* Not all platforms have a clk */
drv_data->clk = clk_get(&pd->dev, NULL);
- if (!IS_ERR(drv_data->clk)) {
- clk_prepare(drv_data->clk);
- clk_enable(drv_data->clk);
- }
+ if (!IS_ERR(drv_data->clk))
+ clk_prepare_enable(drv_data->clk);
#endif
if (pdata) {
drv_data->freq_m = pdata->freq_m;
@@ -686,10 +684,8 @@ mv64xxx_i2c_probe(struct platform_device *pd)
exit_unmap_regs:
#if defined(CONFIG_HAVE_CLK)
/* Not all platforms have a clk */
- if (!IS_ERR(drv_data->clk)) {
- clk_disable(drv_data->clk);
- clk_unprepare(drv_data->clk);
- }
+ if (!IS_ERR(drv_data->clk))
+ clk_disable_unprepare(drv_data->clk);
#endif
mv64xxx_i2c_unmap_regs(drv_data);
exit_kfree:
@@ -708,10 +704,8 @@ mv64xxx_i2c_remove(struct platform_device *dev)
mv64xxx_i2c_unmap_regs(drv_data);
#if defined(CONFIG_HAVE_CLK)
/* Not all platforms have a clk */
- if (!IS_ERR(drv_data->clk)) {
- clk_disable(drv_data->clk);
- clk_unprepare(drv_data->clk);
- }
+ if (!IS_ERR(drv_data->clk))
+ clk_disable_unprepare(drv_data->clk);
#endif
kfree(drv_data);

2012-08-26 16:03:11

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 7/13] drivers/mmc/host/mmci.c: use clk_prepare_enable and clk_disable_unprepare

From: Julia Lawall <[email protected]>

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

---
drivers/mmc/host/mmci.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index 50ff19a..edc3e9b 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -1309,14 +1309,10 @@ static int __devinit mmci_probe(struct amba_device *dev,
goto host_free;
}

- ret = clk_prepare(host->clk);
+ ret = clk_prepare_enable(host->clk);
if (ret)
goto clk_free;

- ret = clk_enable(host->clk);
- if (ret)
- goto clk_unprep;
-
host->plat = plat;
host->variant = variant;
host->mclk = clk_get_rate(host->clk);
@@ -1515,9 +1511,7 @@ static int __devinit mmci_probe(struct amba_device *dev,
err_gpio_cd:
iounmap(host->base);
clk_disable:
- clk_disable(host->clk);
- clk_unprep:
- clk_unprepare(host->clk);
+ clk_disable_unprepare(host->clk);
clk_free:
clk_put(host->clk);
host_free:
@@ -1564,8 +1558,7 @@ static int __devexit mmci_remove(struct amba_device *dev)
gpio_free(host->gpio_cd);

iounmap(host->base);
- clk_disable(host->clk);
- clk_unprepare(host->clk);
+ clk_disable_unprepare(host->clk);
clk_put(host->clk);

if (host->vcc)

2012-08-26 16:03:57

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 5/13] arch/arm: use clk_prepare_enable and clk_disable_unprepare

From: Julia Lawall <[email protected]>

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

---
arch/arm/common/sa1111.c | 3 +--
arch/arm/common/timer-sp.c | 16 ++++------------
arch/arm/kernel/smp_twd.c | 13 +++----------
3 files changed, 8 insertions(+), 24 deletions(-)

diff --git a/arch/arm/common/sa1111.c b/arch/arm/common/sa1111.c
index 9173d11..bd58414 100644
--- a/arch/arm/common/sa1111.c
+++ b/arch/arm/common/sa1111.c
@@ -834,8 +834,7 @@ static void __sa1111_remove(struct sa1111 *sachip)
sa1111_writel(0, irqbase + SA1111_WAKEEN0);
sa1111_writel(0, irqbase + SA1111_WAKEEN1);

- clk_disable(sachip->clk);
- clk_unprepare(sachip->clk);
+ clk_disable_unprepare(sachip->clk);

if (sachip->irq != NO_IRQ) {
irq_set_chained_handler(sachip->irq, NULL);
diff --git a/arch/arm/common/timer-sp.c b/arch/arm/common/timer-sp.c
index df13a3f..af1a4ab 100644
--- a/arch/arm/common/timer-sp.c
+++ b/arch/arm/common/timer-sp.c
@@ -42,17 +42,10 @@ static long __init sp804_get_clock_rate(const char *name)
return PTR_ERR(clk);
}

- err = clk_prepare(clk);
+ err = clk_prepare_enable(clk);
if (err) {
- pr_err("sp804: %s clock failed to prepare: %d\n", name, err);
- clk_put(clk);
- return err;
- }
-
- err = clk_enable(clk);
- if (err) {
- pr_err("sp804: %s clock failed to enable: %d\n", name, err);
- clk_unprepare(clk);
+ pr_err("sp804: %s clock failed to prepare or to enable: %d\n",
+ name, err);
clk_put(clk);
return err;
}
@@ -60,8 +53,7 @@ static long __init sp804_get_clock_rate(const char *name)
rate = clk_get_rate(clk);
if (rate < 0) {
pr_err("sp804: %s clock failed to get rate: %ld\n", name, rate);
- clk_disable(clk);
- clk_unprepare(clk);
+ clk_disable_unprepare(clk);
clk_put(clk);
}

diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c
index fef42b2..8c94b8b 100644
--- a/arch/arm/kernel/smp_twd.c
+++ b/arch/arm/kernel/smp_twd.c
@@ -204,17 +204,10 @@ static struct clk *twd_get_clock(void)
return clk;
}

- err = clk_prepare(clk);
+ err = clk_prepare_enable(clk);
if (err) {
- pr_err("smp_twd: clock failed to prepare: %d\n", err);
- clk_put(clk);
- return ERR_PTR(err);
- }
-
- err = clk_enable(clk);
- if (err) {
- pr_err("smp_twd: clock failed to enable: %d\n", err);
- clk_unprepare(clk);
+ pr_err("smp_twd: clock failed to prepare or to enable: %d\n",
+ err);
clk_put(clk);
return ERR_PTR(err);
}

2012-08-26 16:04:23

by Julia Lawall

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

From: Julia Lawall <[email protected]>

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

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

2012-08-26 16:04:38

by Julia Lawall

[permalink] [raw]
Subject: [PATCH 1/13] drivers/staging/iio/adc/spear_adc.c: use clk_prepare_enable and clk_disable_unprepare

From: Julia Lawall <[email protected]>

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

---
drivers/staging/iio/adc/spear_adc.c | 25 ++++++++-----------------
1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/iio/adc/spear_adc.c b/drivers/staging/iio/adc/spear_adc.c
index 675c427..0b83e2e 100644
--- a/drivers/staging/iio/adc/spear_adc.c
+++ b/drivers/staging/iio/adc/spear_adc.c
@@ -330,36 +330,30 @@ static int __devinit spear_adc_probe(struct platform_device *pdev)
goto errout3;
}

- ret = clk_prepare(info->clk);
- if (ret) {
- dev_err(dev, "failed preparing clock\n");
- goto errout4;
- }
-
- ret = clk_enable(info->clk);
+ ret = clk_prepare_enable(info->clk);
if (ret) {
dev_err(dev, "failed enabling clock\n");
- goto errout5;
+ goto errout4;
}

irq = platform_get_irq(pdev, 0);
if ((irq < 0) || (irq >= NR_IRQS)) {
dev_err(dev, "failed getting interrupt resource\n");
ret = -EINVAL;
- goto errout6;
+ goto errout5;
}

ret = devm_request_irq(dev, irq, spear_adc_isr, 0, MOD_NAME, info);
if (ret < 0) {
dev_err(dev, "failed requesting interrupt\n");
- goto errout6;
+ goto errout5;
}

if (of_property_read_u32(np, "sampling-frequency",
&info->sampling_freq)) {
dev_err(dev, "sampling-frequency missing in DT\n");
ret = -EINVAL;
- goto errout6;
+ goto errout5;
}

/*
@@ -389,16 +383,14 @@ static int __devinit spear_adc_probe(struct platform_device *pdev)

ret = iio_device_register(iodev);
if (ret)
- goto errout6;
+ goto errout5;

dev_info(dev, "SPEAR ADC driver loaded, IRQ %d\n", irq);

return 0;

-errout6:
- clk_disable(info->clk);
errout5:
- clk_unprepare(info->clk);
+ clk_disable_unprepare(info->clk);
errout4:
clk_put(info->clk);
errout3:
@@ -416,8 +408,7 @@ static int __devexit spear_adc_remove(struct platform_device *pdev)

iio_device_unregister(iodev);
platform_set_drvdata(pdev, NULL);
- clk_disable(info->clk);
- clk_unprepare(info->clk);
+ clk_disable_unprepare(info->clk);
clk_put(info->clk);
iounmap(info->adc_base_spear6xx);
iio_device_free(iodev);

2012-08-27 01:45:20

by Barry Song

[permalink] [raw]
Subject: Re: [PATCH 4/13] i2c: sirf: use clk_prepare_enable and clk_disable_unprepare

2012/8/27 Julia Lawall <[email protected]>:
> From: Julia Lawall <[email protected]>
>
> 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 <[email protected]>

Acked-by: Barry Song <[email protected]>

2012-08-27 04:01:07

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH 1/13] drivers/staging/iio/adc/spear_adc.c: use clk_prepare_enable and clk_disable_unprepare

On Sun, Aug 26, 2012 at 9:30 PM, Julia Lawall <[email protected]> wrote:
> From: Julia Lawall <[email protected]>
>
> 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/)

Reviewed-by: Viresh Kumar <[email protected]>

@Stefan/Shiraz: Can you update spear-devel mailing list in MAINTAINERS file
for this driver?

2012-08-27 04:04:12

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH 10/13] drivers/watchdog/sp805_wdt.c: use clk_prepare_enable and clk_disable_unprepare

On Sun, Aug 26, 2012 at 9:31 PM, Julia Lawall <[email protected]> wrote:
> From: Julia Lawall <[email protected]>
>
> 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/)

Acked-by: Viresh Kumar <[email protected]>

2012-08-27 05:57:35

by Pankaj Jangra

[permalink] [raw]
Subject: Re: [PATCH 5/13] arch/arm: use clk_prepare_enable and clk_disable_unprepare

Hi,

On Sun, Aug 26, 2012 at 9:30 PM, Julia Lawall <[email protected]> wrote:
> From: Julia Lawall <[email protected]>
>
> 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 <[email protected]>
>
> ---
> arch/arm/common/sa1111.c | 3 +--
> arch/arm/common/timer-sp.c | 16 ++++------------
> arch/arm/kernel/smp_twd.c | 13 +++----------
> 3 files changed, 8 insertions(+), 24 deletions(-)
>

Reviewed-by: Pankaj Jangra <[email protected]>

Regards,
Pankaj Jangra

2012-08-27 12:33:44

by Ulf Hansson

[permalink] [raw]
Subject: Re: [PATCH 7/13] drivers/mmc/host/mmci.c: use clk_prepare_enable and clk_disable_unprepare

Hi Julia,

Patches for mmci should normally be sent on the arm list as well. mmci
is maintained by Russell King, even if the MAINTAINER file does not
say so.

Some minor comment below.

On 26 August 2012 18:00, Julia Lawall <[email protected]> wrote:
> From: Julia Lawall <[email protected]>
>

I think can simplify the commit msg a lot. Just say something with
"simplify clock code in probe".

> 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 <[email protected]>
>
> ---
> drivers/mmc/host/mmci.c | 13 +++----------
> 1 file changed, 3 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
> index 50ff19a..edc3e9b 100644
> --- a/drivers/mmc/host/mmci.c
> +++ b/drivers/mmc/host/mmci.c
> @@ -1309,14 +1309,10 @@ static int __devinit mmci_probe(struct amba_device *dev,
> goto host_free;
> }
>
> - ret = clk_prepare(host->clk);
> + ret = clk_prepare_enable(host->clk);

white space? Did you run checkpatch?

> if (ret)
> goto clk_free;
>
> - ret = clk_enable(host->clk);
> - if (ret)
> - goto clk_unprep;
> -
> host->plat = plat;
> host->variant = variant;
> host->mclk = clk_get_rate(host->clk);
> @@ -1515,9 +1511,7 @@ static int __devinit mmci_probe(struct amba_device *dev,
> err_gpio_cd:
> iounmap(host->base);
> clk_disable:
> - clk_disable(host->clk);
> - clk_unprep:
> - clk_unprepare(host->clk);
> + clk_disable_unprepare(host->clk);

white space? Did you run checkpatch?

> clk_free:
> clk_put(host->clk);
> host_free:
> @@ -1564,8 +1558,7 @@ static int __devexit mmci_remove(struct amba_device *dev)
> gpio_free(host->gpio_cd);
>
> iounmap(host->base);
> - clk_disable(host->clk);
> - clk_unprepare(host->clk);
> + clk_disable_unprepare(host->clk);

white space? Did you run checkpatch?

> clk_put(host->clk);
>
> if (host->vcc)
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

Kind regards
Ulf Hansson

2012-08-27 12:46:17

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 7/13] drivers/mmc/host/mmci.c: use clk_prepare_enable and clk_disable_unprepare

On Mon, 27 Aug 2012, Ulf Hansson wrote:

> Hi Julia,
>
> Patches for mmci should normally be sent on the arm list as well. mmci
> is maintained by Russell King, even if the MAINTAINER file does not
> say so.

Would it be possible to update the MAINTAINER file?

> Some minor comment below.
>
> On 26 August 2012 18:00, Julia Lawall <[email protected]> wrote:
> > From: Julia Lawall <[email protected]>
> >
>
> I think can simplify the commit msg a lot. Just say something with
> "simplify clock code in probe".

OK, I wasn't familiar with these functions before, so I wanted to explain
my rationale for making the change, in case I was totally off base.

> > 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 <[email protected]>
> >
> > ---
> > drivers/mmc/host/mmci.c | 13 +++----------
> > 1 file changed, 3 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
> > index 50ff19a..edc3e9b 100644
> > --- a/drivers/mmc/host/mmci.c
> > +++ b/drivers/mmc/host/mmci.c
> > @@ -1309,14 +1309,10 @@ static int __devinit mmci_probe(struct amba_device *dev,
> > goto host_free;
> > }
> >
> > - ret = clk_prepare(host->clk);
> > + ret = clk_prepare_enable(host->clk);
>
> white space? Did you run checkpatch?

Yes, I did. And I did so again just now:

palace:linux-next: scripts/checkpatch.pl ~/patches/prepare2/send7
total: 0 errors, 0 warnings, 34 lines checked

/home/julia/patches/prepare2/send7 has no obvious style problems and is
ready for submission. I can see that in your reply there are no tabs,
only space. If you received it that way, perhaps it is a mailer problem
on my side, although I didn't do anything unusual for this patch.

I will try again.

julia


> > if (ret)
> > goto clk_free;
> >
> > - ret = clk_enable(host->clk);
> > - if (ret)
> > - goto clk_unprep;
> > -
> > host->plat = plat;
> > host->variant = variant;
> > host->mclk = clk_get_rate(host->clk);
> > @@ -1515,9 +1511,7 @@ static int __devinit mmci_probe(struct amba_device *dev,
> > err_gpio_cd:
> > iounmap(host->base);
> > clk_disable:
> > - clk_disable(host->clk);
> > - clk_unprep:
> > - clk_unprepare(host->clk);
> > + clk_disable_unprepare(host->clk);
>
> white space? Did you run checkpatch?
>
> > clk_free:
> > clk_put(host->clk);
> > host_free:
> > @@ -1564,8 +1558,7 @@ static int __devexit mmci_remove(struct amba_device *dev)
> > gpio_free(host->gpio_cd);
> >
> > iounmap(host->base);
> > - clk_disable(host->clk);
> > - clk_unprepare(host->clk);
> > + clk_disable_unprepare(host->clk);
>
> white space? Did you run checkpatch?
>
> > clk_put(host->clk);
> >
> > if (host->vcc)
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
> > the body of a message to [email protected]
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
>
> Kind regards
> Ulf Hansson
>

2012-08-27 12:55:15

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH 7/13] drivers/mmc/host/mmci.c: use clk_prepare_enable and clk_disable_unprepare

From: Julia Lawall <[email protected]>

Simplify clock code in probe.

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

---
v2, try to avoid whitespace problem

drivers/mmc/host/mmci.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index 50ff19a..edc3e9b 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -1309,14 +1309,10 @@ static int __devinit mmci_probe(struct amba_device *dev,
goto host_free;
}

- ret = clk_prepare(host->clk);
+ ret = clk_prepare_enable(host->clk);
if (ret)
goto clk_free;

- ret = clk_enable(host->clk);
- if (ret)
- goto clk_unprep;
-
host->plat = plat;
host->variant = variant;
host->mclk = clk_get_rate(host->clk);
@@ -1515,9 +1511,7 @@ static int __devinit mmci_probe(struct amba_device *dev,
err_gpio_cd:
iounmap(host->base);
clk_disable:
- clk_disable(host->clk);
- clk_unprep:
- clk_unprepare(host->clk);
+ clk_disable_unprepare(host->clk);
clk_free:
clk_put(host->clk);
host_free:
@@ -1564,8 +1558,7 @@ static int __devexit mmci_remove(struct amba_device *dev)
gpio_free(host->gpio_cd);

iounmap(host->base);
- clk_disable(host->clk);
- clk_unprepare(host->clk);
+ clk_disable_unprepare(host->clk);
clk_put(host->clk);

if (host->vcc)

2012-08-27 20:06:49

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 1/13] drivers/staging/iio/adc/spear_adc.c: use clk_prepare_enable and clk_disable_unprepare

On 08/27/2012 05:01 AM, viresh kumar wrote:
> On Sun, Aug 26, 2012 at 9:30 PM, Julia Lawall <[email protected]> wrote:
>> From: Julia Lawall <[email protected]>
>>
>> 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/)
>
> Reviewed-by: Viresh Kumar <[email protected]>
merged to fixes-togreg branch of kernel.org iio.git will push onwards in a few
days...
>
> @Stefan/Shiraz: Can you update spear-devel mailing list in MAINTAINERS file
> for this driver?
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2012-08-27 20:09:16

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 1/13] drivers/staging/iio/adc/spear_adc.c: use clk_prepare_enable and clk_disable_unprepare

On 08/27/2012 09:06 PM, Jonathan Cameron wrote:
> On 08/27/2012 05:01 AM, viresh kumar wrote:
>> On Sun, Aug 26, 2012 at 9:30 PM, Julia Lawall <[email protected]> wrote:
>>> From: Julia Lawall <[email protected]>
>>>
>>> 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/)
>>
>> Reviewed-by: Viresh Kumar <[email protected]>
> merged to fixes-togreg branch of kernel.org iio.git will push onwards in a few
> days...
sorry, wrong branch as clearly just a cleanup not a fix. Will be in togreg
branch instead.
>>
>> @Stefan/Shiraz: Can you update spear-devel mailing list in MAINTAINERS file
>> for this driver?
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2012-08-27 20:12:11

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 6/13] drivers/iio/adc/at91_adc.c: use clk_prepare_enable and clk_disable_unprepare

On 08/26/2012 05:00 PM, Julia Lawall wrote:
> From: Julia Lawall <[email protected]>
>
> 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 <[email protected]>
merged to togreg branch of
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git

Thanks,

Jonathan
>
> ---
> drivers/iio/adc/at91_adc.c | 33 +++++++++------------------------
> 1 file changed, 9 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
> index 98c96f9..c1e4690 100644
> --- a/drivers/iio/adc/at91_adc.c
> +++ b/drivers/iio/adc/at91_adc.c
> @@ -589,18 +589,13 @@ static int __devinit at91_adc_probe(struct platform_device *pdev)
> goto error_free_irq;
> }
>
> - ret = clk_prepare(st->clk);
> + ret = clk_prepare_enable(st->clk);
> if (ret) {
> - dev_err(&pdev->dev, "Could not prepare the clock.\n");
> + dev_err(&pdev->dev,
> + "Could not prepare or enable the clock.\n");
> goto error_free_irq;
> }
>
> - ret = clk_enable(st->clk);
> - if (ret) {
> - dev_err(&pdev->dev, "Could not enable the clock.\n");
> - goto error_unprepare_clk;
> - }
> -
> st->adc_clk = devm_clk_get(&pdev->dev, "adc_op_clk");
> if (IS_ERR(st->adc_clk)) {
> dev_err(&pdev->dev, "Failed to get the ADC clock.\n");
> @@ -608,18 +603,13 @@ static int __devinit at91_adc_probe(struct platform_device *pdev)
> goto error_disable_clk;
> }
>
> - ret = clk_prepare(st->adc_clk);
> + ret = clk_prepare_enable(st->adc_clk);
> if (ret) {
> - dev_err(&pdev->dev, "Could not prepare the ADC clock.\n");
> + dev_err(&pdev->dev,
> + "Could not prepare or enable the ADC clock.\n");
> goto error_disable_clk;
> }
>
> - ret = clk_enable(st->adc_clk);
> - if (ret) {
> - dev_err(&pdev->dev, "Could not enable the ADC clock.\n");
> - goto error_unprepare_adc_clk;
> - }
> -
> /*
> * Prescaler rate computation using the formula from the Atmel's
> * datasheet : ADC Clock = MCK / ((Prescaler + 1) * 2), ADC Clock being
> @@ -681,13 +671,9 @@ error_remove_triggers:
> error_unregister_buffer:
> at91_adc_buffer_remove(idev);
> error_disable_adc_clk:
> - clk_disable(st->adc_clk);
> -error_unprepare_adc_clk:
> - clk_unprepare(st->adc_clk);
> + clk_disable_unprepare(st->adc_clk);
> error_disable_clk:
> - clk_disable(st->clk);
> -error_unprepare_clk:
> - clk_unprepare(st->clk);
> + clk_disable_unprepare(st->clk);
> error_free_irq:
> free_irq(st->irq, idev);
> error_free_device:
> @@ -705,8 +691,7 @@ static int __devexit at91_adc_remove(struct platform_device *pdev)
> at91_adc_trigger_remove(idev);
> at91_adc_buffer_remove(idev);
> clk_disable_unprepare(st->adc_clk);
> - clk_disable(st->clk);
> - clk_unprepare(st->clk);
> + clk_disable_unprepare(st->clk);
> free_irq(st->irq, idev);
> iio_device_free(idev);
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2012-08-28 00:25:54

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH 13/13] drivers/rtc/rtc-coh901331.c: use clk_prepare_enable and clk_disable_unprepare

On Sun, Aug 26, 2012 at 9:01 AM, Julia Lawall <[email protected]> wrote:

> I'm not sure about this. Maybe it would be better to leave the disable and
> unprepare separated, since there is no matching nearby clk_prepare.

This is OK.
Acked-by: Linus Walleij <[email protected]>

Yours,
Linus Walleij