From: Jonathan Cameron <jic23@kernel.org>
To: Achim Gratz <Achim.Gratz@Stromeko.DE>
Cc: linux-iio@vger.kernel.org,
"David Lechner" <dlechner@baylibre.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Nuno Sá" <nuno.sa@analog.com>
Subject: Re: [RFC PATCH v3 5/9] iio: pressure: bmp280: remove code duplication
Date: Sat, 4 Oct 2025 16:12:04 +0100 [thread overview]
Message-ID: <20251004161204.0d394c6e@jic23-huawei> (raw)
In-Reply-To: <20250928172637.37138-7-Achim.Gratz@Stromeko.DE>
On Sun, 28 Sep 2025 19:26:33 +0200
Achim Gratz <Achim.Gratz@Stromeko.DE> wrote:
> Eliminate code duplication from bmp280_read_raw_impl() by handling raw
> and processed channel reads together. The decision about which data format
> to output is pre-computed in bool info_raw so that the switch
> statement needs no fallthrough macro.
>
> Signed-off-by: Achim Gratz <Achim.Gratz@Stromeko.DE>
Hi Achim
One minor thing inline. If nothing else comes up I might tweak this whilst
applying (though it's so minor I might not bother!)
J
> ---
> drivers/iio/pressure/bmp280-core.c | 46 +++++++++++-------------------
> 1 file changed, 16 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
> index 2dd36493acb4..4f5c4bd89067 100644
> --- a/drivers/iio/pressure/bmp280-core.c
> +++ b/drivers/iio/pressure/bmp280-core.c
> @@ -619,10 +619,12 @@ static int bmp280_read_raw_impl(struct iio_dev *indio_dev,
> struct bmp280_data *data = iio_priv(indio_dev);
> int chan_value;
> int ret;
> + bool info_raw = mask & IIO_CHAN_INFO_RAW;
>
> guard(mutex)(&data->lock);
>
> switch (mask) {
> + case IIO_CHAN_INFO_RAW:
> case IIO_CHAN_INFO_PROCESSED:
> ret = data->chip_info->conv(data);
> if (ret)
> @@ -634,6 +636,11 @@ static int bmp280_read_raw_impl(struct iio_dev *indio_dev,
> if (ret)
> return ret;
>
> + if (info_raw) {
> + *val = chan_value;
> + return IIO_VAL_INT;
> + }
> +
> *val = data->chip_info->humid_coeffs[0] * chan_value;
> *val2 = data->chip_info->humid_coeffs[1];
> return data->chip_info->humid_coeffs_type;
> @@ -642,6 +649,10 @@ static int bmp280_read_raw_impl(struct iio_dev *indio_dev,
> if (ret)
> return ret;
>
> + if (info_raw) {
> + *val = chan_value;
> + return IIO_VAL_INT;
> + }
Should you be respinning for any reason. Blank line here would be consistent with
other cases above and below.
> *val = data->chip_info->press_coeffs[0] * chan_value;
> *val2 = data->chip_info->press_coeffs[1];
> return data->chip_info->press_coeffs_type;
> @@ -650,42 +661,17 @@ static int bmp280_read_raw_impl(struct iio_dev *indio_dev,
> if (ret)
> return ret;
>
> + if (info_raw) {
> + *val = chan_value;
> + return IIO_VAL_INT;
> + }
> +
> *val = data->chip_info->temp_coeffs[0] * chan_value;
> *val2 = data->chip_info->temp_coeffs[1];
> return data->chip_info->temp_coeffs_type;
> default:
> return -EINVAL;
> }
> - case IIO_CHAN_INFO_RAW:
> - ret = data->chip_info->conv(data);
> - if (ret)
> - return ret;
> -
> - switch (chan->type) {
> - case IIO_HUMIDITYRELATIVE:
> - ret = data->chip_info->read_humid(data, &chan_value);
> - if (ret)
> - return ret;
> -
> - *val = chan_value;
> - return IIO_VAL_INT;
> - case IIO_PRESSURE:
> - ret = data->chip_info->read_press(data, &chan_value);
> - if (ret)
> - return ret;
> -
> - *val = chan_value;
> - return IIO_VAL_INT;
> - case IIO_TEMP:
> - ret = data->chip_info->read_temp(data, &chan_value);
> - if (ret)
> - return ret;
> -
> - *val = chan_value;
> - return IIO_VAL_INT;
> - default:
> - return -EINVAL;
> - }
> case IIO_CHAN_INFO_SCALE:
> switch (chan->type) {
> case IIO_HUMIDITYRELATIVE:
next prev parent reply other threads:[~2025-10-04 15:12 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-28 17:26 [RFC PATCH v3 0/9] Fixes and enhancements for the bmp280 driver Achim Gratz
2025-09-28 17:26 ` [RFC PATCH v3 1/9] iio: pressure: bmp280: correct meas_time_us calculation Achim Gratz
2025-10-04 15:21 ` Jonathan Cameron
2025-09-28 17:26 ` [RFC PATCH v3 1/1] iio: pressure: bmp280: test longer autosuspend (WIP) Achim Gratz
2025-09-28 19:10 ` ASSI
2025-09-28 17:26 ` [RFC PATCH v3 2/9] iio: pressure: bmp280: implement adaptive wait for BMx280 devices Achim Gratz
2025-09-28 17:26 ` [RFC PATCH v3 3/9] iio: pressure: bmp280: implement adaptive wait for BMP380 devices Achim Gratz
2025-09-28 17:26 ` [RFC PATCH v3 4/9] iio: pressure: bmp280: rename wait_conv() to conv(), factor out measurement time calculation Achim Gratz
2025-09-28 17:26 ` [RFC PATCH v3 5/9] iio: pressure: bmp280: remove code duplication Achim Gratz
2025-10-04 15:12 ` Jonathan Cameron [this message]
2025-09-28 17:26 ` [RFC PATCH v3 6/9] iio: pressure: bmp280: enable filter settings for BMx280 Achim Gratz
2025-10-04 15:21 ` Jonathan Cameron
2025-09-28 17:26 ` [RFC PATCH v3 7/9] iio: pressure: bmp280: implement sampling_frequency " Achim Gratz
2025-10-04 15:32 ` Jonathan Cameron
2025-09-28 17:26 ` [RFC PATCH v3 8/9] iio: pressure: bmp280: implement sampling_frequency calculation " Achim Gratz
2025-10-04 15:37 ` Jonathan Cameron
2025-09-28 17:26 ` [RFC PATCH v3 9/9] iio: pressure: bmp280: test longer autosuspend (WIP) Achim Gratz
2025-10-04 15:07 ` [RFC PATCH v3 0/9] Fixes and enhancements for the bmp280 driver Jonathan Cameron
2025-10-04 16:59 ` ASSI
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=20251004161204.0d394c6e@jic23-huawei \
--to=jic23@kernel.org \
--cc=Achim.Gratz@Stromeko.DE \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=nuno.sa@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