Commit b9b3a418 authored by Atilla Filiz's avatar Atilla Filiz Committed by Jonathan Cameron

iio:imu:mpu6050: Fixed segfault in Invensens MPU driver due to null dereference

The driver segfaults when the kernel boots with device tree as the
platform data is then not present and the pointer is deferenced without
checking it is not null.  This patch introduces such a check avoiding the
crash.
Signed-off-by: default avatarAtilla Filiz <atilla.filiz@essensium.com>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
Cc: Stable@vger.kernel.org
parent c60e5760
...@@ -660,6 +660,7 @@ static int inv_mpu_probe(struct i2c_client *client, ...@@ -660,6 +660,7 @@ static int inv_mpu_probe(struct i2c_client *client,
{ {
struct inv_mpu6050_state *st; struct inv_mpu6050_state *st;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct inv_mpu6050_platform_data *pdata;
int result; int result;
if (!i2c_check_functionality(client->adapter, if (!i2c_check_functionality(client->adapter,
...@@ -672,8 +673,10 @@ static int inv_mpu_probe(struct i2c_client *client, ...@@ -672,8 +673,10 @@ static int inv_mpu_probe(struct i2c_client *client,
st = iio_priv(indio_dev); st = iio_priv(indio_dev);
st->client = client; st->client = client;
st->plat_data = *(struct inv_mpu6050_platform_data pdata = (struct inv_mpu6050_platform_data
*)dev_get_platdata(&client->dev); *)dev_get_platdata(&client->dev);
if (pdata)
st->plat_data = *pdata;
/* power is turned on inside check chip type*/ /* power is turned on inside check chip type*/
result = inv_check_and_setup_chip(st, id); result = inv_check_and_setup_chip(st, id);
if (result) if (result)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment