LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: "Théo Borém Fabris" <theobf@usp.br>
Cc: lars@metafoo.de, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org, Marek Vasut <marex@denx.de>,
	Marek Vasut <marek.vasut@gmail.com>
Subject: Re: [PATCH] iio: pressure: hp03: update device probe to register with devm functions
Date: Sun, 8 Aug 2021 17:40:56 +0100	[thread overview]
Message-ID: <20210808174056.63158f33@jic23-huawei> (raw)
In-Reply-To: <20210808122335.4895-1-theobf@usp.br>

On Sun,  8 Aug 2021 09:23:36 -0300
Théo Borém Fabris <theobf@usp.br> wrote:

> Update device probe to register resources with device-managed functions.
> Further, get rid of device-specific remove callback which is no longer
> needed.
> 
> Signed-off-by: Théo Borém Fabris <theobf@usp.br>

+Cc Marek on a couple of addresses as not sure which currently work.

One tiny cleanup inline, otherwise looks good to me.

> ---
> Could the dev_err() messages be improved? In particular, I don't know if
> it is important to express the usage of the device-managed functions.

I'd leave them as is.  Chance of a devm causing a failure that wouldn't
otherwise happen is nearly 0 as it only requires a tiny allocation extra.

> 
>  drivers/iio/pressure/hp03.c | 35 +++++++----------------------------
>  1 file changed, 7 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/iio/pressure/hp03.c b/drivers/iio/pressure/hp03.c
> index e40b1d7dc12..78ea95d9f99 100644
> --- a/drivers/iio/pressure/hp03.c
> +++ b/drivers/iio/pressure/hp03.c
> @@ -242,47 +242,27 @@ static int hp03_probe(struct i2c_client *client,
>  	 * which has it's dedicated I2C address and contains
>  	 * the calibration constants for the sensor.
>  	 */
> -	priv->eeprom_client = i2c_new_dummy_device(client->adapter, HP03_EEPROM_ADDR);
> +	priv->eeprom_client = devm_i2c_new_dummy_device(dev, client->adapter,
> +							HP03_EEPROM_ADDR);
>  	if (IS_ERR(priv->eeprom_client)) {
>  		dev_err(dev, "New EEPROM I2C device failed\n");
>  		return PTR_ERR(priv->eeprom_client);
>  	}
>  
> -	priv->eeprom_regmap = regmap_init_i2c(priv->eeprom_client,
> -					      &hp03_regmap_config);
> +	priv->eeprom_regmap = devm_regmap_init_i2c(priv->eeprom_client,
> +						   &hp03_regmap_config);
>  	if (IS_ERR(priv->eeprom_regmap)) {
>  		dev_err(dev, "Failed to allocate EEPROM regmap\n");
>  		ret = PTR_ERR(priv->eeprom_regmap);
> -		goto err_cleanup_eeprom_client;
> +		return ret;

return PTR_ERR(priv->eeprom_regmap);

>  	}
>  
> -	ret = iio_device_register(indio_dev);
> +	ret = devm_iio_device_register(dev, indio_dev);
>  	if (ret) {
>  		dev_err(dev, "Failed to register IIO device\n");
> -		goto err_cleanup_eeprom_regmap;
> +		return ret;
>  	}
>  
> -	i2c_set_clientdata(client, indio_dev);
> -
> -	return 0;
> -
> -err_cleanup_eeprom_regmap:
> -	regmap_exit(priv->eeprom_regmap);
> -
> -err_cleanup_eeprom_client:
> -	i2c_unregister_device(priv->eeprom_client);
> -	return ret;
> -}
> -
> -static int hp03_remove(struct i2c_client *client)
> -{
> -	struct iio_dev *indio_dev = i2c_get_clientdata(client);
> -	struct hp03_priv *priv = iio_priv(indio_dev);
> -
> -	iio_device_unregister(indio_dev);
> -	regmap_exit(priv->eeprom_regmap);
> -	i2c_unregister_device(priv->eeprom_client);
> -
>  	return 0;
>  }
>  
> @@ -304,7 +284,6 @@ static struct i2c_driver hp03_driver = {
>  		.of_match_table = hp03_of_match,
>  	},
>  	.probe		= hp03_probe,
> -	.remove		= hp03_remove,
>  	.id_table	= hp03_id,
>  };
>  module_i2c_driver(hp03_driver);


      reply	other threads:[~2021-08-08 16:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-08 12:23 Théo Borém Fabris
2021-08-08 16:40 ` Jonathan Cameron [this message]

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=20210808174056.63158f33@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marek.vasut@gmail.com \
    --cc=marex@denx.de \
    --cc=theobf@usp.br \
    --subject='Re: [PATCH] iio: pressure: hp03: update device probe to register with devm functions' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).