iio: cm36651: Fix i2c client leak and possible NULL pointer dereference
authorKrzysztof Kozlowski <k.kozlowski@samsung.com>
Tue, 18 Mar 2014 08:13:00 +0000 (08:13 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 6 May 2014 14:59:27 +0000 (07:59 -0700)
commit9a64345f0369251f2841bccec8054f5bdb2b673b
tree2ddcd7a3af095c070e6c64bb2ff3c16f811e8bfe
parent7b2e3d27a269cc43bbf7fa37d28b8e554ed6b66c
iio: cm36651: Fix i2c client leak and possible NULL pointer dereference

commit d0a588a57c2b0748df8307a0865a1bbbf1624c53 upstream.

During probe the driver allocates dummy I2C devices (i2c_new_dummy())
but they aren't unregistered during driver remove or probe failure.

Additionally driver does not check the return value of i2c_new_dummy().
In case of error (i2c_new_device(): memory allocation failure or I2C
address cannot be used) this function returns NULL which is later
dereferenced by i2c_smbus_{read,write}_data() functions.

Fix issues by properly checking for i2c_new_dummy() return value and
unregistering I2C devices on driver remove or probe failure.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Acked-by: Beomho Seo <beomho.seo@samsung.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/iio/light/cm36651.c