Linux IIO development
 help / color / mirror / Atom feed
From: Petre Rodan <petre.rodan@subdimension.ro>
To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Petre Rodan <petre.rodan@subdimension.ro>,
	Andreas Klinger <ak@it-klinger.de>,
	Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Angel Iglesias <ang.iglesiasg@gmail.com>,
	Matti Vaittinen <mazziesaccount@gmail.com>
Subject: [PATCH v3 06/10] iio: pressure: mprls0025pa remove defaults
Date: Fri, 29 Dec 2023 11:24:34 +0200	[thread overview]
Message-ID: <20231229092445.30180-7-petre.rodan@subdimension.ro> (raw)
In-Reply-To: <20231229092445.30180-1-petre.rodan@subdimension.ro>

This driver supports 32*3 combinations of fixed ranges and transfer
functions, plus custom ranges.

So statistically a user has more than 99% chance that the provided
default configuration will generate invalid pressure readings if the
bindings are not initialized and the driver is instantiated via sysfs.

The current patch removes this loophole making sure the driver loads
only if the firmware properties are present.

Co-developed-by: Andreas Klinger <ak@it-klinger.de>
Signed-off-by: Andreas Klinger <ak@it-klinger.de>
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
v2 -> v3 drop the use of dev_fwnode() entirely

 drivers/iio/pressure/mprls0025pa.c | 48 +++++++++++++-----------------
 1 file changed, 20 insertions(+), 28 deletions(-)

diff --git a/drivers/iio/pressure/mprls0025pa.c b/drivers/iio/pressure/mprls0025pa.c
index 233cc1dc38ad..e0a2a60c6245 100644
--- a/drivers/iio/pressure/mprls0025pa.c
+++ b/drivers/iio/pressure/mprls0025pa.c
@@ -353,34 +353,26 @@ static int mpr_probe(struct i2c_client *client)
 		return dev_err_probe(dev, ret,
 				"can't get and enable vdd supply\n");

-	if (dev_fwnode(dev)) {
-		ret = device_property_read_u32(dev, "honeywell,pmin-pascal",
-								&data->pmin);
-		if (ret)
-			return dev_err_probe(dev, ret,
-				"honeywell,pmin-pascal could not be read\n");
-		ret = device_property_read_u32(dev, "honeywell,pmax-pascal",
-								&data->pmax);
-		if (ret)
-			return dev_err_probe(dev, ret,
-				"honeywell,pmax-pascal could not be read\n");
-		ret = device_property_read_u32(dev,
-				"honeywell,transfer-function", &func);
-		if (ret)
-			return dev_err_probe(dev, ret,
-				"honeywell,transfer-function could not be read\n");
-		data->function = func - 1;
-		if (data->function > MPR_FUNCTION_C)
-			return dev_err_probe(dev, -EINVAL,
-				"honeywell,transfer-function %d invalid\n",
-								data->function);
-	} else {
-		/* when loaded as i2c device we need to use default values */
-		dev_notice(dev, "firmware node not found; using defaults\n");
-		data->pmin = 0;
-		data->pmax = 172369; /* 25 psi */
-		data->function = MPR_FUNCTION_A;
-	}
+	ret = device_property_read_u32(dev, "honeywell,pmin-pascal",
+				       &data->pmin);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				   "honeywell,pmin-pascal could not be read\n");
+	ret = device_property_read_u32(dev, "honeywell,pmax-pascal",
+				       &data->pmax);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				   "honeywell,pmax-pascal could not be read\n");
+	ret = device_property_read_u32(dev,
+				       "honeywell,transfer-function", &func);
+	if (ret)
+		return dev_err_probe(dev, ret,
+			     "honeywell,transfer-function could not be read\n");
+	data->function = func - 1;
+	if (data->function > MPR_FUNCTION_C)
+		return dev_err_probe(dev, -EINVAL,
+				     "honeywell,transfer-function %d invalid\n",
+				     data->function);

 	data->outmin = mpr_func_spec[data->function].output_min;
 	data->outmax = mpr_func_spec[data->function].output_max;
--
2.41.0


  parent reply	other threads:[~2023-12-29  9:25 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-29  9:24 [PATCH v3 00/10] changes to mprls0025pa Petre Rodan
2023-12-29  9:24 ` [PATCH v3 01/10] dt-bindings: iio: pressure: honeywell,mprls0025pa.yaml improvements Petre Rodan
2023-12-29  9:24 ` [PATCH v3 02/10] dt-bindings: iio: pressure: honeywell,mprls0025pa.yaml add pressure-triplet Petre Rodan
2024-01-04  8:26   ` Krzysztof Kozlowski
2023-12-29  9:24 ` [PATCH v3 03/10] dt-bindings: iio: pressure: honeywell,mprls0025pa.yaml add spi bus Petre Rodan
2024-01-04  8:26   ` Krzysztof Kozlowski
2023-12-29  9:24 ` [PATCH v3 04/10] iio: pressure: mprls0025pa fix off-by-one enum Petre Rodan
2023-12-29  9:24 ` [PATCH v3 05/10] iio: pressure: mprls0025pa improve driver error resilience Petre Rodan
2023-12-29  9:24 ` Petre Rodan [this message]
2023-12-29  9:24 ` [PATCH v3 07/10] iio: pressure: mprls0025pa whitespace cleanup Petre Rodan
2024-01-06 15:24   ` Andy Shevchenko
2023-12-29  9:24 ` [PATCH v3 08/10] iio: pressure: mprls0025pa refactor Petre Rodan
2023-12-29  9:24 ` [PATCH v3 09/10] iio: pressure: mprls0025pa add triplet property Petre Rodan
2023-12-29  9:24 ` [PATCH v3 10/10] iio: pressure: mprls0025pa add SPI driver Petre Rodan
2024-01-06 15:30   ` Andy Shevchenko
2024-01-06 16:02     ` Petre Rodan
2024-01-06 16:07       ` Andy Shevchenko
2024-01-07 16:32         ` 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=20231229092445.30180-7-petre.rodan@subdimension.ro \
    --to=petre.rodan@subdimension.ro \
    --cc=ak@it-klinger.de \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=ang.iglesiasg@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mazziesaccount@gmail.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