Skip to content

Commit

Permalink
spi: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
Browse files Browse the repository at this point in the history
Since we cannot make sure the 'n' will always be none zero here, and
then if either equal to zero, the kzalloc() will return ZERO_SIZE_PTR,
which equals to ((void *)16).

So this patch fix this with just doing the zero check before calling
kzalloc().

Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Xiubo Li authored and Mark Brown committed Sep 24, 2014
1 parent 38ec10f commit c7908a3
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/spi/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n)
struct boardinfo *bi;
int i;

if (!n)
return -EINVAL;

bi = kzalloc(n * sizeof(*bi), GFP_KERNEL);
if (!bi)
return -ENOMEM;
Expand Down

0 comments on commit c7908a3

Please sign in to comment.