diff mbox

[06/11] spi-dw: Force error on out of range chip select.

Message ID 1308794413-11069-7-git-send-email-dirk.brandewie@gmail.com
State Superseded, archived
Headers show

Commit Message

dirk.brandewie@gmail.com June 23, 2011, 2 a.m. UTC
From: Dirk Brandewie <dirk.brandewie@gmail.com>

BUG_ON() if the selected chip select is out of range.

Signed-off-by: Dirk Brandewie <dirk.brandewie@gmail.com>
---
 drivers/spi/spi-dw.h |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

Comments

Grant Likely June 23, 2011, 3:51 a.m. UTC | #1
On Wed, Jun 22, 2011 at 8:00 PM,  <dirk.brandewie@gmail.com> wrote:
> From: Dirk Brandewie <dirk.brandewie@gmail.com>
>
> BUG_ON() if the selected chip select is out of range.
>
> Signed-off-by: Dirk Brandewie <dirk.brandewie@gmail.com>
> ---
>  drivers/spi/spi-dw.h |    3 +--
>  1 files changed, 1 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h
> index 860bc34..3fa4c13 100644
> --- a/drivers/spi/spi-dw.h
> +++ b/drivers/spi/spi-dw.h
> @@ -178,8 +178,7 @@ static inline void spi_dw_set_clk(struct spi_dw *dws, u16 div)
>
>  static inline void spi_dw_chip_sel(struct spi_dw *dws, u16 cs)
>  {
> -       if (cs > dws->num_cs)
> -               return;
> +       BUG_ON(cs >= dws->master->num_chipselect);

BUG is rather an over-reaction.  The transfer should be rejected if
the cs# is invalid, and a warning message is appropriate, but BUG() is
too extreme.

g.

------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev
dirk.brandewie@gmail.com June 23, 2011, 4:13 a.m. UTC | #2
On 06/22/2011 08:51 PM, Grant Likely wrote:
> On Wed, Jun 22, 2011 at 8:00 PM,<dirk.brandewie@gmail.com>  wrote:
>> From: Dirk Brandewie<dirk.brandewie@gmail.com>
>>
>> BUG_ON() if the selected chip select is out of range.
>>
>> Signed-off-by: Dirk Brandewie<dirk.brandewie@gmail.com>
>> ---
>>   drivers/spi/spi-dw.h |    3 +--
>>   1 files changed, 1 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h
>> index 860bc34..3fa4c13 100644
>> --- a/drivers/spi/spi-dw.h
>> +++ b/drivers/spi/spi-dw.h
>> @@ -178,8 +178,7 @@ static inline void spi_dw_set_clk(struct spi_dw *dws, u16 div)
>>
>>   static inline void spi_dw_chip_sel(struct spi_dw *dws, u16 cs)
>>   {
>> -       if (cs>  dws->num_cs)
>> -               return;
>> +       BUG_ON(cs>= dws->master->num_chipselect);
>
> BUG is rather an over-reaction.  The transfer should be rejected if
> the cs# is invalid, and a warning message is appropriate, but BUG() is
> too extreme.

This is extreme I agree, the current driver will fail silently if an out of 
range chip select is requested.

We can drop this one for now and I will put a proper check in probe/init so we 
won't get here.



>
> g.


------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev
diff mbox

Patch

diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h
index 860bc34..3fa4c13 100644
--- a/drivers/spi/spi-dw.h
+++ b/drivers/spi/spi-dw.h
@@ -178,8 +178,7 @@  static inline void spi_dw_set_clk(struct spi_dw *dws, u16 div)
 
 static inline void spi_dw_chip_sel(struct spi_dw *dws, u16 cs)
 {
-	if (cs > dws->num_cs)
-		return;
+	BUG_ON(cs >= dws->master->num_chipselect);
 
 	if (dws->cs_control)
 		dws->cs_control(SPI_DW_ASSERT);