Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Svyatoslav Ryhel" <clamor95@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 2/2] platform/asus: Add driver for ASUS Transformer's Dock of Tegra based devices
Date: Fri, 04 Dec 2026 07:08:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-249293@kernel.org> (raw)
In-Reply-To: <20261204063414.63617-3-clamor95@gmail.com>

Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] platform/asus: double-free and UAF reusing priv->adap after
  failed add
- [Medium] platform/asus: asus_tf_dock_probe() returns -ENODEV instead
  of -EPROBE_DEFER
- [Medium] platform/asus: asus_tf_dock_activate() sets wrong
  adap.dev.parent
- [Medium] platform/asus: missing PM resume callback misses dock changes
  in suspend
- [Medium] platform/asus: asus_tf_dock_algo omits xfer_atomic and uses
  deprecated master_xfer
- [Medium] platform/asus: nested I2C retries in asus_tf_dock_probe()
- [Low] platform/asus: shared static i2c_bus_recovery_info mutated
  without locking
--

commit a88f182670e0c763b88a8c86992d33cc8ebfaf13
Author: Michał Mirosław <mirq-linux@rere.qmqm.pl>

platform/asus: Add driver for ASUS Transformer's Dock of Tegra based devices

This commit adds a platform driver for the ASUS Transformer dock on
Tegra-based devices, exposing a hot-pluggable child I2C adapter whose
presence is tracked via a detect GPIO.

> diff --git a/drivers/platform/asus/asus-transformer-dock.c b/drivers/platform/asus/asus-transformer-dock.c
> new file mode 100644
> index 0000000000000..a3f5e5ddcb0c7
> --- /dev/null
> +++ b/drivers/platform/asus/asus-transformer-dock.c
> @@ -0,0 +1,282 @@

[ ... ]

> +static const struct i2c_algorithm asus_tf_dock_algo_i2c = {
> +	.master_xfer = asus_tf_dock_master_xfer,
> +	.functionality = asus_tf_dock_functionality,
> +};
> +
> +static const struct i2c_algorithm asus_tf_dock_algo_smbus = {
> +	.smbus_xfer = asus_tf_dock_smbus_xfer,
> +	.functionality = asus_tf_dock_functionality,
> +};
> +
> +static const struct i2c_algorithm asus_tf_dock_algo_both = {
> +	.master_xfer = asus_tf_dock_master_xfer,
> +	.smbus_xfer = asus_tf_dock_smbus_xfer,
> +	.functionality = asus_tf_dock_functionality,
> +};

[Severity: Medium]
Should these i2c_algorithm structs use .xfer instead of the deprecated
.master_xfer and propagate .xfer_atomic / .smbus_xfer_atomic from parent?

Tegra's tegra_i2c_algo supports .xfer_atomic, so an atomic dock transfer
during shutdown or reboot triggers a WARN in __i2c_lock_bus_helper() and
breaks atomic SMBus fallback in __i2c_smbus_xfer().  Populating a
per-instance struct i2c_algorithm from parent->algo avoids this.

[ ... ]

> +static struct i2c_bus_recovery_info asus_tf_dock_recovery_info = {
> +	.recover_bus = asus_tf_dock_recover_bus,
> +};

[Severity: Low]
Can sharing a single mutable static struct i2c_bus_recovery_info across
instances cause a data race during adapter registration?

i2c_add_adapter() -> i2c_register_adapter() -> i2c_init_recovery() calls
i2c_gpio_init_pinctrl_recovery() without holding core_lock, mutating
bri->pinctrl, bri->pins_default, and bri->pins_gpio before non-generic
recover_bus callbacks are skipped.  Embedding struct i2c_bus_recovery_info
in struct asus_tf_dock_priv eliminates the shared mutable state.

> +static int asus_tf_dock_activate(struct asus_tf_dock_priv *priv)
> +{
> +	int ret;
> +
> +	if (test_bit(ASUS_TF_DOCK_ATTACHED, &priv->state_flags))
> +		return 0;
> +
> +	/*
> +	 * Store the dev data in adapter dev, since
> +	 * previous i2c_del_adapter might have wiped it.
> +	 */
> +	priv->adap.dev.parent = priv->dev;

[Severity: Medium]
Should priv->adap.dev.parent be &priv->parent->dev rather than priv->dev?

i2c_parent_is_i2c_adapter() and i2c_adapter_depth() check for ancestors of
type &i2c_adapter_type.  Using the platform device breaks cross-bus address
collision detection in i2c_check_addr_busy(), stops i2c_root_adapter() at
priv->adap, and loses lockdep depth and parent-child async PM ordering.

> +	device_set_node(&priv->adap.dev, priv->i2c_fwnode);
> +
> +	dev_dbg(priv->adap.dev.parent, "connection detected");
> +
> +	ret = i2c_add_adapter(&priv->adap);
> +	if (!ret)
> +		set_bit(ASUS_TF_DOCK_ATTACHED, &priv->state_flags);
> +
> +	return ret;
> +}

[ ... ]

> +	if (state)
> +		asus_tf_dock_activate(priv);
> +	else
> +		asus_tf_dock_deactivate(priv);

[Severity: High]
Can reusing priv->adap after a failed i2c_add_adapter() cause a double
free and use-after-free on the next attach interrupt?

Unlike i2c_del_adapter(), i2c_register_adapter()'s err_put_adap path calls
put_device(&adap->dev) without zeroing adap->dev.  If registration fails
after device_initialize() (e.g., in device_add()), kobject_cleanup() frees
kobj.name and device_release() frees dev->p without clearing them.

Since ASUS_TF_DOCK_ATTACHED remains clear and asus_tf_dock_interrupt()
ignores the return value, the next attach retries on the released device:
dev_set_name() double frees kobj.name and device_add() dereferences the
dangling dev->p.

Allocating a fresh struct i2c_adapter per activation (or zeroing
priv->adap.dev before registration) and logging errors from
asus_tf_dock_activate() would avoid this.

[ ... ]

> +	parent = of_get_i2c_adapter_by_node(parent_np);
> +	of_node_put(parent_np);
> +	if (!parent)
> +		return dev_err_probe(dev, -ENODEV,
> +				     "Failed to get parent I2C adapter\n");

[Severity: Medium]
Should this return -EPROBE_DEFER instead of -ENODEV when parent is NULL?

of_get_i2c_adapter_by_node() returns NULL whenever the parent I2C adapter
has not registered yet (for instance with modular or asynchronously probed
controllers, or fw_devlink=off).  Returning -ENODEV permanently aborts
probe instead of deferring, leaving the dock bus and its devices unbound.

[ ... ]

> +	priv->adap.retries = parent->retries;
> +	priv->adap.timeout = parent->timeout;

[Severity: Medium]
Does copying parent->retries and parent->timeout nest the I2C core retry
loops on -EAGAIN?

asus_tf_dock_master_xfer() and asus_tf_dock_smbus_xfer() delegate to
__i2c_transfer(parent, ...) and __i2c_smbus_xfer(parent, ...), running the
parent retry loop inside priv->adap's loop.  On arbitration loss, attempts
are squared to (parent->retries + 1)^2 while holding parent->bus_lock.

Leaving priv->adap.retries at 0 lets the parent adapter handle retries
once without nesting.

[ ... ]

> +static struct platform_driver asus_tf_dock_driver = {
> +	.driver	= {
> +		.name = "asus-transformer-dock",
> +		.of_match_table = asus_tf_dock_of_match,
> +	},
> +	.probe = asus_tf_dock_probe,
> +};

[Severity: Medium]
Does this driver miss dock attach and detach events that occur during
system suspend?

On Tegra, tegra_gpio_suspend() masks non-wakeup GPIO interrupts and
tegra_gpio_resume() does not synthesize missed edges.  Without
enable_irq_wake() or a PM resume callback to re-check priv->gpio, docking
or undocking during suspend leaves software state out of sync on resume.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204063414.63617-1-clamor95@gmail.com?part=2

      reply	other threads:[~2026-12-04  7:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  6:34 [PATCH v2 0/2] platform/asus: Add driver for ASUS Transformer's Dock Svyatoslav Ryhel
2026-12-04  6:34 ` [PATCH v2 1/2] dt-bindings: connector: Document " Svyatoslav Ryhel
2026-12-04  6:52   ` sashiko-bot
2026-12-04  6:34 ` [PATCH v2 2/2] platform/asus: Add driver for ASUS Transformer's Dock of Tegra based devices Svyatoslav Ryhel
2026-12-04  7:08   ` 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=sashiko-outbox-249293@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=clamor95@gmail.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