regmap: cache: Fix possible ZERO_SIZE_PTR pointer dereferencing error.
authorXiubo Li <Li.Xiubo@freescale.com>
Thu, 9 Oct 2014 09:02:57 +0000 (17:02 +0800)
committerMark Brown <broonie@kernel.org>
Mon, 20 Oct 2014 11:25:02 +0000 (12:25 +0100)
commitfb70067e4a2cc45d273864f071fd6cf62143137a
tree853f7f6971a9d336adb2d32a6a9ac12feb4bc753
parent06f9c24e55075e50ebc8b249a7853ad31bc1b3d1
regmap: cache: Fix possible ZERO_SIZE_PTR pointer dereferencing error.

When all the registers are volatile(unlikely, but logically and mostly
will happen for some 'device' who has very few registers), then the
count will be euqal to 0, then kmalloc() will return ZERO_SIZE_PTR,
which equals to ((void *)16).

So this patch fix this with just doing the zero check before calling
kmalloc(). If the count == 0, so we can make sure that all the registers
are volatile, so no cache is need.

Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/base/regmap/regcache.c