LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Jonathan Cameron <jic23@kernel.org>, Andreas Klinger <ak@it-klinger.de>
Cc: devicetree@vger.kernel.org, linux-iio@vger.kernel.org,
	Rob Herring <robh+dt@kernel.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Jiri Kosina <trivial@kernel.org>,
	Chris Packham <chris.packham@alliedtelesis.co.nz>,
	Slawomir Stepien <sst@poczta.fm>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Vadim Pasternak <vadimp@nvidia.com>,
	Alexandru Ardelean <alexandru.ardelean@analog.com>,
	linux-kernel@vger.kernel.org,
	Lars-Peter Clausen <lars@metafoo.de>,
	Tomasz Duszynski <tomasz.duszynski@octakon.com>
Subject: Re: [PATCH 2/2] iio: chemical: Add driver support for sgp40
Date: Sat, 31 Jul 2021 11:06:25 -0700	[thread overview]
Message-ID: <42e31edc-445c-06ac-dd3a-80db1b439996@roeck-us.net> (raw)
In-Reply-To: <20210731173928.08d6812f@jic23-huawei>

On 7/31/21 9:39 AM, Jonathan Cameron wrote:
> On Tue, 27 Jul 2021 18:35:19 +0200
> Andreas Klinger <ak@it-klinger.de> wrote:
> 
>> sgp40 is a gas sensor used for measuring the air quality.
>>
>> This driver is reading the raw resistance value which can be passed to
>> a userspace algorithm for further calculation.
>>
>> The raw value is also used to calculate an estimated absolute voc index
>> in the range from 0 to 500. For this purpose the raw_mean value of the
>> resistance for which the index value is 250 might be set up as a
>> calibration step.
>>
>> Compensation of relative humidity and temperature is supported and can
>> be used by writing to device attributes of the driver.
>>
>> There is a predecesor sensor type (sgp30) already existing. This driver
>> module was not extended because the new sensor is quite different in its
>> i2c telegrams.
>>
>> Signed-off-by: Andreas Klinger <ak@it-klinger.de>
> 
> Hi Andreas,
> 
> Non standard ABI in here, so we are missing documentation in Documentation/ABI/testing/sysfs-bus-iio-*
> 
> Otherwise a few suggestions inline.
> 
> Thanks,
> 
> Jonathan
> 
> 
>> ---
[ ... ]

>> +static int sgp40_read_raw(struct iio_dev *indio_dev,
>> +			struct iio_chan_spec const *chan, int *val,
>> +			int *val2, long mask)
>> +{
>> +	struct sgp40_data *data = iio_priv(indio_dev);
>> +	int ret;
>> +	u16 raw;
>> +	int voc;
>> +
>> +	switch (mask) {
>> +	case IIO_CHAN_INFO_RAW:
>> +		mutex_lock(&data->lock);
>> +		ret = sgp40_measure_raw(data, &raw);
>> +		if (ret) {
>> +			mutex_unlock(&data->lock);
>> +			return ret;
>> +		}
>> +		*val = raw;
>> +		ret = IIO_VAL_INT;
>> +		mutex_unlock(&data->lock);
>> +		break;
>> +	case IIO_CHAN_INFO_PROCESSED:
>> +		mutex_lock(&data->lock);
>> +		ret = sgp40_measure_raw(data, &raw);
>> +		if (ret) {
>> +			mutex_unlock(&data->lock);
>> +			return ret;
>> +		}
>> +		ret = sgp40_calc_voc(data, raw, &voc);
>> +		if (ret) {
>> +			mutex_unlock(&data->lock);
>> +			return ret;
>> +		}
>> +		*val = voc;
>> +		ret = IIO_VAL_INT;
>> +		mutex_unlock(&data->lock);
> 
> You are holding the lock longer than needed - it would be good
> to reduce this, hopefully removing the need for unlocking separately
> in each of the error paths.
> 
>> +		break;
>> +	default:
>> +		return -EINVAL;
>> +	}
>> +
>> +	return ret;
> 
> Drop this as you can't get here.
> 

Are you sure ? I see several "break;" above.

Guenter

  reply	other threads:[~2021-07-31 18:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-27 16:35 Andreas Klinger
2021-07-31 16:39 ` Jonathan Cameron
2021-07-31 18:06   ` Guenter Roeck [this message]
2021-08-01 17:01     ` 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=42e31edc-445c-06ac-dd3a-80db1b439996@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=ak@it-klinger.de \
    --cc=alexandre.belloni@bootlin.com \
    --cc=alexandru.ardelean@analog.com \
    --cc=chris.packham@alliedtelesis.co.nz \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=krzk@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=sst@poczta.fm \
    --cc=tomasz.duszynski@octakon.com \
    --cc=trivial@kernel.org \
    --cc=vadimp@nvidia.com \
    --subject='Re: [PATCH 2/2] iio: chemical: Add driver support for sgp40' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).