aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-05-05 18:38:07 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-05-05 18:38:07 -0400
commit2b86c4a84377b74a6ec0ec9463feb0803bcb1066 (patch)
tree31e88fad600270dfabe6f04d2557f141035d8988
parent431adc0aeca68d257bd705db50f73e4c19e5690d (diff)
parent393dbe4e18dd5b17b3952c7d36ac88f61ec40924 (diff)
Merge tag 'iio-fixes-for-4.6d' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus
Jonathan writes: Fourth set of IIO fixes for the 4.6 cycle. This last minute set is concerned with a regression in the mpu6050 driver. The regression causes a null pointer dereference on any ACPI device that has one of these present such as the ASUS T100TA Baytrail/T. The issue was known but thought (i.e. missunderstood by me) to only be a possible with no reports, so was routed via the normal merge window. Turns out this was wrong (thanks to Alan for reporting the crash). The pull is just for the null dereference fix and a followup fix that also stops the reported name of the device being NULL. * mpu6050 - Fix a 'possible' NULL dereference introduced as part of splitting the driver to allow both i2c and spi to be supported. The issue affects ACPI systems with this device. - Fix a follow up issue where the name and chip id both get set to null if the device driver instance is instantiated from ACPI tables.
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c30
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c3
2 files changed, 29 insertions, 4 deletions
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
index f581256d9d4c..5ee4e0dc093e 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
@@ -104,6 +104,19 @@ static int inv_mpu6050_deselect_bypass(struct i2c_adapter *adap,
104 return 0; 104 return 0;
105} 105}
106 106
107static const char *inv_mpu_match_acpi_device(struct device *dev, int *chip_id)
108{
109 const struct acpi_device_id *id;
110
111 id = acpi_match_device(dev->driver->acpi_match_table, dev);
112 if (!id)
113 return NULL;
114
115 *chip_id = (int)id->driver_data;
116
117 return dev_name(dev);
118}
119
107/** 120/**
108 * inv_mpu_probe() - probe function. 121 * inv_mpu_probe() - probe function.
109 * @client: i2c client. 122 * @client: i2c client.
@@ -115,14 +128,25 @@ static int inv_mpu_probe(struct i2c_client *client,
115 const struct i2c_device_id *id) 128 const struct i2c_device_id *id)
116{ 129{
117 struct inv_mpu6050_state *st; 130 struct inv_mpu6050_state *st;
118 int result; 131 int result, chip_type;
119 const char *name = id ? id->name : NULL;
120 struct regmap *regmap; 132 struct regmap *regmap;
133 const char *name;
121 134
122 if (!i2c_check_functionality(client->adapter, 135 if (!i2c_check_functionality(client->adapter,
123 I2C_FUNC_SMBUS_I2C_BLOCK)) 136 I2C_FUNC_SMBUS_I2C_BLOCK))
124 return -EOPNOTSUPP; 137 return -EOPNOTSUPP;
125 138
139 if (id) {
140 chip_type = (int)id->driver_data;
141 name = id->name;
142 } else if (ACPI_HANDLE(&client->dev)) {
143 name = inv_mpu_match_acpi_device(&client->dev, &chip_type);
144 if (!name)
145 return -ENODEV;
146 } else {
147 return -ENOSYS;
148 }
149
126 regmap = devm_regmap_init_i2c(client, &inv_mpu_regmap_config); 150 regmap = devm_regmap_init_i2c(client, &inv_mpu_regmap_config);
127 if (IS_ERR(regmap)) { 151 if (IS_ERR(regmap)) {
128 dev_err(&client->dev, "Failed to register i2c regmap %d\n", 152 dev_err(&client->dev, "Failed to register i2c regmap %d\n",
@@ -131,7 +155,7 @@ static int inv_mpu_probe(struct i2c_client *client,
131 } 155 }
132 156
133 result = inv_mpu_core_probe(regmap, client->irq, name, 157 result = inv_mpu_core_probe(regmap, client->irq, name,
134 NULL, id->driver_data); 158 NULL, chip_type);
135 if (result < 0) 159 if (result < 0)
136 return result; 160 return result;
137 161
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
index dea6c4361de0..7bcb8d839f05 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
@@ -46,6 +46,7 @@ static int inv_mpu_probe(struct spi_device *spi)
46 struct regmap *regmap; 46 struct regmap *regmap;
47 const struct spi_device_id *id = spi_get_device_id(spi); 47 const struct spi_device_id *id = spi_get_device_id(spi);
48 const char *name = id ? id->name : NULL; 48 const char *name = id ? id->name : NULL;
49 const int chip_type = id ? id->driver_data : 0;
49 50
50 regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config); 51 regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config);
51 if (IS_ERR(regmap)) { 52 if (IS_ERR(regmap)) {
@@ -55,7 +56,7 @@ static int inv_mpu_probe(struct spi_device *spi)
55 } 56 }
56 57
57 return inv_mpu_core_probe(regmap, spi->irq, name, 58 return inv_mpu_core_probe(regmap, spi->irq, name,
58 inv_mpu_i2c_disable, id->driver_data); 59 inv_mpu_i2c_disable, chip_type);
59} 60}
60 61
61static int inv_mpu_remove(struct spi_device *spi) 62static int inv_mpu_remove(struct spi_device *spi)