diff mbox

spi: atmel: Fix scheduling while atomic

Message ID 1478792090-6376-1-git-send-email-ben.whitten@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ben Whitten Nov. 10, 2016, 3:34 p.m. UTC
From: Ben Whitten <ben.whitten@lairdtech.com>

A call to clk_get_rate appears to be called in the context of an interrupt,
cache the bus clock for the frequency calculations in transmission.

This fixes a 'BUG: scheduling while atomic' and
'WARNING: CPU: 0 PID: 777 at kernel/sched/core.c:2960 atmel_spi_unlock'

Signed-off-by: Ben Whitten <ben.whitten@lairdtech.com>
Signed-off-by: Steve deRosier <steve.derosier@lairdtech.com>
---
 drivers/spi/spi-atmel.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Alexandre Belloni Nov. 14, 2016, 1:08 p.m. UTC | #1
Hi,

On 10/11/2016 at 15:34:50 +0000, ben.whitten@gmail.com wrote :
> From: Ben Whitten <ben.whitten@lairdtech.com>
> 
> A call to clk_get_rate appears to be called in the context of an interrupt,
> cache the bus clock for the frequency calculations in transmission.
> 
> This fixes a 'BUG: scheduling while atomic' and
> 'WARNING: CPU: 0 PID: 777 at kernel/sched/core.c:2960 atmel_spi_unlock'
> 
> Signed-off-by: Ben Whitten <ben.whitten@lairdtech.com>
> Signed-off-by: Steve deRosier <steve.derosier@lairdtech.com>

The spi subsystem maintainer is not copied so this fix will not be
applied.

Else, it seems ok to me.

> ---
>  drivers/spi/spi-atmel.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
> index 8feac59..c281d1a 100644
> --- a/drivers/spi/spi-atmel.c
> +++ b/drivers/spi/spi-atmel.c
> @@ -295,6 +295,7 @@ struct atmel_spi {
>  	int			irq;
>  	struct clk		*clk;
>  	struct platform_device	*pdev;
> +	unsigned long		spi_clk;
>  
>  	struct spi_transfer	*current_transfer;
>  	int			current_remaining_bytes;
> @@ -864,7 +865,7 @@ static int atmel_spi_set_xfer_speed(struct atmel_spi *as,
>  	unsigned long		bus_hz;
>  
>  	/* v1 chips start out at half the peripheral bus speed. */
> -	bus_hz = clk_get_rate(as->clk);
> +	bus_hz = as->spi_clk;
>  	if (!atmel_spi_is_v2(as))
>  		bus_hz /= 2;
>  
> @@ -1606,6 +1607,9 @@ static int atmel_spi_probe(struct platform_device *pdev)
>  	ret = clk_prepare_enable(clk);
>  	if (ret)
>  		goto out_free_irq;
> +
> +	as->spi_clk = clk_get_rate(clk);
> +
>  	spi_writel(as, CR, SPI_BIT(SWRST));
>  	spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
>  	if (as->caps.has_wdrbt) {
> -- 
> 2.7.4
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
diff mbox

Patch

diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
index 8feac59..c281d1a 100644
--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -295,6 +295,7 @@  struct atmel_spi {
 	int			irq;
 	struct clk		*clk;
 	struct platform_device	*pdev;
+	unsigned long		spi_clk;
 
 	struct spi_transfer	*current_transfer;
 	int			current_remaining_bytes;
@@ -864,7 +865,7 @@  static int atmel_spi_set_xfer_speed(struct atmel_spi *as,
 	unsigned long		bus_hz;
 
 	/* v1 chips start out at half the peripheral bus speed. */
-	bus_hz = clk_get_rate(as->clk);
+	bus_hz = as->spi_clk;
 	if (!atmel_spi_is_v2(as))
 		bus_hz /= 2;
 
@@ -1606,6 +1607,9 @@  static int atmel_spi_probe(struct platform_device *pdev)
 	ret = clk_prepare_enable(clk);
 	if (ret)
 		goto out_free_irq;
+
+	as->spi_clk = clk_get_rate(clk);
+
 	spi_writel(as, CR, SPI_BIT(SWRST));
 	spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
 	if (as->caps.has_wdrbt) {