From: Joshua Crofts via B4 Relay <devnull+joshua.crofts1.gmail.com@kernel.org>
To: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Joshua Crofts <joshua.crofts1@gmail.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v4 16/17] iio: magnetometer: ak8975: use temporary variable for struct device
Date: Mon, 04 May 2026 11:48:28 +0200 [thread overview]
Message-ID: <20260504-magnetometer-fixes-v4-16-a291c2a7c71a@gmail.com> (raw)
In-Reply-To: <20260504-magnetometer-fixes-v4-0-a291c2a7c71a@gmail.com>
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Use temporary variable for struct device to make code neater.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.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 861a12ba8cfcc3724573b332b3f5bc243b67b1de..eeaf7cd5e36dc0e09f4bc588edceeb66501b8bef 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;
}
}
@@ -734,10 +733,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);
@@ -755,20 +755,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);
@@ -777,7 +777,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;
}
@@ -927,7 +927,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");
@@ -937,13 +937,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;
@@ -955,7 +954,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;
@@ -965,16 +964,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);
@@ -996,7 +995,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);
@@ -1032,8 +1031,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;
}
@@ -1048,7 +1047,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 */
@@ -1072,7 +1071,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.47.3
next prev parent reply other threads:[~2026-05-04 9:48 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-04 9:48 [PATCH v4 00/17] iio: magnetometer: ak8975: modernize and cleanup driver Joshua Crofts via B4 Relay
2026-05-04 9:48 ` [PATCH v4 01/17] iio: magnetometer: ak8975: sort headers alphabetically Joshua Crofts via B4 Relay
2026-05-04 9:48 ` [PATCH v4 02/17] iio: magnetometer: ak8975: update headers per IWYU principle Joshua Crofts via B4 Relay
2026-05-04 9:48 ` [PATCH v4 03/17] iio: magnetometer: ak8975: replace usleep_range() with fsleep() Joshua Crofts via B4 Relay
2026-05-04 9:48 ` [PATCH v4 04/17] iio: magnetometer: ak8975: change 'u8*' to 'u8 *' in cast Joshua Crofts via B4 Relay
2026-05-04 9:48 ` [PATCH v4 05/17] iio: magnetometer: ak8975: fix wrong errno on return Joshua Crofts via B4 Relay
2026-05-04 9:48 ` [PATCH v4 06/17] iio: magnetometer: ak8975: modernize polling loops with iopoll() macros Joshua Crofts via B4 Relay
2026-05-04 11:18 ` Andy Shevchenko
2026-05-04 15:06 ` Jonathan Cameron
2026-05-05 4:57 ` Andy Shevchenko
2026-05-05 7:07 ` Joshua Crofts
2026-05-05 7:21 ` Andy Shevchenko
2026-05-05 7:26 ` Joshua Crofts
2026-05-05 8:07 ` Joshua Crofts
2026-05-05 8:17 ` Andy Shevchenko
2026-05-04 9:48 ` [PATCH v4 07/17] iio: magnetometer: ak8975: pass conversion timeouts as arguments Joshua Crofts via B4 Relay
2026-05-04 11:10 ` Andy Shevchenko
2026-05-04 11:25 ` Joshua Crofts
2026-05-04 14:06 ` Andy Shevchenko
2026-05-04 14:11 ` Joshua Crofts
2026-05-04 15:07 ` Jonathan Cameron
2026-05-04 11:33 ` Joshua Crofts
2026-05-04 15:09 ` Jonathan Cameron
2026-05-04 9:48 ` [PATCH v4 08/17] iio: magnetometer: ak8975: avoid using temporary variable Joshua Crofts via B4 Relay
2026-05-04 9:48 ` [PATCH v4 09/17] iio: magnetometer: ak8975: drop duplicate NULL check Joshua Crofts via B4 Relay
2026-05-04 9:48 ` [PATCH v4 10/17] iio: magnetometer: ak8975: remove duplicate error message Joshua Crofts via B4 Relay
2026-05-04 9:48 ` [PATCH v4 11/17] iio: magnetometer: ak8975: reduce usage of magic lengths of the buffer Joshua Crofts via B4 Relay
2026-05-04 9:48 ` [PATCH v4 12/17] iio: magnetometer: ak8975: unify return code variable name Joshua Crofts via B4 Relay
2026-05-04 9:48 ` [PATCH v4 13/17] iio: magnetometer: ak8975: switch to using managed resources Joshua Crofts via B4 Relay
2026-05-04 11:13 ` Andy Shevchenko
2026-05-04 11:28 ` Joshua Crofts
2026-05-04 9:48 ` [PATCH v4 14/17] iio: magnetometer: ak8975: consistently use 'data' parameter Joshua Crofts via B4 Relay
2026-05-04 9:48 ` [PATCH v4 15/17] iio: magnetometer: ak8975: unify messages with help of dev_err_probe() Joshua Crofts via B4 Relay
2026-05-04 9:48 ` Joshua Crofts via B4 Relay [this message]
2026-05-04 9:48 ` [PATCH v4 17/17] iio: magnetometer: ak8975: make use of the macros from bits.h Joshua Crofts via B4 Relay
2026-05-04 11:01 ` [PATCH v4 00/17] iio: magnetometer: ak8975: modernize and cleanup driver Andy Shevchenko
2026-05-04 11:13 ` Joshua Crofts
2026-05-04 15:15 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260504-magnetometer-fixes-v4-16-a291c2a7c71a@gmail.com \
--to=devnull+joshua.crofts1.gmail.com@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=joshua.crofts1@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox