Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Roman Vivchar via B4 Relay" <devnull+rva333.protonmail.com@kernel.org>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH v2 2/4] iio: adc: mt6323-auxadc: add mt6323 PMIC AUXADC driver
Date: Tue, 09 Jun 2026 13:44:28 +0000	[thread overview]
Message-ID: <20260609134428.7E4C81F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260609-mt6323-adc-v2-2-aa93a22309f9@protonmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] The probe function unconditionally dereferences `dev->parent` and `dev->parent->parent`, which will cause a kernel panic if the parent device is NULL.
- [High] The driver incorrectly uses the logical device tree channel index instead of the physical ADC channel index when setting the hardware request bitmask.
- [Medium] The AUXADC voltage buffer (`VBUF`) is left permanently enabled on error paths, leading to a resource/power leak.
- [Medium] Incorrect IIO channel types are hardcoded as `IIO_VOLTAGE` for temperature and current channels, violating IIO ABI.
--

commit 5d793b85b8942cff4538a9fd7c909fd225402286
Author: Roman Vivchar <rva333@protonmail.com>

iio: adc: mt6323-auxadc: add mt6323 PMIC AUXADC driver

The mt6323 AUXADC is a 15-bit ADC used for system monitoring. This driver
provides support for reading various channels including battery and charger
voltages, battery and chip temperature, current sensing and accessory
detection.

Tested-by: Ben Grisdale <bengris32@protonmail.ch> # Amazon Echo Dot (2nd Generation)
Signed-off-by: Roman Vivchar <rva333@protonmail.com>

[ ... ]
> diff --git a/drivers/iio/adc/mt6323-auxadc.c b/drivers/iio/adc/mt6323-auxadc.c
> new file mode 100644
> index 0000000000000..f2cef989d3ce7
> --- /dev/null
> +++ b/drivers/iio/adc/mt6323-auxadc.c
[ ... ]
> +#define AUXADC_DEFAULT_OSR		3
> +
> +#define MTK_PMIC_IIO_CHAN(_name, _chan, _addr)                  \
> +{                                                               \
> +	.type = IIO_VOLTAGE,                                    \

[Severity: Medium]
Does hardcoding IIO_VOLTAGE here break the IIO ABI for temperature and
current channels?

It looks like bat_temp, chip_temp, and isense will be exported as
in_voltage_*_raw instead of IIO_TEMP and IIO_CURRENT.

> +	.indexed = 1,                                           \
> +	.channel = _chan,                                       \
[ ... ]
> +static int mt6323_auxadc_request(struct mt6323_auxadc *auxadc,
> +				 unsigned long channel)
> +{
> +	struct regmap *map = auxadc->regmap;
> +	int ret;
> +
> +	ret = regmap_set_bits(map, MT6323_AUXADC_CON11, AUXADC_CON11_VBUF_EN);
> +	if (ret)
> +		return ret;
> +
> +	return regmap_set_bits(map, MT6323_AUXADC_CON22, BIT(channel));

[Severity: High]
Does BIT(channel) request the correct physical hardware channel here?

The channel parameter receives chan->channel, which is a logical sequential
index (e.g., MT6323_AUXADC_BATON2 = 0), but the hardware request register
appears to expect bits corresponding to the physical ADC channels. For
instance, setting BIT(0) for BATON2 would request ADC0 from the hardware,
but the driver will later poll the ADC6 data register.

[Severity: Medium]
If regmap_set_bits() fails to set MT6323_AUXADC_CON22, does this leave the
AUXADC voltage buffer (VBUF) permanently enabled? 

Since the caller aborts on error without calling mt6323_auxadc_release(),
the AUXADC_CON11_VBUF_EN bit is never cleared.

> +}
> +
> +static int mt6323_auxadc_release(struct mt6323_auxadc *auxadc,
> +				 unsigned long channel)
> +{
> +	struct regmap *map = auxadc->regmap;
> +	int ret;
> +
> +	ret = regmap_clear_bits(map, MT6323_AUXADC_CON22, BIT(channel));
> +	if (ret)
> +		return ret;

[Severity: Medium]
If clearing MT6323_AUXADC_CON22 fails here, does it skip disabling the
voltage buffer? 

Returning early would leave AUXADC_CON11_VBUF_EN enabled.

> +
> +	return regmap_clear_bits(map, MT6323_AUXADC_CON11, AUXADC_CON11_VBUF_EN);
> +}
[ ... ]
> +static int mt6323_auxadc_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct mt6323_auxadc *auxadc;
> +	struct regmap *regmap;
> +	struct iio_dev *iio;
> +	int ret;
> +
> +	regmap = dev_get_regmap(dev->parent->parent, NULL);

[Severity: High]
Can this cause a null pointer dereference if the driver is probed directly
from a device tree node without an MFD parent?

Because the driver defines an of_match_table, it could be instantiated where
dev->parent is null. Even if dev->parent is valid but dev->parent->parent is
null, passing null to dev_get_regmap() will cause a kernel panic when it
attempts to lock devres.

> +	if (!regmap)
> +		return dev_err_probe(dev, -ENODEV, "failed to get regmap\n");
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260609-mt6323-adc-v2-0-aa93a22309f9@protonmail.com?part=2

  reply	other threads:[~2026-06-09 13:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09 13:31 [PATCH v2 0/4] AUXADC driver for the MediaTek mt6323 PMIC Roman Vivchar via B4 Relay
2026-06-09 13:31 ` [PATCH v2 1/4] dt-bindings: iio: adc: mediatek,mt6359-auxadc: add mt6323 PMIC AUXADC Roman Vivchar via B4 Relay
2026-06-09 16:01   ` Conor Dooley
2026-06-09 17:29     ` Roman Vivchar
2026-06-09 13:31 ` [PATCH v2 2/4] iio: adc: mt6323-auxadc: add mt6323 PMIC AUXADC driver Roman Vivchar via B4 Relay
2026-06-09 13:44   ` sashiko-bot [this message]
2026-06-09 13:32 ` [PATCH v2 3/4] mfd: mt6397-core: add mt6323 AUXADC support Roman Vivchar via B4 Relay
2026-06-09 13:43   ` sashiko-bot
2026-06-09 13:32 ` [PATCH v2 4/4] ARM: dts: mediatek: mt6323: add " Roman Vivchar via B4 Relay

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