diff options
| author | Linux Build Service Account <lnxbuild@localhost> | 2017-01-19 09:52:37 -0800 |
|---|---|---|
| committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2017-01-19 09:52:37 -0800 |
| commit | 8d03dd19a923c1750d91de0a1bc8627665988404 (patch) | |
| tree | 94881bc50600845eedb440fe1afff00dfd2f9a77 | |
| parent | ca24c4deccf507651d69929514abc76a21421c56 (diff) | |
| parent | 6614eb6abf4d74bc57b3cab94663807da9d27e53 (diff) | |
Merge "drivers: mfd: Check device id null pointer before dereferencing"
| -rw-r--r-- | drivers/mfd/wcd9xxx-core.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/drivers/mfd/wcd9xxx-core.c b/drivers/mfd/wcd9xxx-core.c index 5bcd0db929b3..5a97affd96a4 100644 --- a/drivers/mfd/wcd9xxx-core.c +++ b/drivers/mfd/wcd9xxx-core.c @@ -1214,11 +1214,19 @@ static int wcd9xxx_slim_probe(struct slim_device *slim) { struct wcd9xxx *wcd9xxx; struct wcd9xxx_pdata *pdata; + const struct slim_device_id *device_id; int ret = 0; int intf_type; intf_type = wcd9xxx_get_intf_type(); + wcd9xxx = devm_kzalloc(&slim->dev, sizeof(struct wcd9xxx), + GFP_KERNEL); + if (!wcd9xxx) { + ret = -ENOMEM; + goto err; + } + if (!slim) { ret = -EINVAL; goto err; @@ -1227,7 +1235,8 @@ static int wcd9xxx_slim_probe(struct slim_device *slim) if (intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { dev_dbg(&slim->dev, "%s:Codec is detected in I2C mode\n", __func__); - return -ENODEV; + ret = -ENODEV; + goto err; } if (slim->dev.of_node) { dev_info(&slim->dev, "Platform data from device tree\n"); @@ -1261,21 +1270,22 @@ static int wcd9xxx_slim_probe(struct slim_device *slim) goto err; } - wcd9xxx = devm_kzalloc(&slim->dev, sizeof(struct wcd9xxx), - GFP_KERNEL); - if (!wcd9xxx) { - ret = -ENOMEM; - goto err; - } if (!slim->ctrl) { dev_err(&slim->dev, "%s: Error, no SLIMBUS control data\n", __func__); ret = -EINVAL; goto err_codec; } - wcd9xxx->type = slim_get_device_id(slim)->driver_data; + device_id = slim_get_device_id(slim); + if (!device_id) { + dev_err(&slim->dev, "%s: Error, no device id\n", __func__); + ret = -EINVAL; + goto err; + } + + wcd9xxx->type = device_id->driver_data; dev_info(&slim->dev, "%s: probing for wcd type: %d, name: %s\n", - __func__, wcd9xxx->type, slim_get_device_id(slim)->name); + __func__, wcd9xxx->type, device_id->name); /* wcd9xxx members init */ wcd9xxx->multi_reg_write = wcd9xxx_slim_multi_reg_write; @@ -1416,6 +1426,7 @@ err_supplies: err_codec: slim_set_clientdata(slim, NULL); err: + devm_kfree(&slim->dev, wcd9xxx); return ret; } static int wcd9xxx_slim_remove(struct slim_device *pdev) |
