lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240225120700.2a0da3f6@jic23-huawei>
Date: Sun, 25 Feb 2024 12:07:00 +0000
From: Jonathan Cameron <jic23@...nel.org>
To: Ondřej Jirman <megi@....cz>
Cc: linux-kernel@...r.kernel.org, Lars-Peter Clausen <lars@...afoo.de>, Rob
 Herring <robh+dt@...nel.org>, Krzysztof Kozlowski
 <krzysztof.kozlowski+dt@...aro.org>, Conor Dooley <conor+dt@...nel.org>,
 Andrey Skvortsov <andrej.skvortzov@...il.com>, Icenowy Zheng
 <icenowy@...c.io>, Dalton Durst <dalton@...orts.com>, Shoji Keita
 <awaittrot@...k.jp>, linux-iio@...r.kernel.org, devicetree@...r.kernel.org
Subject: Re: [PATCH v4 3/4] iio: magnetometer: add a driver for Voltafield
 AF8133J magnetometer

On Thu, 22 Feb 2024 02:13:37 +0100
Ondřej Jirman <megi@....cz> wrote:

> From: Icenowy Zheng <icenowy@...c.io>
> 
> AF8133J is a simple I2C-connected magnetometer, without interrupts.
> 
> Add a simple IIO driver for it.
> 
> Co-developed-by: Icenowy Zheng <icenowy@...c.io>
> Signed-off-by: Icenowy Zheng <icenowy@...c.io>
Check patch correct moaned that Icenowy is the author (from:)
so doesn't need a co-developed.

> Signed-off-by: Dalton Durst <dalton@...orts.com>
> Signed-off-by: Shoji Keita <awaittrot@...k.jp>
> Co-developed-by: Ondrej Jirman <megi@....cz>
> Signed-off-by: Ondrej Jirman <megi@....cz>
> Reviewed-by: Andrey Skvortsov <andrej.skvortzov@...il.com>
> Tested-by: Andrey Skvortsov <andrej.skvortzov@...il.com>

Hi.

A few really minor things noticed during a final review.
I'll tweak them whilst applying.  Diff is

diff --git a/drivers/iio/magnetometer/af8133j.c b/drivers/iio/magnetometer/af8133j.c
index c75d545e152b..40657a08ce37 100644
--- a/drivers/iio/magnetometer/af8133j.c
+++ b/drivers/iio/magnetometer/af8133j.c
@@ -40,6 +40,10 @@ static const char * const af8133j_supply_names[] = {
 struct af8133j_data {
        struct i2c_client *client;
        struct regmap *regmap;
+       /*
+        * Protect device internal state between starting a measurement
+        * and reading the result.
+        */
        struct mutex mutex;
        struct iio_mount_matrix orientation;
 
@@ -107,8 +111,8 @@ static int af8133j_product_check(struct af8133j_data *data)
        }
 
        if (val != AF8133J_REG_PCODE_VAL) {
-               dev_err(dev, "Invalid product code (0x%02x)\n", val);
-               return -EINVAL;
+               dev_warn(dev, "Invalid product code (0x%02x)\n", val);
+               return 0; /* Allow unknown ID so fallback compatibles work */
        }
 
        return 0;
@@ -237,8 +241,8 @@ static int af8133j_read_measurement(struct af8133j_data *data, __le16 buf[3])
 }
 
 static const int af8133j_scales[][2] = {
-       [0] = { 0, 366210 }, // 12 gauss
-       [1] = { 0, 671386 }, // 22 gauss
+       [0] = { 0, 366210 }, /* 12 gauss */
+       [1] = { 0, 671386 }, /* 22 gauss */
 };


> diff --git a/drivers/iio/magnetometer/af8133j.c b/drivers/iio/magnetometer/af8133j.c
> new file mode 100644
> index 000000000000..c75d545e152b
> --- /dev/null
> +++ b/drivers/iio/magnetometer/af8133j.c

> +
> +struct af8133j_data {
> +	struct i2c_client *client;
> +	struct regmap *regmap;
> +	struct mutex mutex;

I thought checkpatch still moaned that every lock should have documentation.
I guess not.  However it's still a nice to have.

Here it seems this is about protecting device state between triggering a
measurement and getting the reading.

> +	struct iio_mount_matrix orientation;
> +
> +	struct gpio_desc *reset_gpiod;
> +	struct regulator_bulk_data supplies[ARRAY_SIZE(af8133j_supply_names)];
> +
> +	u8 range;
> +};

> +
> +static int af8133j_product_check(struct af8133j_data *data)
> +{
> +	struct device *dev = &data->client->dev;
> +	unsigned int val;
> +	int ret;
> +
> +	ret = regmap_read(data->regmap, AF8133J_REG_PCODE, &val);
> +	if (ret) {
> +		dev_err(dev, "Error reading product code (%d)\n", ret);
> +		return ret;
> +	}
> +
> +	if (val != AF8133J_REG_PCODE_VAL) {
> +		dev_err(dev, "Invalid product code (0x%02x)\n", val);
> +		return -EINVAL;

This should be warn only and we should carry on regardless.  The reason
behind this is to support fallback compatible values in DT to potentially enable
a newer device to be supported on an older kernel.

Many IIO drivers do this wrong as my understanding on what counted on
'compatible' used to be different.  Long discussions on this with the DT
maintainers led me to accept that letting ID checks fail was fine, but
that a message was appropriate.   Often a fail here actually means no device.
We have some exceptions to this rule for devices where we know the same
FW ids are in use in the wild for devices supported by different Linux
drivers - but those are thankfully rare!

> +	}
> +
> +	return 0;
> +}
> +
}

> +static const int af8133j_scales[][2] = {
> +	[0] = { 0, 366210 }, // 12 gauss
> +	[1] = { 0, 671386 }, // 22 gauss
Trivial so I'll fix it up: IIO comments are /* */
not C++ style (with exception of the SPDX stuff that needs to be).
> +};




Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ