From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Joshua Crofts <joshua.crofts1@gmail.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] iio: light: opt3001: split opt3001_get_processed() logic
Date: Sun, 12 Jul 2026 16:58:55 +0300 [thread overview]
Message-ID: <alOdn0m3fbznqqDm@ashevche-desk.local> (raw)
In-Reply-To: <20260712-opt3001-unwind-cleanup-v3-1-5fa336876b08@gmail.com>
On Sun, Jul 12, 2026 at 12:32:49PM +0200, Joshua Crofts wrote:
> Split the logic inside the opt3001_get_processed() function, as the
> current flow is hard to read, mixing IRQ and non-IRQ code blocks.
>
> Separate the IRQ code path into its own function, same for the
> non-IRQ path.
...
> static int opt3001_get_processed(struct opt3001 *opt, int *val, int *val2)
> if (ret < 0) {
> dev_err(dev, "failed to write register %02x\n",
> OPT3001_CONFIGURATION);
> + return ret;
> + }
> +
> + return 0;
Now it can be simply
if (ret < 0)
dev_err(dev, "failed to write register %02x\n",
OPT3001_CONFIGURATION);
return ret;
...
> + ret = wait_event_timeout(opt->result_ready_queue,
> + opt->result_ready,
> + msecs_to_jiffies(OPT3001_RESULT_READY_LONG));
> + if (ret == 0)
> + ret = -ETIMEDOUT;
ret is int and for holding an error code, with the above ret is rewritten
with positive number and might lead to subtle issues. The recommended way
to handle is
if (wait_event_timeout(opt->result_ready_queue, opt->result_ready,
msecs_to_jiffies(OPT3001_RESULT_READY_LONG)))
ret = 0;
else
ret = -ETIMEDOUT;
or something like that.
...
> + /*
> + * Disable the end-of-conversion interrupt mechanism by restoring the
> + * low-level limit value (clearing OPT3001_LOW_LIMIT_EOC_ENABLE). Note
> + * that selectively clearing those enable bits would affect the actual
> + * limit value due to bit-overlap and therefore can't be done.
> + */
> + value = (opt->low_thresh_exp << 12) | opt->low_thresh_mantissa;
> + ret = i2c_smbus_write_word_swapped(client, OPT3001_LOW_LIMIT, value);
> + if (ret < 0) {
> + dev_err(dev, "failed to write register %02x\n",
> + OPT3001_LOW_LIMIT);
> + return ret;
> }
>
> + return 0;
Also can be simply
return ret;
in both branches.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-07-12 13:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-12 10:32 [PATCH v3] iio: light: opt3001: split opt3001_get_processed() logic Joshua Crofts
2026-07-12 13:58 ` Andy Shevchenko [this message]
2026-07-12 16:38 ` Joshua Crofts
2026-07-13 1:04 ` 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=alOdn0m3fbznqqDm@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=joshua.crofts1@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@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