From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Ariana Lazar <ariana.lazar@microchip.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
"Dan Carpenter" <error27@gmail.com>
Subject: Re: [PATCH v3] iio: dac: mcp47feb02: Fix passing uninitialized vref1_uV for no Vref1 case
Date: Thu, 4 Jun 2026 10:58:56 +0300 [thread overview]
Message-ID: <aiEwQLq1RQW1OfZq@ashevche-desk.local> (raw)
In-Reply-To: <20260603-mcp47feb02-fix4-v3-1-ed09975cad15@microchip.com>
On Wed, Jun 03, 2026 at 05:44:48PM +0300, Ariana Lazar wrote:
> Ensure that if a device has Vref1 but reading the regulator returns an
> error, mcp47feb02_init_ctrl_regs() is not called with an uninitialized
> vref1_uV value.
>
> Also add a device_property_present() check for the Vref1 supply before
> reading the regulator.
...
> +static void mcp47feb02_regulator_disable(void *d)
> +{
> + struct regulator *reg = (struct regulator *)d;
Unneeded casting, then for the maintenance it's better to have assignment and
definition to be split as we have a validation check.
> + if (reg)
> + regulator_disable(reg);
> +}
With the above being said, there are two alternatives:
static void mcp47feb02_regulator_disable(void *d)
{
struct regulator *reg;
reg = d;
if (reg)
regulator_disable(reg);
}
OR (my preference)
static void mcp47feb02_regulator_disable(void *reg)
{
if (reg)
regulator_disable(reg);
}
...
> +static bool mcp47feb02_ref_mismatch(struct mcp47feb02_data *data, unsigned int ch)
> +{
> + bool use_vref, use_bandgap;
> +
> + if (data->chdata[ch].ref_mode == MCP47FEB02_VREF_VDD)
> + return false;
> +
> + use_vref = (data->phys_channels >= 4 && (ch % 2)) ? data->use_vref1 : data->use_vref;
Too many spaces.
> + use_bandgap = (data->chdata[ch].ref_mode == MCP47FEB02_INTERNAL_BAND_GAP);
(Unneeded parentheses.)
> + return use_vref == use_bandgap;
I would rewrite this as
bool use_bandgap;
if (data->chdata[ch].ref_mode == MCP47FEB02_VREF_VDD)
return false;
use_bandgap = data->chdata[ch].ref_mode == MCP47FEB02_INTERNAL_BAND_GAP;
if (data->phys_channels >= 4 && (ch % 2))
return data->use_vref1 == use_bandgap;
else // redundant, but left for the formatting purposes
return data->use_vref == use_bandgap;
> +}
...
> + data->phys_channels >= 4 && (i % 2)) {
This idiom is repeated so many times that I would rather see
static inline bool is_...(data, ch)
{
return data->phys_channels >= 4 && (ch % 2);
}
and be used everywhere. If required, add also a comment on top to explain the logic,
why we need it to be done this way.
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2026-06-04 7:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 14:44 Ariana Lazar
2026-06-03 17:15 ` Jonathan Cameron
2026-06-04 7:58 ` Andy Shevchenko [this message]
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=aiEwQLq1RQW1OfZq@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=andy@kernel.org \
--cc=ariana.lazar@microchip.com \
--cc=dlechner@baylibre.com \
--cc=error27@gmail.com \
--cc=jic23@kernel.org \
--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
all inboxes | Powered by JetHome®