Linux Documentation
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Daniel Matyas <daniel.matyas@analog.com>
Cc: no To-header on input <;, Jean Delvare <jdelvare@suse.com>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH v4 1/7] hwmon: max31827: Make code cleaner
Date: Wed, 25 Oct 2023 14:43:19 -0700	[thread overview]
Message-ID: <5376244a-c6ec-466f-a42d-97d2d52af2cb@roeck-us.net> (raw)
In-Reply-To: <20230919093456.10592-1-daniel.matyas@analog.com>

On Tue, Sep 19, 2023 at 12:34:49PM +0300, Daniel Matyas wrote:
> Used enums and while loops to replace switch for selecting and getting
> update interval from conversion rate bits.
> 
> Divided the write_alarm_val function into 2 functions. The new function
> is more generic: it can be used not only for alarm writes, but for any
> kind of writes which require the device to be in shutdown mode.
> 
> Signed-off-by: Daniel Matyas <daniel.matyas@analog.com>
> ---

Applied, with one change.

> @@ -333,39 +330,27 @@ static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
>  			if (!st->enable)
>  				return -EINVAL;
>  
> -			switch (val) {
> -			case 125:
> -				val = MAX31827_CNV_8_HZ;
> -				break;
> -			case 250:
> -				val = MAX31827_CNV_4_HZ;
> -				break;
> -			case 1000:
> -				val = MAX31827_CNV_1_HZ;
> -				break;
> -			case 4000:
> -				val = MAX31827_CNV_1_DIV_4_HZ;
> -				break;
> -			case 16000:
> -				val = MAX31827_CNV_1_DIV_16_HZ;
> -				break;
> -			case 32000:
> -				val = MAX31827_CNV_1_DIV_32_HZ;
> -				break;
> -			case 64000:
> -				val = MAX31827_CNV_1_DIV_64_HZ;
> -				break;
> -			default:
> -				return -EINVAL;
> -			}
> +			/*
> +			 * Convert the desired conversion rate into register
> +			 * bits. res is already initialized with 1.
> +			 *
> +			 * This was inspired by lm73 driver.
> +			 */
> +			while (res < ARRAY_SIZE(max31827_conversions) &&
> +			       val < max31827_conversions[res])
> +				res++;
> +
> +			if (res == ARRAY_SIZE(max31827_conversions) ||
> +			    val != max31827_conversions[res])
> +				return -EOPNOTSUPP;

Changing the return value from -EINVAL to -EOPNOTSUPP was inappropriate
here. This needs to return -EINVAL because it is the result of an
invalid value provided by userspace, not the result of an unsupported
operation.

Guenter

      parent reply	other threads:[~2023-10-25 21:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-19  9:34 [PATCH v4 1/7] hwmon: max31827: Make code cleaner Daniel Matyas
2023-09-19  9:34 ` [PATCH v4 2/7] hwmon: max31827: Modify conversion wait time Daniel Matyas
2023-10-25 21:44   ` Guenter Roeck
2023-09-19  9:34 ` [PATCH v4 3/7] dt-bindings: hwmon: Add possible new properties to max31827 bindings Daniel Matyas
2023-09-19 11:00   ` Conor Dooley
2023-10-25 21:44   ` Guenter Roeck
2023-09-19  9:34 ` [PATCH v4 4/7] hwmon: max31827: Handle new properties from the devicetree Daniel Matyas
2023-10-25 22:01   ` Guenter Roeck
2023-10-26  0:45   ` Guenter Roeck
2023-09-19  9:34 ` [PATCH v4 5/7] hwmon: max31827: Add support for max31828 and max31829 Daniel Matyas
2023-09-19  9:34 ` [PATCH v4 6/7] hwmon: max31827: Update bits with shutdown_write() Daniel Matyas
2023-09-19  9:34 ` [PATCH v4 7/7] hwmon: max31827: Add custom attribute for resolution Daniel Matyas
2023-10-25 21:43 ` 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=5376244a-c6ec-466f-a42d-97d2d52af2cb@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=daniel.matyas@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