aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baluta <daniel.baluta@intel.com>2016-03-17 12:32:44 -0400
committerJonathan Cameron <jic23@kernel.org>2016-05-04 03:44:27 -0400
commit393dbe4e18dd5b17b3952c7d36ac88f61ec40924 (patch)
tree31e88fad600270dfabe6f04d2557f141035d8988
parent140afdd9626cdaaf54223e82931213de785c7c94 (diff)
iio: imu: mpu6050: Fix name/chip_id when using ACPI
When using ACPI, id is NULL and the current code automatically defaults name to NULL and chip id to 0. We should instead use the data provided in the ACPI device table. Fixes: c816d9e7a57b ("iio: imu: mpu6050: fix possible NULL dereferences") Signed-off-by: Daniel Baluta <daniel.baluta@intel.com> Reviewed-By: Matt Ranostay <matt.ranostay@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
index d0c0e20c7122..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,15 +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 const int chip_type = id ? id->driver_data : 0;
121 struct regmap *regmap; 132 struct regmap *regmap;
133 const char *name;
122 134
123 if (!i2c_check_functionality(client->adapter, 135 if (!i2c_check_functionality(client->adapter,
124 I2C_FUNC_SMBUS_I2C_BLOCK)) 136 I2C_FUNC_SMBUS_I2C_BLOCK))
125 return -EOPNOTSUPP; 137 return -EOPNOTSUPP;
126 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
127 regmap = devm_regmap_init_i2c(client, &inv_mpu_regmap_config); 150 regmap = devm_regmap_init_i2c(client, &inv_mpu_regmap_config);
128 if (IS_ERR(regmap)) { 151 if (IS_ERR(regmap)) {
129 dev_err(&client->dev, "Failed to register i2c regmap %d\n", 152 dev_err(&client->dev, "Failed to register i2c regmap %d\n",