The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Nuno Sá" <noname.nuno@gmail.com>
To: joshua.crofts1@gmail.com, "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,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: Re: [PATCH 6/8] iio: magnetometer: ak8975: use temporary variable for struct device
Date: Sat, 09 May 2026 10:06:21 +0100	[thread overview]
Message-ID: <a73cd9f3c061b390a2ef661491f9b251db64d6c1.camel@gmail.com> (raw)
In-Reply-To: <20260507-magnetometer-fixes-post-pickup-v1-6-37827ca68fb3@gmail.com>

On Thu, 2026-05-07 at 16:35 +0200, Joshua Crofts via B4 Relay wrote:
> 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>
> ---

Reviewed-by: Nuno Sá <nuno.sa@analog.com>

>  drivers/iio/magnetometer/ak8975.c | 63 +++++++++++++++++++--------------------
>  1 file changed, 31 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
> index
> 394f930b862e82fd41c02d81bc6fdb3cfc8b729f..fde37cdcdd053bde1630c2f73ab717f9d008e2fa
> 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;
>  		}
>  	}
> @@ -736,10 +735,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);
>  
> @@ -757,20 +757,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);
> @@ -779,8 +779,8 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int
> index, int *val)
>  
>  exit:
>  	mutex_unlock(&data->lock);
> -	pm_runtime_put_autosuspend(&data->client->dev);
> -	dev_err(&client->dev, "Error in reading axis\n");
> +	pm_runtime_put_autosuspend(dev);
> +	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;
>  	}
>  

  reply	other threads:[~2026-05-09  9:05 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-07 14:35 [PATCH 0/8] iio: magnetometer: ak8975: driver cleanup Joshua Crofts via B4 Relay
2026-05-07 14:35 ` [PATCH 1/8] iio: magnetometer: ak8975: modernize polling loops with iopoll() macros Joshua Crofts via B4 Relay
2026-05-09  8:48   ` Nuno Sá
2026-05-07 14:35 ` [PATCH 2/8] iio: magnetometer: ak8975: check if gpiod read was successful Joshua Crofts via B4 Relay
2026-05-09  8:49   ` Nuno Sá
2026-05-07 14:35 ` [PATCH 3/8] iio: magnetometer: ak8975: switch to using managed resources Joshua Crofts via B4 Relay
2026-05-08  9:58   ` Andy Shevchenko
2026-05-08 13:51     ` Joshua Crofts
2026-05-09  6:52       ` Andy Shevchenko
2026-05-09  7:47         ` Joshua Crofts
2026-05-09  7:54           ` Andy Shevchenko
2026-05-11 18:17             ` Jonathan Cameron
2026-05-09  9:03   ` Nuno Sá
2026-05-09 13:32     ` Joshua Crofts
2026-05-09 17:15     ` Andy Shevchenko
2026-05-11  7:04       ` Joshua Crofts
2026-05-11 13:12         ` Jonathan Cameron
2026-05-07 14:35 ` [PATCH 4/8] iio: magnetometer: ak8975: consistently use 'data' parameter Joshua Crofts via B4 Relay
2026-05-09  9:04   ` Nuno Sá
2026-05-07 14:35 ` [PATCH 5/8] iio: magnetometer: ak8975: unify messages with help of dev_err_probe() Joshua Crofts via B4 Relay
2026-05-09  9:05   ` Nuno Sá
2026-05-07 14:35 ` [PATCH 6/8] iio: magnetometer: ak8975: use temporary variable for struct device Joshua Crofts via B4 Relay
2026-05-09  9:06   ` Nuno Sá [this message]
2026-05-07 14:35 ` [PATCH 7/8] iio: magnetometer: ak8975: add scan mask index enum Joshua Crofts via B4 Relay
2026-05-09  9:07   ` Nuno Sá
2026-05-07 14:35 ` [PATCH 8/8] iio: magnetometer: ak8975: make use of the macros from bits.h Joshua Crofts via B4 Relay
2026-05-09  9:09   ` Nuno Sá
2026-05-09  9:15     ` Joshua Crofts
2026-05-09 17:16     ` Andy Shevchenko
2026-05-08  7:39 ` [PATCH 0/8] iio: magnetometer: ak8975: driver cleanup Andy Shevchenko
2026-05-08  8:59   ` Joshua Crofts
2026-05-08  9:19     ` Andy Shevchenko
2026-05-08 13:34       ` Jonathan Cameron
2026-05-08 13:45         ` Joshua Crofts

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=a73cd9f3c061b390a2ef661491f9b251db64d6c1.camel@gmail.com \
    --to=noname.nuno@gmail.com \
    --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