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.

Changed files
+29 -4
drivers
iio
imu
+27 -3
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
··· 104 104 return 0; 105 105 } 106 106 107 + static 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 121 * inv_mpu_probe() - probe function. 109 122 * @client: i2c client. ··· 128 115 const struct i2c_device_id *id) 129 116 { 130 117 struct inv_mpu6050_state *st; 131 - int result; 132 - const char *name = id ? id->name : NULL; 118 + int result, chip_type; 133 119 struct regmap *regmap; 120 + const char *name; 134 121 135 122 if (!i2c_check_functionality(client->adapter, 136 123 I2C_FUNC_SMBUS_I2C_BLOCK)) 137 124 return -EOPNOTSUPP; 125 + 126 + if (id) { 127 + chip_type = (int)id->driver_data; 128 + name = id->name; 129 + } else if (ACPI_HANDLE(&client->dev)) { 130 + name = inv_mpu_match_acpi_device(&client->dev, &chip_type); 131 + if (!name) 132 + return -ENODEV; 133 + } else { 134 + return -ENOSYS; 135 + } 138 136 139 137 regmap = devm_regmap_init_i2c(client, &inv_mpu_regmap_config); 140 138 if (IS_ERR(regmap)) { ··· 155 131 } 156 132 157 133 result = inv_mpu_core_probe(regmap, client->irq, name, 158 - NULL, id->driver_data); 134 + NULL, chip_type); 159 135 if (result < 0) 160 136 return result; 161 137
+2 -1
drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
··· 46 46 struct regmap *regmap; 47 47 const struct spi_device_id *id = spi_get_device_id(spi); 48 48 const char *name = id ? id->name : NULL; 49 + const int chip_type = id ? id->driver_data : 0; 49 50 50 51 regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config); 51 52 if (IS_ERR(regmap)) { ··· 56 55 } 57 56 58 57 return inv_mpu_core_probe(regmap, spi->irq, name, 59 - inv_mpu_i2c_disable, id->driver_data); 58 + inv_mpu_i2c_disable, chip_type); 60 59 } 61 60 62 61 static int inv_mpu_remove(struct spi_device *spi)