aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrzysztof Kozlowski <k.kozlowski@samsung.com>2014-02-11 05:03:34 -0500
committerLee Jones <lee.jones@linaro.org>2014-03-19 04:58:08 -0400
commit97dc4ed3fa377ec91bb60ba98b70d645c2099384 (patch)
tree263230d4a648cca58e8e86c253e5642fbe99bb54
parent3c699105d0376c14940ce7cf561754a94cdff8dd (diff)
mfd: max8997: Fix possible NULL pointer dereference on i2c_new_dummy error
During probe the driver allocates dummy I2C devices for RTC, haptic and MUIC with i2c_new_dummy() but it does not check the return value of this calls. In case of error (i2c_new_device(): memory allocation failure or I2C address cannot be used) this function returns NULL which is later used by i2c_unregister_device(). If i2c_new_dummy() fails for RTC, haptic or MUIC devices, fail also the probe for main MFD driver. Cc: stable@vger.kernel.org Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> Signed-off-by: Lee Jones <lee.jones@linaro.org>
-rw-r--r--drivers/mfd/max8997.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c
index 5adede0fb04c..8cf7a015cfe5 100644
--- a/drivers/mfd/max8997.c
+++ b/drivers/mfd/max8997.c
@@ -208,10 +208,26 @@ static int max8997_i2c_probe(struct i2c_client *i2c,
208 mutex_init(&max8997->iolock); 208 mutex_init(&max8997->iolock);
209 209
210 max8997->rtc = i2c_new_dummy(i2c->adapter, I2C_ADDR_RTC); 210 max8997->rtc = i2c_new_dummy(i2c->adapter, I2C_ADDR_RTC);
211 if (!max8997->rtc) {
212 dev_err(max8997->dev, "Failed to allocate I2C device for RTC\n");
213 return -ENODEV;
214 }
211 i2c_set_clientdata(max8997->rtc, max8997); 215 i2c_set_clientdata(max8997->rtc, max8997);
216
212 max8997->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC); 217 max8997->haptic = i2c_new_dummy(i2c->adapter, I2C_ADDR_HAPTIC);
218 if (!max8997->haptic) {
219 dev_err(max8997->dev, "Failed to allocate I2C device for Haptic\n");
220 ret = -ENODEV;
221 goto err_i2c_haptic;
222 }
213 i2c_set_clientdata(max8997->haptic, max8997); 223 i2c_set_clientdata(max8997->haptic, max8997);
224
214 max8997->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC); 225 max8997->muic = i2c_new_dummy(i2c->adapter, I2C_ADDR_MUIC);
226 if (!max8997->muic) {
227 dev_err(max8997->dev, "Failed to allocate I2C device for MUIC\n");
228 ret = -ENODEV;
229 goto err_i2c_muic;
230 }
215 i2c_set_clientdata(max8997->muic, max8997); 231 i2c_set_clientdata(max8997->muic, max8997);
216 232
217 pm_runtime_set_active(max8997->dev); 233 pm_runtime_set_active(max8997->dev);
@@ -239,7 +255,9 @@ static int max8997_i2c_probe(struct i2c_client *i2c,
239err_mfd: 255err_mfd:
240 mfd_remove_devices(max8997->dev); 256 mfd_remove_devices(max8997->dev);
241 i2c_unregister_device(max8997->muic); 257 i2c_unregister_device(max8997->muic);
258err_i2c_muic:
242 i2c_unregister_device(max8997->haptic); 259 i2c_unregister_device(max8997->haptic);
260err_i2c_haptic:
243 i2c_unregister_device(max8997->rtc); 261 i2c_unregister_device(max8997->rtc);
244 return ret; 262 return ret;
245} 263}