Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kaustabh Chakraborty" <kauschluss@disroot.org>
Cc: devicetree@vger.kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH v6 11/11] power: supply: add support for Samsung S2M series PMIC charger device
Date: Fri, 15 May 2026 11:20:08 +0000	[thread overview]
Message-ID: <20260515112008.A5351C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260515-s2mu005-pmic-v6-11-1979106992d4@disroot.org>

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [Critical] Registration of power supply before acquiring `extcon` creates a race condition that can lead to a kernel panic.
- [High] `extcon_get_state()` negative error codes are incorrectly evaluated as true in boolean contexts, risking hardware damage.
- [High] Missing `else if` in `s2mu005_chgr_get_usb_type()` overwrites valid USB types.
- [High] Infinite probe deferral loop if the mandatory 'muic' device tree node is missing.
- [High] Ignored return value from `devm_extcon_register_notifier_all()` silently masks registration failures.
- [Medium] The initial hardware charger mode is not synchronized with the physical cable state during probe.
- [Low] Misleading indentation in `s2mu005_chgr_mode_set_charger()` due to missing curly braces.
--

commit e4bc7879e2d0f0f694862fddb5772356c6262c9b
Author: Kaustabh Chakraborty <kauschluss@disroot.org>

power: supply: add support for Samsung S2M series PMIC charger device

Add a driver for charger controllers found in certain Samsung S2M series
PMICs. The driver includes initial support for the S2MU005 PMIC charger.

> diff --git a/drivers/power/supply/s2m-charger.c b/drivers/power/supply/s2m-charger.c
> new file mode 100644
> index 0000000000000..b32cea55b8b04
> --- /dev/null
> +++ b/drivers/power/supply/s2m-charger.c
[ ... ]
> +static void s2mu005_chgr_get_usb_type(struct s2m_chgr *priv, int *value)
> +{
> +	if (extcon_get_state(priv->extcon, EXTCON_CHG_USB_CDP))
> +		*value = POWER_SUPPLY_USB_TYPE_CDP;
> +	if (extcon_get_state(priv->extcon, EXTCON_CHG_USB_SDP))
> +		*value = POWER_SUPPLY_USB_TYPE_SDP;
> +	if (extcon_get_state(priv->extcon, EXTCON_CHG_USB_DCP))
> +		*value = POWER_SUPPLY_USB_TYPE_DCP;
> +	else
> +		*value = POWER_SUPPLY_USB_TYPE_UNKNOWN;
> +}

Does the missing else if on the DCP check overwrite valid CDP or SDP states?
If a CDP or SDP charger is attached, DCP evaluates to false, which executes
the else block and overwrites *value with POWER_SUPPLY_USB_TYPE_UNKNOWN.

Also, extcon_get_state() can return negative error codes (e.g. -EINVAL) if
the cable ID is unsupported. Does evaluating this directly in a boolean
context cause it to be treated as true? Should this explicitly check for > 0?

[ ... ]
> +static int s2mu005_chgr_mode_set_charger(struct s2m_chgr *priv)
> +{
[ ... ]
> +	/* then set to charging mode */
> +	ret = regmap_update_bits(priv->regmap, S2MU005_REG_CHGR_CTRL0,
> +				 S2MU005_CHGR_OP_MODE,
> +				 FIELD_PREP(S2MU005_CHGR_OP_MODE,
> +					    S2MU005_CHGR_OP_MODE_CHG));
> +	if (ret < 0)
> +		dev_err(priv->dev, "failed to set opmode to charging (%d)\n", ret);
> +		return ret;
> +}

Is there a missing curly brace for the if (ret < 0) block? While return ret
executes unconditionally, the indentation is misleading.

[ ... ]
> +static void s2mu005_chgr_extcon_work(struct work_struct *work)
> +{
> +	struct s2m_chgr *priv = container_of(work, struct s2m_chgr, extcon_work);
> +
> +	if (extcon_get_state(priv->extcon, EXTCON_USB_HOST))
> +		s2mu005_chgr_mode_set_host(priv);
> +	else if (extcon_get_state(priv->extcon, EXTCON_USB))
> +		s2mu005_chgr_mode_set_charger(priv);
> +	else
> +		s2mu005_chgr_mode_unset(priv);
> +
> +	power_supply_changed(priv->psy);
> +}

Could a negative return from extcon_get_state() evaluate as true here? This
might trigger s2mu005_chgr_mode_set_host() erroneously, turning on the 5.1V
boost converter on the VBUS line. If this triggers while connected to an
external power source, back-driving 5.1V could damage the hardware.

[ ... ]
> +static int s2m_chgr_probe(struct platform_device *pdev)
> +{
[ ... ]
> +	psy_cfg.drv_data = priv;
> +	psy_cfg.fwnode = dev_fwnode(dev->parent);
> +	priv->psy = devm_power_supply_register(dev, psy_desc, &psy_cfg);
> +	if (IS_ERR(priv->psy))
> +		return dev_err_probe(dev, PTR_ERR(priv->psy),
> +				     "failed to register power supply subsystem\n");
> +
> +	/* MUIC is mandatory. If unavailable, request probe deferral */
> +	extcon_node = of_get_child_by_name(dev->parent->of_node, "muic");
> +	priv->extcon = extcon_find_edev_by_node(extcon_node);
> +	if (IS_ERR(priv->extcon))
> +		return -EPROBE_DEFER;

Could registering the power supply before acquiring extcon introduce a race
condition? If userspace (like udevd) reads the usb_type property
concurrently via sysfs:

sysfs read
  s2mu005_chgr_get_usb_type()
    extcon_get_state(priv->extcon, ...)

If this occurs while priv->extcon is still NULL, it passes NULL to
extcon_get_state(), returning -EINVAL.

Additionally, if extcon_find_edev_by_node() defers and returns
ERR_PTR(-EPROBE_DEFER), priv->extcon becomes an error pointer. Passing an
error pointer to extcon_get_state() bypasses its !edev NULL check, leading
to a dereference of an invalid address.

Furthermore, if the muic node is completely missing from the device tree,
of_get_child_by_name() returns NULL. Passing NULL to
extcon_find_edev_by_node() returns -EPROBE_DEFER.

Does this cause an infinite probe deferral loop for hardware that will never
appear? Should this explicitly check for !extcon_node and return -ENODEV
instead?

> +
> +	ret = devm_work_autocancel(dev, &priv->extcon_work, extcon_work_func);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "failed to initialize extcon work\n");
> +
> +	priv->extcon_nb.notifier_call = s2m_chgr_extcon_notifier;
> +	ret = devm_extcon_register_notifier_all(dev, priv->extcon, &priv->extcon_nb);
> +	if (ret)
> +		dev_err_probe(dev, ret, "failed to register extcon notifier\n");
> +
> +	return 0;
> +}

Is there a missing return statement before dev_err_probe()? Execution will
fall through to return 0, leaving the driver falsely reporting success but
unable to receive extcon state changes.

Also, the driver registers an extcon notifier, but is the initial hardware
charger mode ever synchronized with the physical cable state? Since
notifiers only fire on state transitions, if a USB cable is already plugged
in during boot, the PMIC might remain in its default unconfigured state.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260515-s2mu005-pmic-v6-0-1979106992d4@disroot.org?part=11

      reply	other threads:[~2026-05-15 11:20 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-15 10:38 [PATCH v6 00/11] Support for Samsung S2MU005 PMIC and its sub-devices Kaustabh Chakraborty
2026-05-15 10:38 ` [PATCH v6 01/11] dt-bindings: leds: document Samsung S2M series PMIC flash LED device Kaustabh Chakraborty
2026-05-15 10:38 ` [PATCH v6 02/11] dt-bindings: extcon: document Samsung S2M series PMIC extcon device Kaustabh Chakraborty
2026-05-15 11:05   ` sashiko-bot
2026-05-15 10:38 ` [PATCH v6 03/11] dt-bindings: mfd: add documentation for S2MU005 PMIC Kaustabh Chakraborty
2026-05-15 10:52   ` sashiko-bot
2026-05-15 10:39 ` [PATCH v6 04/11] mfd: sec: add support " Kaustabh Chakraborty
2026-05-15 11:16   ` sashiko-bot
2026-05-15 10:39 ` [PATCH v6 05/11] mfd: sec: set DMA coherent mask Kaustabh Chakraborty
2026-05-15 11:10   ` sashiko-bot
2026-05-15 10:39 ` [PATCH v6 06/11] mfd: sec: resolve PMIC revision in S2MU005 Kaustabh Chakraborty
2026-05-15 10:39 ` [PATCH v6 07/11] leds: flash: add support for Samsung S2M series PMIC flash LED device Kaustabh Chakraborty
2026-05-15 11:05   ` sashiko-bot
2026-05-15 10:39 ` [PATCH v6 08/11] leds: rgb: add support for Samsung S2M series PMIC RGB " Kaustabh Chakraborty
2026-05-15 11:13   ` sashiko-bot
2026-05-15 10:39 ` [PATCH v6 09/11] Documentation: leds: document pattern behavior of Samsung S2M series PMIC RGB LEDs Kaustabh Chakraborty
2026-05-15 11:03   ` sashiko-bot
2026-05-15 10:39 ` [PATCH v6 10/11] extcon: add support for Samsung S2M series PMIC extcon devices Kaustabh Chakraborty
2026-05-15 11:17   ` sashiko-bot
2026-05-15 10:39 ` [PATCH v6 11/11] power: supply: add support for Samsung S2M series PMIC charger device Kaustabh Chakraborty
2026-05-15 11:20   ` sashiko-bot [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=20260515112008.A5351C2BCB0@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kauschluss@disroot.org \
    --cc=krzk+dt@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