[PATCH] commands: spi: fix chip select validation

Sascha Hauer s.hauer at pengutronix.de
Mon Nov 7 23:56:03 PST 2016


On Mon, Nov 07, 2016 at 04:10:56PM +0100, Stefan Lengfeld wrote:
> The chip selects are numbered 0..(max chip selects - 1). Chip select
> with number <max chip selects> is invalid. Fix the check for that. Using
> the out of bound chip select may hang your board.
> 
> Signed-off-by: Stefan Lengfeld <s.lengfeld at phytec.de>
> ---
>  commands/spi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/commands/spi.c b/commands/spi.c
> index 21db9ae..6603b34 100644
> --- a/commands/spi.c
> +++ b/commands/spi.c
> @@ -68,8 +68,8 @@ static int do_spi(int argc, char *argv[])
>  		return -ENODEV;
>  	}
>  
> -	if (spi.chip_select > spi.master->num_chipselect) {
> -		printf("spi chip select (%d)> master num chipselect (%d)\n",
> +	if (spi.chip_select >= spi.master->num_chipselect) {
> +		printf("spi chip select (%d) >= master num chipselect (%d)\n",
>  			spi.chip_select, spi.master->num_chipselect);
>  		return -EINVAL;
>  	}
> -- 
> 1.9.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list