Skip to content

Commit

Permalink
iio:imu:mpu6050: Fixed segfault in Invensens MPU driver due to null d…
Browse files Browse the repository at this point in the history
…ereference

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: Atilla Filiz <atilla.filiz@essensium.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Cc: Stable@vger.kernel.org
  • Loading branch information
Atilla Filiz authored and Jonathan Cameron committed Apr 26, 2014
1 parent c60e576 commit b9b3a41
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ static int inv_mpu_probe(struct i2c_client *client,
{
struct inv_mpu6050_state *st;
struct iio_dev *indio_dev;
struct inv_mpu6050_platform_data *pdata;
int result;

if (!i2c_check_functionality(client->adapter,
Expand All @@ -672,8 +673,10 @@ static int inv_mpu_probe(struct i2c_client *client,

st = iio_priv(indio_dev);
st->client = client;
st->plat_data = *(struct inv_mpu6050_platform_data
*)dev_get_platdata(&client->dev);
pdata = (struct inv_mpu6050_platform_data
*)dev_get_platdata(&client->dev);
if (pdata)
st->plat_data = *pdata;
/* power is turned on inside check chip type*/
result = inv_check_and_setup_chip(st, id);
if (result)
Expand Down

0 comments on commit b9b3a41

Please sign in to comment.