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: <9df82b13-7594-a8f0-f27e-87bce5a38b74@sberdevices.ru>
Date:   Mon, 29 May 2023 01:31:40 +0300
From:   George Stark <gnstark@...rdevices.ru>
To:     Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
CC:     "jic23@...nel.org" <jic23@...nel.org>,
        "lars@...afoo.de" <lars@...afoo.de>,
        "neil.armstrong@...aro.org" <neil.armstrong@...aro.org>,
        "khilman@...libre.com" <khilman@...libre.com>,
        "jbrunet@...libre.com" <jbrunet@...libre.com>,
        "martin.blumenstingl@...glemail.com" 
        <martin.blumenstingl@...glemail.com>,
        "nuno.sa@...log.com" <nuno.sa@...log.com>,
        "linux-iio@...r.kernel.org" <linux-iio@...r.kernel.org>,
        "linux-arm-kernel@...ts.infradead.org" 
        <linux-arm-kernel@...ts.infradead.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "linux-amlogic@...ts.infradead.org" 
        <linux-amlogic@...ts.infradead.org>, kernel <kernel@...rdevices.ru>
Subject: Re: [PATCH v2] meson saradc: add iio device attrib to switch channel
 7 mux

On 5/28/23 13:46, Andy Shevchenko wrote:

Hello Andy
> On Sun, May 28, 2023 at 12:48:54AM +0300, George Stark wrote:
>> Patch adds two sysfs nodes: chan7_mux to set mux state
>> and chan7_mux_available to show available mux states.
>> Mux can be used to debug and calibrate adc by
>> switching and measuring well-known inputs like GND, Vdd etc.
> Thank you for an update, my comments below.
>
> ...
>
>> ---
> Missing changelog, what has been done in v2, how it's different to v1.
Ok I'll keep it on mind
>
>>   drivers/iio/adc/meson_saradc.c | 65 ++++++++++++++++++++++++++++++++++
>>   1 file changed, 65 insertions(+)
> ...
>
>> +static const char * const chan7_vol[] = {
>> +	"gnd",
>> +	"vdd/4",
>> +	"vdd/2",
>> +	"vdd*3/4",
>> +	"vdd",
>> +	"ch7_input",
>> +};
>> +
>> +static ssize_t chan7_mux_show(struct device *dev, struct device_attribute *attr,
>> +			      char *buf)
>> +{
>> +	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>> +	struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
>> +	unsigned int index = priv->chan7_mux_sel;
>> +
>> +	if (index >= ARRAY_SIZE(chan7_vol))
>> +		index = ARRAY_SIZE(chan7_vol) - 1;
> I think this is incorrect and prone to error in the future in case this array
> will be extended. What I would expect is to return something like "unknown".

I agree this part is unclean. Actually the register's last 3 (out of 8) 
possible values
are stand for the same mux input "ch7_input". So theoretically we can 
read from register
a value out of array bounds. There should be a comment at least.

About the question of naming mux inputs from the other letter (vdd/2 vs 
0.5Vdd etc).
While I fully agree with you that point is better than slash but mixing 
letter cases... should we?

e.g. this is how iio_info output looks like now:
...
             voltage7:  (input)
             3 channel-specific attributes found:
                 attr  0: mean_raw value: 0
                 attr  1: raw value: 1
                 attr  2: scale value: 0.439453125
         4 device-specific attributes found:
                 attr  0: chan7_mux value: gnd
                 attr  1: chan7_mux_available value: gnd vdd/4 vdd/2 
vdd*3/4 vdd ch7_input
                 attr  2: current_timestamp_clock value: realtime

                 attr  3: waiting_for_supplier value: 0

or naming with Jonathan's approach
/sys/devices/platform/soc/fe000000.bus/fe002c00.adc/iio:device0/in_voltage_0.5vdd_raw

Best regards
George

>> +	return sysfs_emit(buf, "%s\n", chan7_vol[index]);
>> +}
>> +
>> +static ssize_t chan7_mux_store(struct device *dev,
>> +			       struct device_attribute *attr,
>> +			       const char *buf, size_t count)
>> +{
>> +	struct iio_dev *indio_dev = dev_to_iio_dev(dev);
>> +	int i;
>> +
>> +	i = sysfs_match_string(chan7_vol, buf);
>> +	if (i < 0)
>> +		return -EINVAL;
> Do not shadow the error code if it's not justified.
>
> 		return i;
>
>> +	meson_sar_adc_set_chan7_mux(indio_dev, i);
>> +	return count;
>> +}
>> +
> Redundant blank line.
>
>> +static IIO_DEVICE_ATTR_RW(chan7_mux, -1);
>> +
>> +static ssize_t chan7_mux_available_show(struct device *dev, struct device_attribute *attr,
>> +			      char *buf)
>> +{
>> +	int i, len = 0;
>> +
>> +	for (i = 0; i < ARRAY_SIZE(chan7_vol); i++)
>> +		len += sysfs_emit_at(buf, len, "%s ", chan7_vol[i]);
>> +
>> +	return len;
>> +}
>> +
> Ditto.
>
>> +static IIO_DEVICE_ATTR_RO(chan7_mux_available, -1);


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ