Browse Source

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>
Xiubo Li 11 years ago
parent
commit
c7908a37ae
1 changed files with 3 additions and 0 deletions
  1. 3 0
      drivers/spi/spi.c

+ 3 - 0
drivers/spi/spi.c

@@ -552,6 +552,9 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n)
 	struct boardinfo *bi;
 	struct boardinfo *bi;
 	int i;
 	int i;
 
 
+	if (!n)
+		return -EINVAL;
+
 	bi = kzalloc(n * sizeof(*bi), GFP_KERNEL);
 	bi = kzalloc(n * sizeof(*bi), GFP_KERNEL);
 	if (!bi)
 	if (!bi)
 		return -ENOMEM;
 		return -ENOMEM;