Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ariana Lazar" <ariana.lazar@microchip.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 3/9] iio: dac: mcp47feb02: correct false state case in store_eeprom_store
Date: Wed, 19 Aug 2026 12:51:28 +0000	[thread overview]
Message-ID: <20260819125128.970911F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260819-mcp47feb02_refactor-v4-3-beb2aa3bfd09@microchip.com>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but mcp47feb02_resume incorrectly writes the powerdown mode to the Voltage Reference (VREF) register, corrupting the channel's reference voltage setting.
- [High] This problem wasn't introduced by this patch, but mcp47feb02_suspend and mcp47feb02_resume overwrite the software powerdown state, causing all channels to be forcefully activated on resume regardless of user configuration.
- [High] This problem wasn't introduced by this patch, but mcp47feb02_init_ctrl_regs fails to identify the powerdown state when the hardware boots in '1kohm_to_gnd' mode.
- [High] This problem wasn't introduced by this patch, but store_eeprom_store performs a sequence of volatile register reads and EEPROM writes without holding the state mutex, leading to a TOCTOU race condition.
- [High] This problem wasn't introduced by this patch, but mcp47feb02_write_raw does not validate the incoming user value against bounds for IIO_CHAN_INFO_RAW.
--

--- Patch [3]: [PATCH v4 3/9] iio: dac: mcp47feb02: correct false state case in store_eeprom_store ---
commit dc6f30f8cc576f94a887f7f0e174caf833ebb683
Author: Ariana Lazar <ariana.lazar@microchip.com>

iio: dac: mcp47feb02: correct false state case in store_eeprom_store
    
Return len also when the state is false instead of 0.

> diff --git a/drivers/iio/dac/mcp47feb02.c b/drivers/iio/dac/mcp47feb02.c
> index bf78618ac2c89..2ee981393aa1a 100644
> --- a/drivers/iio/dac/mcp47feb02.c
> +++ b/drivers/iio/dac/mcp47feb02.c
> @@ -469,7 +469,7 @@ static ssize_t store_eeprom_store(struct device *dev, struct device_attribute *a
>  		return ret;
>  
>  	if (!state)
> -		return 0;
> +		return len;
>  
>  	/*
>  	 * Verify DAC Wiper and DAC Configuration are unlocked. If both are disabled,

[ ... ]

[Severity: High]
This isn't a bug introduced by this patch, but store_eeprom_store performs
a sequence of volatile register reads and EEPROM writes without holding the
state mutex, leading to a race condition with concurrent state modifications.

Can an inconsistent combination of driver states be written to the NV EEPROM
because the data->lock is not held across the snapshot sequence?

drivers/iio/dac/mcp47feb02.c:store_eeprom_store() {
    ...
    ret = mcp47feb02_write_to_eeprom(data, NV_REG_ADDR(i),
                                     data->chdata[i].dac_data);
    ...
}

[Severity: High]
This is a pre-existing issue, but mcp47feb02_resume incorrectly writes the
powerdown mode to the Voltage Reference (VREF) register, corrupting the
channel's reference voltage setting.

During system resume, does this corrupt the voltage reference configuration
because it targets MCP47FEB02_VREF_REG_ADDR instead of the powerdown register?

drivers/iio/dac/mcp47feb02.c:mcp47feb02_resume() {
    ...
    ret = regmap_update_bits(data->regmap, MCP47FEB02_VREF_REG_ADDR,
                             DAC_CTRL_MASK(ch), DAC_CTRL_VAL(ch, pd_mode));
    ...
}

[Severity: High]
This is a pre-existing issue, but mcp47feb02_suspend and mcp47feb02_resume
overwrite the software powerdown state, causing all channels to be forcefully
activated on resume regardless of user configuration.

Does this unconditionally wake the channel and destroy the user's previously
configured powerdown preference?

drivers/iio/dac/mcp47feb02.c:mcp47feb02_suspend() {
    ...
    data->chdata[ch].powerdown = true;
    ...
}

drivers/iio/dac/mcp47feb02.c:mcp47feb02_resume() {
    ...
    data->chdata[ch].powerdown = false;
    ...
}

[Severity: High]
This isn't a bug introduced by this patch, but mcp47feb02_init_ctrl_regs
fails to identify the powerdown state when the hardware boots in 1kohm_to_gnd
mode.

When pd_tmp is 1, powerdown_mode becomes 0. Does this cause the powerdown
check to evaluate to false even though the hardware is in a powerdown state?

drivers/iio/dac/mcp47feb02.c:mcp47feb02_init_ctrl_regs() {
    ...
    data->chdata[i].powerdown = !!(data->chdata[i].powerdown_mode);
    ...
}

[Severity: High]
This isn't a bug introduced by this patch, but mcp47feb02_write_raw does not
validate the incoming user value against bounds for IIO_CHAN_INFO_RAW.

Can out-of-bounds values be written directly to the DAC data registers since
the user-supplied value is not validated?

drivers/iio/dac/mcp47feb02.c:mcp47feb02_write_raw() {
    ...
    ret = regmap_write(data->regmap, REG_ADDR(ch->address), val);
    ...
}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260819-mcp47feb02_refactor-v4-0-beb2aa3bfd09@microchip.com?part=3

  reply	other threads:[~2026-08-19 12:51 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-19 12:41 [PATCH v4 0/9] Refactor Microchip MCP47FEB02 I2C driver in separate modules to add support for MCP48FEB02 SPI driver Ariana Lazar
2026-08-19 12:41 ` [PATCH v4 1/9] iio: dac: mcp47feb02: initialize dac_data field in channel data struct at probe Ariana Lazar
2026-08-19 14:17   ` Andy Shevchenko
2026-08-19 12:41 ` [PATCH v4 2/9] iio: dac: mcp47feb02: correct gain bitshift " Ariana Lazar
2026-08-19 12:50   ` sashiko-bot
2026-08-19 14:15   ` Andy Shevchenko
2026-08-19 12:41 ` [PATCH v4 3/9] iio: dac: mcp47feb02: correct false state case in store_eeprom_store Ariana Lazar
2026-08-19 12:51   ` sashiko-bot [this message]
2026-08-19 14:18   ` Andy Shevchenko
2026-08-19 12:41 ` [PATCH v4 4/9] iio: dac: mcp47feb02: use dev_dbg for invalid label Ariana Lazar
2026-08-19 12:49   ` sashiko-bot
2026-08-19 14:23   ` Andy Shevchenko
2026-08-19 12:41 ` [PATCH v4 5/9] iio: dac: mcp47feb02: correct typo from a comment Ariana Lazar
2026-08-19 12:41 ` [PATCH v4 6/9] iio: dac: mcp47feb02: rename command mask define Ariana Lazar
2026-08-19 12:46   ` sashiko-bot
2026-08-19 12:41 ` [PATCH v4 7/9] iio: dac: mcp47feb02: refactor MCP47FEB02 I2C driver into two modules Ariana Lazar
2026-08-19 12:52   ` sashiko-bot
2026-08-19 12:41 ` [PATCH v4 8/9] dt-bindings: iio: dac: add support for MCP48FEB02 SPI Ariana Lazar
2026-08-19 12:41 ` [PATCH v4 9/9] iio: dac: add support for Microchip MCP48FEB02 Ariana Lazar
2026-08-19 12:53   ` sashiko-bot

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=20260819125128.970911F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ariana.lazar@microchip.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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