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

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

regmap: Fix possible ZERO_SIZE_PTR pointer dereferencing error.



Since we cannot make sure the 'len = pair_size * num_regs' will always
be none zero from the users, and then if 'num_regs' equals to zero by
mistake or other reasons, the kzalloc() will return ZERO_SIZE_PTR, which
equals to ((void *)16).

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

Signed-off-by: default avatarXiubo Li <Li.Xiubo@freescale.com>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent c9eaa447
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1615,6 +1615,9 @@ static int _regmap_raw_multi_reg_write(struct regmap *map,
	size_t pair_size = reg_bytes + pad_bytes + val_bytes;
	size_t len = pair_size * num_regs;

	if (!len)
		return -EINVAL;

	buf = kzalloc(len, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;