Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rong Zhang" <i@rong.moe>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v4 8/9] HID: haptic: Convert into a loadable plugin module
Date: Tue, 24 Nov 2026 17:04:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-231651@kernel.org> (raw)
In-Reply-To: <20261125-hid-haptic-kmod-v4-8-03713a89f656@rong.moe>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] HID: haptic: module unload race via hid_plugin_put() in
  hid-haptic.ko
--

commit 36f36535430850c43124dc68d1bb0a9b639c5f30
Author: Rong Zhang <i@rong.moe>

HID: haptic: Convert into a loadable plugin module

This commit converts hid-haptic into a loadable module using the
hid-plugin framework so that hid-multitouch can load it on demand.

Link: https://lore.kernel.org/linux-input/auypydfkhx2eg7vp764way4batdilzc35inqda3exwzs3tk3ff@oagat6g46zto/

> diff --git a/drivers/hid/hid-haptic.c b/drivers/hid/hid-haptic.c
> index cbe834a77fd47..50d6673c7c211 100644
> --- a/drivers/hid/hid-haptic.c
> +++ b/drivers/hid/hid-haptic.c
> @@ -310,11 +310,12 @@ static void hid_haptic_destroy(struct ff_device *ff)
>  
>  	kfree(haptic->hid_usage_map);
>  	haptic->hid_usage_map = NULL;
> +
> +	hid_plugin_put(HID_PLUGIN_HAPTIC, &haptic->self_plugin->hp);
>  }
>  
> -int hid_haptic_init(struct hid_device *hdev,
> -		    struct hid_haptic_device *haptic,
> -		    struct input_dev *dev)
> +static int __hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *haptic,
> +			     struct input_dev *dev)
>  {
>  	struct ff_device *ff;
>  	int ret = 0, r;
> @@ -436,6 +437,20 @@ int hid_haptic_init(struct hid_device *hdev,
>  	haptic->hid_usage_map = NULL;
>  exit:
>  	dev_warn(&hdev->dev, "Cannot allocate haptic for %s: %d\n", hdev->name, ret);
> +	hid_plugin_put(HID_PLUGIN_HAPTIC, &haptic->self_plugin->hp);
>  	return ret;
>  }

[Severity: Medium]
Can calling hid_plugin_put() from inside hid_haptic_destroy() and
__hid_haptic_init() allow hid-haptic.ko to be unmapped while a CPU is
still executing inside it?

hid_plugin_put() is an inline helper that calls module_put(plugin->owner),
where plugin->owner is THIS_MODULE (hid-haptic.ko).  Because
hid-multitouch holds no direct symbol dependency on hid-haptic.ko, the
module refcount acquired by hid_plugin_get() is the only thing keeping the
module loaded:

CPU0                                  CPU1
input_ff_destroy()
  ff->destroy() [hid_haptic_destroy]
    hid_plugin_put()
      module_put(THIS_MODULE)
        atomic_dec_if_positive()
                                      delete_module("hid_haptic")
                                        try_stop_module()
                                        mod->exit()
                                        free_module()
        trace_module_put()
    return;  <-- page fault on unmapped hid-haptic.ko text

The same race exists on the error path of __hid_haptic_init().  To avoid
executing module text after dropping the last reference, the caller
outside hid-haptic.ko should call hid_plugin_put() after
self_plugin->init() fails or after the destroy callback returns.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-hid-haptic-kmod-v4-0-03713a89f656@rong.moe?part=8

  reply	other threads:[~2026-11-24 17:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 16:44 [PATCH v4 0/9] HID: Add hid-plugin framework & convert haptic into a plugin Rong Zhang
2026-11-24 16:44 ` [PATCH v4 1/9] HID: haptic: Get rid of input_ff_destroy() in error paths Rong Zhang
2026-11-24 17:04   ` sashiko-bot
2026-11-24 17:07     ` Rong Zhang
2026-11-24 16:44 ` [PATCH v4 2/9] HID: haptic: Fix use-after-free when draining workqueue Rong Zhang
2026-11-24 16:44 ` [PATCH v4 3/9] HID: haptic, multitouch: Check haptic prerequisite properly Rong Zhang
2026-11-24 16:44 ` [PATCH v4 4/9] HID: haptic, multitouch: Fix haptic device double-free and unnecessary allocation Rong Zhang
2026-11-24 16:44 ` [PATCH v4 5/9] HID: haptic: Postpone GET_REPORT to init Rong Zhang
2026-11-24 16:44 ` [PATCH v4 6/9] HID: haptic: Convert simple methods into static inline ones Rong Zhang
2026-11-24 16:44 ` [PATCH v4 7/9] HID: Add hid-plugin framework for loadable plugin modules Rong Zhang
2026-11-24 16:44 ` [PATCH v4 8/9] HID: haptic: Convert into a loadable plugin module Rong Zhang
2026-11-24 17:04   ` sashiko-bot [this message]
2026-11-24 16:44 ` [PATCH v4 9/9] HID: haptic: Remove stubs in favor of inlined dead code elimination Rong Zhang

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-231651@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=i@rong.moe \
    --cc=linux-input@vger.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