Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Roman Vivchar" <rva333@protonmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v5 2/3] nvmem: add mt6323 PMIC EFUSE driver
Date: Mon, 21 Sep 2026 08:01:55 +0000	[thread overview]
Message-ID: <20260921080156.5BE881F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260921-mt6323-nvmem-v5-2-2f5d308369f0@protonmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] nvmem: buffer overflow and unaligned memory access in efuse read loop
- [Medium] nvmem: EFUSE data exposed with host-dependent endianness
- [Medium] nvmem: NULL pointer dereference in probe when parent is missing
- [Medium] nvmem: module autoloading fails without MODULE_ALIAS
--

commit 3543415716c7fda0e6f5e6edb62e4ed761b35afd
Author: Roman Vivchar <rva333@protonmail.com>

nvmem: add mt6323 PMIC EFUSE driver

This commit adds support for the EFUSE controller found in the Mediatek
MT6323 PMIC. The MT6323 EFUSE stores 24 bytes of hardware-related data,
such as thermal sensor calibration values.

diff --git a/drivers/nvmem/mt6323-efuse.c b/drivers/nvmem/mt6323-efuse.c
new file mode 100644
index 0000000000000..de5e30215c22d
--- /dev/null
+++ b/drivers/nvmem/mt6323-efuse.c
[ ... ]
> +static int mt6323_efuse_read(void *context, unsigned int offset, void *val,
> +			     size_t bytes)
> +{
> +	struct regmap *map = context;
> +	u16 *buf = val;
> +	u32 tmp;
> +	int ret;
> +
> +	/*
> +	 * A manual loop using regmap_read is required because PWRAP is not
> +	 * a continuous MMIO space, but rather a FSM that doesn't implement the
> +	 * necessary read callback for the regmap_read_raw and regmap_read_bulk
> +	 * functions.
> +	 */
> +	for (size_t i = 0; i < bytes; i += sizeof(*buf)) {

[Severity: High]
Could this loop overflow the allocated val buffer and cause unaligned memory
accesses?

The NVMEM core API nvmem_device_read() does not enforce that the requested
bytes count is a multiple of word_size. If an in-kernel consumer requests an
odd number of bytes (for example, 1 or 3), the loop will run an extra
iteration and unconditionally write a full 16-bit word. This will overflow
the caller's allocated val buffer by 1 byte.

Additionally, if val is not 16-bit aligned, this causes an unaligned memory
access.

> +		ret = regmap_read(map, MT6323_EFUSE_DOUT_BASE + offset + i, &tmp);
> +		if (ret)
> +			return ret;
> +
> +		*buf++ = tmp;

[Severity: Medium]
Does this expose the EFUSE data with a host-dependent endianness?

The regmap_read() function returns a CPU-endian 32-bit integer, which is
assigned to tmp. Writing this integer into a 16-bit buffer using native CPU
byte order means that on big-endian architectures, the bytes will be swapped
compared to little-endian architectures, breaking the expected NVMEM byte
stream consistency.

> +	}
> +
> +	return 0;
> +}
> +
> +static int mt6323_efuse_probe(struct platform_device *pdev)
> +{
> +	struct mt6397_chip *mt6323 = dev_get_drvdata(pdev->dev.parent);

[Severity: Medium]
Will this cause a NULL pointer dereference if the parent device pointer is
missing?

The driver has an of_match_table. If it is instantiated directly from a root
Device Tree node rather than being instantiated as an MFD child, the parent
device pointer pdev->dev.parent will be NULL. Calling dev_get_drvdata() on a
NULL parent dereferences it immediately without checks, leading to a crash.

[ ... ]
> +static struct platform_driver mt6323_efuse_driver = {
> +	.probe = mt6323_efuse_probe,
> +	.driver = {
> +		.name = "mt6323-efuse",
> +		.of_match_table = mt6323_efuse_of_match,
> +	},
> +};
> +module_platform_driver(mt6323_efuse_driver);
> +
> +MODULE_DESCRIPTION("MediaTek MT6323 PMIC EFUSE driver");
> +MODULE_LICENSE("GPL");

[Severity: Medium]
Will module autoloading fail without a MODULE_ALIAS declaration here?

On systems where the Device Tree lacks the mediatek,mt6323-efuse node, the
MFD core will still instantiate the child device by name, producing a modalias
of platform:mt6323-efuse. Because the driver lacks a MODULE_ALIAS declaration
for platform:mt6323-efuse, udev cannot match the modalias, and the module
might never be automatically loaded on boot.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260921-mt6323-nvmem-v5-0-2f5d308369f0@protonmail.com?part=2

  reply	other threads:[~2026-09-21  8:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21  7:50 [PATCH v5 0/3] nvmem: add support for the MediaTek mt6323 PMIC Roman Vivchar via B4 Relay
2026-09-21  7:50 ` [PATCH v5 1/3] dt-bindings: mfd: mediatek: mt6397: add mt6323 PMIC EFUSE Roman Vivchar via B4 Relay
2026-09-21  7:50 ` [PATCH v5 2/3] nvmem: add mt6323 PMIC EFUSE driver Roman Vivchar via B4 Relay
2026-09-21  8:01   ` sashiko-bot [this message]
2026-09-21  7:50 ` [PATCH v5 3/3] ARM: dts: mediatek: mt6323: add EFUSE support Roman Vivchar via B4 Relay
2026-09-21  9:30 ` (subset) [PATCH v5 0/3] nvmem: add support for the MediaTek mt6323 PMIC Srinivas Kandagatla

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=20260921080156.5BE881F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=rva333@protonmail.com \
    --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