Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c7908a37 authored by Xiubo Li's avatar Xiubo Li Committed by Mark Brown
Browse files

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: default avatarXiubo Li <Li.Xiubo@freescale.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 38ec10f6
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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;