public inbox for linux-hwmon@vger.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Jean Delvare <jdelvare@suse.com>,
	linux-hwmon@vger.kernel.org, Peter Rosin <peda@axentia.se>,
	Chris Lesiak <chris.lesiak@licor.com>
Subject: Re: [PATCH 1/3 v2] hwmon: (ntc_thermistor): Move and refactor DT parsing
Date: Tue, 7 Dec 2021 09:33:01 -0800	[thread overview]
Message-ID: <20211207173301.GA658961@roeck-us.net> (raw)
In-Reply-To: <20211206020423.62402-1-linus.walleij@linaro.org>

On Mon, Dec 06, 2021 at 03:04:21AM +0100, Linus Walleij wrote:
> Move the parsing of the DT config right above probe().
> 
> Allocate the state container for the driver in probe()
> instead of inside the DT config parsing function: as a
> result return an int instead of a pointer.
> 
> Drop the check for !np: we can only probe from DT right
> now so no risk of ending up here.
> 
> Cc: Peter Rosin <peda@axentia.se>
> Cc: Chris Lesiak <chris.lesiak@licor.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

Applied.

Thanks,
Guenter

> ---
> ChangeLog v1->v2:
> - Instead of inlining the DT probing, keep the separate
>   function, but move out the state container allocation
>   and return an int.
> ---
>  drivers/hwmon/ntc_thermistor.c | 93 ++++++++++++++++------------------
>  1 file changed, 43 insertions(+), 50 deletions(-)
> 
> diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
> index ed638ebd0923..12435ef66530 100644
> --- a/drivers/hwmon/ntc_thermistor.c
> +++ b/drivers/hwmon/ntc_thermistor.c
> @@ -403,49 +403,6 @@ static const struct of_device_id ntc_match[] = {
>  };
>  MODULE_DEVICE_TABLE(of, ntc_match);
>  
> -static struct ntc_data *ntc_thermistor_parse_dt(struct device *dev)
> -{
> -	struct ntc_data *data;
> -	struct iio_channel *chan;
> -	enum iio_chan_type type;
> -	struct device_node *np = dev->of_node;
> -	int ret;
> -
> -	if (!np)
> -		return NULL;
> -
> -	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
> -	if (!data)
> -		return ERR_PTR(-ENOMEM);
> -
> -	chan = devm_iio_channel_get(dev, NULL);
> -	if (IS_ERR(chan))
> -		return ERR_CAST(chan);
> -
> -	ret = iio_get_channel_type(chan, &type);
> -	if (ret < 0)
> -		return ERR_PTR(ret);
> -
> -	if (type != IIO_VOLTAGE)
> -		return ERR_PTR(-EINVAL);
> -
> -	if (of_property_read_u32(np, "pullup-uv", &data->pullup_uv))
> -		return ERR_PTR(-ENODEV);
> -	if (of_property_read_u32(np, "pullup-ohm", &data->pullup_ohm))
> -		return ERR_PTR(-ENODEV);
> -	if (of_property_read_u32(np, "pulldown-ohm", &data->pulldown_ohm))
> -		return ERR_PTR(-ENODEV);
> -
> -	if (of_find_property(np, "connected-positive", NULL))
> -		data->connect = NTC_CONNECTED_POSITIVE;
> -	else /* status change should be possible if not always on. */
> -		data->connect = NTC_CONNECTED_GROUND;
> -
> -	data->chan = chan;
> -
> -	return data;
> -}
> -
>  static inline u64 div64_u64_safe(u64 dividend, u64 divisor)
>  {
>  	if (divisor == 0 && dividend == 0)
> @@ -638,6 +595,42 @@ static const struct hwmon_chip_info ntc_chip_info = {
>  	.info = ntc_info,
>  };
>  
> +static int ntc_thermistor_parse_dt(struct device *dev,
> +				   struct ntc_data *data)
> +{
> +	struct iio_channel *chan;
> +	enum iio_chan_type type;
> +	struct device_node *np = dev->of_node;
> +	int ret;
> +
> +	chan = devm_iio_channel_get(dev, NULL);
> +	if (IS_ERR(chan))
> +		return PTR_ERR(chan);
> +
> +	ret = iio_get_channel_type(chan, &type);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (type != IIO_VOLTAGE)
> +		return -EINVAL;
> +
> +	if (of_property_read_u32(np, "pullup-uv", &data->pullup_uv))
> +		return -ENODEV;
> +	if (of_property_read_u32(np, "pullup-ohm", &data->pullup_ohm))
> +		return -ENODEV;
> +	if (of_property_read_u32(np, "pulldown-ohm", &data->pulldown_ohm))
> +		return -ENODEV;
> +
> +	if (of_find_property(np, "connected-positive", NULL))
> +		data->connect = NTC_CONNECTED_POSITIVE;
> +	else /* status change should be possible if not always on. */
> +		data->connect = NTC_CONNECTED_GROUND;
> +
> +	data->chan = chan;
> +
> +	return 0;
> +}
> +
>  static int ntc_thermistor_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> @@ -646,15 +639,15 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
>  	const struct platform_device_id *pdev_id;
>  	struct device *hwmon_dev;
>  	struct ntc_data *data;
> +	int ret;
>  
> -	data = ntc_thermistor_parse_dt(dev);
> -	if (IS_ERR(data))
> -		return PTR_ERR(data);
> +	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
> +	if (!data)
> +		return -ENOMEM;
>  
> -	if (!data) {
> -		dev_err(dev, "No platform init data supplied.\n");
> -		return -ENODEV;
> -	}
> +	ret = ntc_thermistor_parse_dt(dev, data);
> +	if (ret)
> +		return ret;
>  
>  	if (data->pullup_uv == 0 ||
>  	    (data->pullup_ohm == 0 && data->connect ==

      parent reply	other threads:[~2021-12-07 17:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06  2:04 [PATCH 1/3 v2] hwmon: (ntc_thermistor): Move and refactor DT parsing Linus Walleij
2021-12-06  2:04 ` [PATCH 2/3 v2] hwmon: (ntc_thermistor): Switch to generic firmware props Linus Walleij
2021-12-07 17:33   ` Guenter Roeck
2021-12-06  2:04 ` [PATCH 3/3 v2] hwmon: (ntc_thermistor): Move DT matches to the driver block Linus Walleij
2021-12-07 17:33 ` Guenter Roeck [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=20211207173301.GA658961@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=chris.lesiak@licor.com \
    --cc=jdelvare@suse.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=peda@axentia.se \
    /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