[PATCH v0 13/14] iio: magnetometer: ak8975: Use temporary variable for struct device

Andy Shevchenko
2026-04-27T20:14:32Z

Use temporary variable for struct device to make code neater.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/iio/magnetometer/ak8975.c | 61 +++++++++++++++----------------
1 file changed, 30 insertions(+), 31 deletions(-)

diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index c2eb7b0d0da8..e6ca30b36965 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -433,18 +433,17 @@ struct ak8975_data {
/* Enable attached power regulator if any. */
static int ak8975_power_on(const struct ak8975_data *data)
{
+ struct device *dev = &data->client->dev;
int ret;

ret = regulator_enable(data->vdd);
if (ret) {
- dev_warn(&data->client->dev,
- "Failed to enable specified Vdd supply\n");
+ dev_warn(dev, "Failed to enable specified Vdd supply\n");
return ret;
}
ret = regulator_enable(data->vid);
if (ret) {
- dev_warn(&data->client->dev,
- "Failed to enable specified Vid supply\n");
+ dev_warn(dev, "Failed to enable specified Vid supply\n");
regulator_disable(data->vdd);
return ret;
}
@@ -572,6 +571,7 @@ static irqreturn_t ak8975_irq_handler(int irq, void *data)
static int ak8975_setup_irq(struct ak8975_data *data)
{
struct i2c_client *client = data->client;
+ struct device *dev = &client->dev;
int irq;
int ret;

@@ -582,9 +582,8 @@ static int ak8975_setup_irq(struct ak8975_data *data)
else
irq = gpiod_to_irq(data->eoc_gpiod);

- ret = devm_request_irq(&client->dev, irq, ak8975_irq_handler,
- IRQF_TRIGGER_RISING,
- dev_name(&client->dev), data);
+ ret = devm_request_irq(dev, irq, ak8975_irq_handler, IRQF_TRIGGER_RISING,
+ dev_name(dev), data);
if (ret)
return ret;

@@ -600,12 +599,13 @@ static int ak8975_setup_irq(struct ak8975_data *data)
static int ak8975_setup(struct ak8975_data *data)
{
struct i2c_client *client = data->client;
+ struct device *dev = &client->dev;
int ret;

/* Write the fused rom access mode. */
ret = ak8975_set_mode(data, FUSE_ROM);
if (ret < 0) {
- dev_err(&client->dev, "Error in setting fuse access mode\n");
+ dev_err(dev, "Error in setting fuse access mode\n");
return ret;
}

@@ -615,22 +615,21 @@ static int ak8975_setup(struct ak8975_data *data)
sizeof(data->asa),
data->asa);
if (ret < 0) {
- dev_err(&client->dev, "Not able to read asa data\n");
+ dev_err(dev, "Not able to read asa data\n");
return ret;
}

/* After reading fuse ROM data set power-down mode */
ret = ak8975_set_mode(data, POWER_DOWN);
if (ret < 0) {
- dev_err(&client->dev, "Error in setting power-down mode\n");
+ dev_err(dev, "Error in setting power-down mode\n");
return ret;
}

if (data->eoc_gpiod || client->irq > 0) {
ret = ak8975_setup_irq(data);
if (ret < 0) {
- dev_err(&client->dev,
- "Error setting data ready interrupt\n");
+ dev_err(dev, "Error setting data ready interrupt\n");
return ret;
}
}
@@ -727,10 +726,11 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
struct ak8975_data *data = iio_priv(indio_dev);
const struct i2c_client *client = data->client;
const struct ak_def *def = data->def;
+ struct device *dev = &data->client->dev;
__le16 rval;
int ret;

- pm_runtime_get_sync(&data->client->dev);
+ pm_runtime_get_sync(dev);

mutex_lock(&data->lock);

@@ -748,20 +748,20 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
/* Read out ST2 for release lock on measurement data. */
ret = i2c_smbus_read_byte_data(client, data->def->ctrl_regs[ST2]);
if (ret < 0) {
- dev_err(&client->dev, "Error in reading ST2\n");
+ dev_err(dev, "Error in reading ST2\n");
goto exit;
}

if (ret & (data->def->ctrl_masks[ST2_DERR] |
data->def->ctrl_masks[ST2_HOFL])) {
- dev_err(&client->dev, "ST2 status error 0x%x\n", ret);
+ dev_err(dev, "ST2 status error 0x%x\n", ret);
ret = -EINVAL;
goto exit;
}

mutex_unlock(&data->lock);

- pm_runtime_put_autosuspend(&data->client->dev);
+ pm_runtime_put_autosuspend(dev);

/* Swap bytes and convert to valid range. */
*val = clamp_t(s16, le16_to_cpu(rval), -def->range, def->range);
@@ -770,7 +770,7 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)

exit:
mutex_unlock(&data->lock);
- dev_err(&client->dev, "Error in reading axis\n");
+ dev_err(dev, "Error in reading axis\n");
return ret;
}

@@ -909,7 +909,7 @@ static int ak8975_probe(struct i2c_client *client)
* We may not have a GPIO based IRQ to scan, that is fine, we will
* poll if so.
*/
- eoc_gpiod = devm_gpiod_get_optional(&client->dev, NULL, GPIOD_IN);
+ eoc_gpiod = devm_gpiod_get_optional(dev, NULL, GPIOD_IN);
if (IS_ERR(eoc_gpiod))
return PTR_ERR(eoc_gpiod);
gpiod_set_consumer_name(eoc_gpiod, "ak_8975");
@@ -919,13 +919,12 @@ static int ak8975_probe(struct i2c_client *client)
* deassert reset on ak8975_power_on() and assert reset on
* ak8975_power_off().
*/
- reset_gpiod = devm_gpiod_get_optional(&client->dev,
- "reset", GPIOD_OUT_HIGH);
+ reset_gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
if (IS_ERR(reset_gpiod))
return PTR_ERR(reset_gpiod);

/* Register with IIO */
- indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
if (indio_dev == NULL)
return -ENOMEM;

@@ -937,7 +936,7 @@ static int ak8975_probe(struct i2c_client *client)
data->reset_gpiod = reset_gpiod;
data->eoc_irq = 0;

- ret = iio_read_mount_matrix(&client->dev, &data->orientation);
+ ret = iio_read_mount_matrix(dev, &data->orientation);
if (ret)
return ret;

@@ -947,16 +946,16 @@ static int ak8975_probe(struct i2c_client *client)
return -ENODEV;

/* If enumerated via firmware node, fix the ABI */
- if (dev_fwnode(&client->dev))
- name = dev_name(&client->dev);
+ if (dev_fwnode(dev))
+ name = dev_name(dev);
else
name = id->name;

/* Fetch the regulators */
- data->vdd = devm_regulator_get(&client->dev, "vdd");
+ data->vdd = devm_regulator_get(dev, "vdd");
if (IS_ERR(data->vdd))
return PTR_ERR(data->vdd);
- data->vid = devm_regulator_get(&client->dev, "vid");
+ data->vid = devm_regulator_get(dev, "vid");
if (IS_ERR(data->vid))
return PTR_ERR(data->vid);

@@ -971,7 +970,7 @@ static int ak8975_probe(struct i2c_client *client)
ret = ak8975_who_i_am(data, data->def->type);
if (ret)
return dev_err_probe(dev, ret, "Unexpected device\n");
- dev_dbg(&client->dev, "Asahi compass chip %s\n", name);
+ dev_dbg(dev, "Asahi compass chip %s\n", name);

/* Perform some basic start-of-day setup of the device. */
ret = ak8975_setup(data);
@@ -1007,8 +1006,8 @@ static int ak8975_probe(struct i2c_client *client)
* The device comes online in 500us, so add two orders of magnitude
* of delay before autosuspending: 50 ms.
*/
- pm_runtime_set_autosuspend_delay(&client->dev, 50);
- pm_runtime_use_autosuspend(&client->dev);
+ pm_runtime_set_autosuspend_delay(dev, 50);
+ pm_runtime_use_autosuspend(dev);

return 0;
}
@@ -1023,7 +1022,7 @@ static int ak8975_runtime_suspend(struct device *dev)
/* Set the device in power down if it wasn't already */
ret = ak8975_set_mode(data, POWER_DOWN);
if (ret < 0) {
- dev_err(&client->dev, "Error in setting power-down mode\n");
+ dev_err(dev, "Error in setting power-down mode\n");
return ret;
}
/* Next cut the regulators */
@@ -1047,7 +1046,7 @@ static int ak8975_runtime_resume(struct device *dev)
*/
ret = ak8975_set_mode(data, POWER_DOWN);
if (ret < 0) {
- dev_err(&client->dev, "Error in setting power-down mode\n");
+ dev_err(dev, "Error in setting power-down mode\n");
return ret;
}

--
2.50.1