diff options
author | Xiubo Li <Li.Xiubo@freescale.com> | 2014-09-24 02:30:29 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2014-09-24 04:52:43 -0400 |
commit | c7908a37aeee2a038d7b1492eae29750d8738d2e (patch) | |
tree | abecdcc00c0e480427e0c0d1a680ce31df268220 /drivers/spi/spi.c | |
parent | 38ec10f60d9ca3a7eb3a5b52500a67479296b86f (diff) |
spi: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
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>
Diffstat (limited to 'drivers/spi/spi.c')
-rw-r--r-- | drivers/spi/spi.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 0edccc82ece5..cc83cdd969ce 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c | |||
@@ -552,6 +552,9 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n) | |||
552 | struct boardinfo *bi; | 552 | struct boardinfo *bi; |
553 | int i; | 553 | int i; |
554 | 554 | ||
555 | if (!n) | ||
556 | return -EINVAL; | ||
557 | |||
555 | bi = kzalloc(n * sizeof(*bi), GFP_KERNEL); | 558 | bi = kzalloc(n * sizeof(*bi), GFP_KERNEL); |
556 | if (!bi) | 559 | if (!bi) |
557 | return -ENOMEM; | 560 | return -ENOMEM; |