Commit cb26d236 authored by Jonathan Cameron's avatar Jonathan Cameron

iio:chemical:sgp30: Use local variable dev to simplify code

This cleans up the code at bit, but is primarily here as a precusor
to the next patch. I've only done this for the two functions
which use the dev pointer repeatedly.
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Cc: Andreas Brauchli <andreas.brauchli@sensirion.com>
Link: https://lore.kernel.org/r/20200910173242.621168-27-jic23@kernel.org
parent a867e898
...@@ -409,6 +409,7 @@ static int sgp_read_raw(struct iio_dev *indio_dev, ...@@ -409,6 +409,7 @@ static int sgp_read_raw(struct iio_dev *indio_dev,
static int sgp_check_compat(struct sgp_data *data, static int sgp_check_compat(struct sgp_data *data,
unsigned int product_id) unsigned int product_id)
{ {
struct device *dev = &data->client->dev;
const struct sgp_version *supported_versions; const struct sgp_version *supported_versions;
u16 ix, num_fs; u16 ix, num_fs;
u16 product, generation, major, minor; u16 product, generation, major, minor;
...@@ -416,21 +417,20 @@ static int sgp_check_compat(struct sgp_data *data, ...@@ -416,21 +417,20 @@ static int sgp_check_compat(struct sgp_data *data,
/* driver does not match product */ /* driver does not match product */
generation = SGP_VERS_GEN(data); generation = SGP_VERS_GEN(data);
if (generation != 0) { if (generation != 0) {
dev_err(&data->client->dev, dev_err(dev,
"incompatible product generation %d != 0", generation); "incompatible product generation %d != 0", generation);
return -ENODEV; return -ENODEV;
} }
product = SGP_VERS_PRODUCT(data); product = SGP_VERS_PRODUCT(data);
if (product != product_id) { if (product != product_id) {
dev_err(&data->client->dev, dev_err(dev, "sensor reports a different product: 0x%04hx\n",
"sensor reports a different product: 0x%04hx\n",
product); product);
return -ENODEV; return -ENODEV;
} }
if (SGP_VERS_RESERVED(data)) if (SGP_VERS_RESERVED(data))
dev_warn(&data->client->dev, "reserved bit is set\n"); dev_warn(dev, "reserved bit is set\n");
/* engineering samples are not supported: no interface guarantees */ /* engineering samples are not supported: no interface guarantees */
if (SGP_VERS_ENG_BIT(data)) if (SGP_VERS_ENG_BIT(data))
...@@ -456,8 +456,7 @@ static int sgp_check_compat(struct sgp_data *data, ...@@ -456,8 +456,7 @@ static int sgp_check_compat(struct sgp_data *data,
minor >= supported_versions[ix].minor) minor >= supported_versions[ix].minor)
return 0; return 0;
} }
dev_err(&data->client->dev, "unsupported sgp version: %d.%d\n", dev_err(dev, "unsupported sgp version: %d.%d\n", major, minor);
major, minor);
return -ENODEV; return -ENODEV;
} }
...@@ -499,17 +498,18 @@ static const struct of_device_id sgp_dt_ids[] = { ...@@ -499,17 +498,18 @@ static const struct of_device_id sgp_dt_ids[] = {
static int sgp_probe(struct i2c_client *client, static int sgp_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct device *dev = &client->dev;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct sgp_data *data; struct sgp_data *data;
const struct of_device_id *of_id; const struct of_device_id *of_id;
unsigned long product_id; unsigned long product_id;
int ret; int ret;
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
if (!indio_dev) if (!indio_dev)
return -ENOMEM; return -ENOMEM;
of_id = of_match_device(sgp_dt_ids, &client->dev); of_id = of_match_device(sgp_dt_ids, dev);
if (of_id) if (of_id)
product_id = (unsigned long)of_id->data; product_id = (unsigned long)of_id->data;
else else
...@@ -541,9 +541,9 @@ static int sgp_probe(struct i2c_client *client, ...@@ -541,9 +541,9 @@ static int sgp_probe(struct i2c_client *client,
sgp_init(data); sgp_init(data);
ret = devm_iio_device_register(&client->dev, indio_dev); ret = devm_iio_device_register(dev, indio_dev);
if (ret) { if (ret) {
dev_err(&client->dev, "failed to register iio device\n"); dev_err(dev, "failed to register iio device\n");
return ret; return ret;
} }
......
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