All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Varshini Rajendran" <varshini.rajendran@microchip.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 09/16] nvmem: microchip-otpc: nvmem: add emulation mode and OTP access validation
Date: Mon, 27 Jul 2026 12:39:48 +0000	[thread overview]
Message-ID: <20260727123948.E8EAB1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260727122633.117435-10-varshini.rajendran@microchip.com>

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

Pre-existing issues:
- [High] The arguments for `sleep_us` and `timeout_us` in `read_poll_timeout` are swapped, causing the poll to sleep excessively and fail prematurely.
- [High] There is a mismatch between the calculated NVMEM device size and the number of bytes read per packet, leading to truncated reads and corrupted payload data in the buffer.
- [Medium] The OTP payload stream is read from the `MCHP_OTPC_DR` data register using `readl_relaxed()` in a loop, which causes unintended byte-swapping on big-endian architectures.
--

--- Patch [9]: [PATCH v4 09/16] nvmem: microchip-otpc: nvmem: add emulation mode and OTP access validation ---
commit b464c23d34790bae23b36f89796febe703de8718
Author: Varshini Rajendran <varshini.rajendran@microchip.com>

nvmem: microchip-otpc: nvmem: add emulation mode and OTP access validation

This commit adds validation of OTP memory accessibility and emulation mode
status during probe. When the boot packet is not configured, emulation mode
allows access to the other packets.

> diff --git a/drivers/nvmem/microchip-otpc.c b/drivers/nvmem/microchip-otpc.c
> index a17f82afdc37d..6b0184423463e 100644
> --- a/drivers/nvmem/microchip-otpc.c
> +++ b/drivers/nvmem/microchip-otpc.c
> @@ -343,7 +344,8 @@ static int mchp_otpc_probe(struct platform_device *pdev)
>  {
[ ... ]
>  	ret = mchp_otpc_init_packets_list(otpc, &size);
>  	if (ret)
>  		return ret;
>  
> +	if (!size) {
> +		dev_warn(otpc->dev, "Cannot access OTP memory\n");
> +		if (!emul_enable)
> +			dev_info(otpc->dev, "Boot packet not programmed and emulation mode disabled\n");
> +	}
> +
>  	mchp_nvmem_config.dev = otpc->dev;
>  	mchp_nvmem_config.add_legacy_fixed_of_cells = true;

While reviewing this patch, I noticed a few pre-existing issues in the same
file that you might want to address:

drivers/nvmem/microchip-otpc.c:mchp_otpc_read()
>        *buf++ = readl_relaxed(otpc->base + MCHP_OTPC_DR);

[Severity: Medium]
This is a pre-existing issue, but does this read sequential FIFO payload data
using a byteswapping scalar accessor rather than a stream accessor (e.g.
readsl())?

Using readl_relaxed() here might cause unintended byte-swapping on big-endian
architectures when reading the underlying raw byte stream.


drivers/nvmem/microchip-otpc.c:mchp_otpc_prepare_read()
>    return read_poll_timeout(readl_relaxed, tmp, !(tmp & MCHP_OTPC_SR_READ),
>                             10000, 2000, false, otpc->base + MCHP_OTPC_SR);

[Severity: High]
This is a pre-existing issue, but are the sleep_us and timeout_us arguments
swapped here?

The sleep_us parameter is set to 10000 (10ms) while timeout_us is set to
2000 (2ms), which would cause the timeout to expire before the first sleep
completes.


drivers/nvmem/microchip-otpc.c:mchp_otpc_init_packets_list()
>    *size += 4 * (payload_size + 1);

drivers/nvmem/microchip-otpc.c:mchp_otpc_read()
>    } while (payload_size >= 0 && len < bytes);

[Severity: High]
This is a pre-existing issue, but is there a mismatch between the calculated
NVMEM device size and the number of bytes read per packet?

In mchp_otpc_init_packets_list(), the total size is incremented by exactly
payload_size + 1 words (header + payload).

However, in mchp_otpc_read(), the loop condition payload_size >= 0 causes
it to iterate payload_size + 1 times for the payload alone, meaning a total
of payload_size + 2 words (including header) are fetched and written to the
buffer per packet.

Could this write a padding or gap word into the user buffer, shifting
subsequent packets and causing final packets to be truncated because the
len < bytes limit is reached prematurely?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260727122633.117435-1-varshini.rajendran@microchip.com?part=9

  reply	other threads:[~2026-07-27 12:39 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27 12:26 [PATCH v4 00/16] Add thermal management support for sama7d65 Varshini Rajendran
2026-07-27 12:26 ` [PATCH v4 01/16] dt-bindings: iio: adc: at91-sama5d2: document sama7d65 Varshini Rajendran
2026-07-27 12:26 ` [PATCH v4 02/16] iio: adc: at91-sama5d2_adc: use cleanup.h for NVMEM buffer Varshini Rajendran
2026-07-27 12:36   ` sashiko-bot
2026-07-27 12:26 ` [PATCH v4 03/16] iio: adc: at91-sama5d2_adc: rework temp calibration layout handling Varshini Rajendran
2026-07-27 12:39   ` sashiko-bot
2026-07-27 12:26 ` [PATCH v4 04/16] iio: adc: at91-sama5d2_adc: add condition to validate calibration data Varshini Rajendran
2026-07-27 12:42   ` sashiko-bot
2026-07-27 12:26 ` [PATCH v4 05/16] iio: adc: at91-sama5d2_adc: remove unnecessary casts in of_device_id Varshini Rajendran
2026-07-27 12:26 ` [PATCH v4 06/16] iio: adc: at91-sama5d2_adc: adapt the driver for sama7d65 Varshini Rajendran
2026-07-27 12:41   ` sashiko-bot
2026-07-27 12:26 ` [PATCH v4 07/16] dt-bindings: nvmem: microchip,sama7g5-otpc: add sama7d65 and dt node example Varshini Rajendran
2026-07-27 12:41   ` sashiko-bot
2026-07-27 12:26 ` [PATCH v4 08/16] nvmem: microchip-otpc: nvmem: microchip-otpc: add tag-based packet lookup Varshini Rajendran
2026-07-27 12:44   ` sashiko-bot
2026-07-27 12:26 ` [PATCH v4 09/16] nvmem: microchip-otpc: nvmem: add emulation mode and OTP access validation Varshini Rajendran
2026-07-27 12:39   ` sashiko-bot [this message]
2026-07-27 12:26 ` [PATCH v4 10/16] ARM: dts: microchip: sama7d65: add cpu opps Varshini Rajendran
2026-07-27 12:26 ` [PATCH v4 11/16] ARM: dts: microchip: sama7d65: Add ADC node Varshini Rajendran
2026-07-27 12:26 ` [PATCH v4 12/16] ARM: dts: microchip: sama7d65_curiosity: Enable ADC, DVFS Varshini Rajendran
2026-07-27 12:26 ` [PATCH v4 13/16] ARM: dts: microchip: sama7d65: add otpc node Varshini Rajendran
2026-07-27 12:44   ` sashiko-bot
2026-07-27 12:26 ` [PATCH v4 14/16] ARM: dts: microchip: sama7d65: add cells for temperature calibration Varshini Rajendran
2026-07-27 12:50   ` sashiko-bot
2026-07-27 12:26 ` [PATCH v4 15/16] ARM: dts: microchip: sama7d65: add temperature sensor Varshini Rajendran
2026-07-27 12:45   ` sashiko-bot
2026-07-27 12:26 ` [PATCH v4 16/16] ARM: dts: microchip: sama7d65: add thermal zones node Varshini Rajendran

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=20260727123948.E8EAB1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=varshini.rajendran@microchip.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.