All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ziqiang Xia" <xiazq123666@gmail.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v3 2/2] platform/x86: Add Emdoor Intel EWMI platform driver
Date: Thu, 26 Nov 2026 08:34:40 +0000	[thread overview]
Message-ID: <sashiko-outbox-235031@kernel.org> (raw)
In-Reply-To: <20261126-emdoor-intel-wmi-rfc-v3-2-7dfbb70f04a9@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] platform/x86: devres ordering UAF on priv->profile in
  ewmi_method_probe()
--

commit bb36b820143c26587e8a321ea23c0c4bd48c65cd
Author: Ziqiang Xia <xiazq123666@gmail.com>

platform/x86: Add Emdoor Intel EWMI platform driver

This commit adds a WMI platform driver for Emdoor Intel EWMI laptops,
exposing hwmon fan tachometers, platform_profile, touchpad state, and
WMI hotkey events.

> diff --git a/drivers/platform/x86/emdoor-intel-wmi.c b/drivers/platform/x86/emdoor-intel-wmi.c
> new file mode 100644
> index 0000000000000..f530462e2c400
> --- /dev/null
> +++ b/drivers/platform/x86/emdoor-intel-wmi.c
[ ... ]
> +static void ewmi_profile_work(struct work_struct *work)
> +{
> +	struct ewmi_method *priv = container_of(work, struct ewmi_method,
> +						profile_work);
> +
> +	platform_profile_notify(priv->profile);
> +}
> +
> +static int ewmi_method_event(struct notifier_block *nb, unsigned long code,
> +			     void *data)
> +{
> +	struct ewmi_method *priv = container_of(nb, struct ewmi_method,
> +						event_nb);
> +	struct wmi_device *event_wdev = data;
> +
> +	if (event_wdev->dev.parent != priv->wdev->dev.parent)
> +		return NOTIFY_DONE;
> +	if (code == EWMI_EVENT_PROFILE_NOTIFY ||
> +	    code == EWMI_EVENT_PROFILE_BALANCED ||
> +	    code == EWMI_EVENT_PROFILE_PERFORMANCE)
> +		schedule_work(&priv->profile_work);
> +
> +	return NOTIFY_OK;
> +}
> +
> +static void ewmi_method_stop(void *data)
> +{
> +	struct ewmi_method *priv = data;
> +
> +	blocking_notifier_chain_unregister(&ewmi_event_chain, &priv->event_nb);
> +}
> +
> +static int ewmi_method_probe(struct wmi_device *wdev, const void *context)
> +{
> +	static const u8 expected_version[] = { 1, 0, 1, 0 };
> +	struct ewmi_method *priv;
> +	struct device *hwmon;
> +	u8 version[4];
> +	int ret;
> +
> +	priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL);
> +	if (!priv)
> +		return -ENOMEM;
> +	priv->wdev = wdev;
> +
> +	ret = devm_mutex_init(&wdev->dev, &priv->lock);
> +	if (ret)
> +		return ret;
> +
> +	ret = devm_work_autocancel(&wdev->dev, &priv->profile_work,
> +				   ewmi_profile_work);
> +	if (ret)
> +		return ret;
> +
> +	dev_set_drvdata(&wdev->dev, priv);
> +
> +	scoped_guard(mutex, &priv->lock) {
> +		ret = ewmi_call(priv, EWMI_GRP_SYSTEM, EWMI_CMD_GET_VERSION, 0,
> +				version, sizeof(version));
> +		if (ret) {
> +			return dev_err_probe(&wdev->dev, ret,
> +					     "Cannot query protocol version\n");
> +		}
> +	}
> +	if (memcmp(version, expected_version, sizeof(version))) {
> +		return dev_err_probe(&wdev->dev, -ENODEV,
> +				     "Unsupported protocol version\n");
> +	}
> +
> +	priv->profile = devm_platform_profile_register(&wdev->dev,
> +						       "emdoor-intel-wmi",
> +						       priv, &ewmi_profile_ops);
> +	if (IS_ERR(priv->profile)) {
> +		return dev_err_probe(&wdev->dev, PTR_ERR(priv->profile),
> +				     "Cannot register platform profile\n");
> +	}
> +
> +	priv->event_nb.notifier_call = ewmi_method_event;
> +	ret = blocking_notifier_chain_register(&ewmi_event_chain,
> +					       &priv->event_nb);
> +	if (ret)
> +		return ret;
> +	ret = devm_add_action_or_reset(&wdev->dev, ewmi_method_stop, priv);
> +	if (ret)
> +		return ret;

[Severity: Medium]
Can ewmi_profile_work() cause a use-after-free on priv->profile during
device teardown?

Because devm_work_autocancel() is registered before
devm_platform_profile_register(), devres teardown runs them in reverse
order:

CPU0                              CPU1
ewmi_event_notify()
  ...
    ewmi_method_event()
      schedule_work(&priv->profile_work)
device_release_driver()
  ewmi_method_stop()
  devm_platform_profile_release()
    platform_profile_remove(priv->profile)
                                  ewmi_profile_work()
                                    platform_profile_notify(priv->profile)
                                      <-- use-after-free
  devm_work_drop()
    cancel_work_sync(&priv->profile_work)

Registering devm_work_autocancel() after devm_platform_profile_register()
(or canceling priv->profile_work in ewmi_method_stop()) ensures the work
is canceled before priv->profile is removed.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-emdoor-intel-wmi-rfc-v3-0-7dfbb70f04a9@gmail.com?part=2

  reply	other threads:[~2026-11-26  8:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  8:21 [PATCH v3 0/2] platform/x86: Add Emdoor Intel EWMI platform driver Ziqiang Xia
2026-11-26  8:21 ` Ziqiang Xia via B4 Relay
2026-11-26  8:21 ` [PATCH v3 1/2] Documentation: ABI: testing: Add emdoor-intel-wmi sysfs ABI Ziqiang Xia
2026-11-26  8:21   ` Ziqiang Xia via B4 Relay
2026-11-26  8:21 ` [PATCH v3 2/2] platform/x86: Add Emdoor Intel EWMI platform driver Ziqiang Xia
2026-11-26  8:21   ` Ziqiang Xia via B4 Relay
2026-11-26  8:34   ` sashiko-bot [this message]
2026-11-26  8:34 ` [PATCH v3 0/2] " sashiko-bot

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-235031@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xiazq123666@gmail.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.