diff mbox

spi: Fix possible ZERO_SIZE_PTR pointer dereferencing error.

Message ID 1411540229-24915-1-git-send-email-Li.Xiubo@freescale.com (mailing list archive)
State Accepted
Commit c7908a37aeee2a038d7b1492eae29750d8738d2e
Headers show

Commit Message

Xiubo Li Sept. 24, 2014, 6:30 a.m. UTC
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>
---
 drivers/spi/spi.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox

Patch

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 95cfe3b..e19512f 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)
 	struct boardinfo *bi;
 	int i;
 
+	if (!n)
+		return -EINVAL;
+
 	bi = kzalloc(n * sizeof(*bi), GFP_KERNEL);
 	if (!bi)
 		return -ENOMEM;