Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian Fressl" <christian@fressl.at>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH] HID: magicmouse: add haptic click configuration for Magic Trackpad 2
Date: Wed, 13 May 2026 00:16:49 +0000	[thread overview]
Message-ID: <20260513001649.E9EE5C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260511203115.104087-1-christian@fressl.at>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The module parameter `haptic_click` is read multiple times without being cached, resulting in a Time-of-Check to Time-of-Use (TOCTOU) race condition.
--

commit 160ed71822c4a0697b90debaa037251a7e50642c
Author: Christian Fressl <christian@fressl.at>

HID: magicmouse: add haptic click configuration for Magic Trackpad 2

This commit adds support for configuring the haptic feedback on Apple
Magic Trackpad 2 devices. It introduces the haptic_click module parameter
to choose between unchanged, silent-low, or off states.

Link: https://github.com/mwyborski/Linux-Magic-Trackpad-2-Driver/issues/28#issuecomment-451625504

> diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
> index e70bd3dc07ab7..31002cb1f1089 100644
> --- a/drivers/hid/hid-magicmouse.c
> +++ b/drivers/hid/hid-magicmouse.c

[ ... ]

> @@ -812,6 +827,81 @@ static bool is_usb_magictrackpad2(__u32 vendor, __u32 product)

[ ... ]

> +static int magicmouse_apply_haptic_click(struct hid_device *hdev)
> +{
> +	u32 click_feedback;
> +	u32 release_feedback;
> +	int ret;
> +
> +	if (haptic_click == TRACKPAD2_HAPTIC_CLICK_UNCHANGED)
> +		return 0;
> +
> +	switch (haptic_click) {

Since haptic_click is a module parameter with 0644 permissions, can it
change concurrently between the if statement and the switch statement?

If it changes from TRACKPAD2_HAPTIC_CLICK_SILENT_LOW (1) to
TRACKPAD2_HAPTIC_CLICK_UNCHANGED (0) right after the early return check,
this regression could cause the switch statement to fall through to the
default case. This would result in an incorrect warning and return -EINVAL.

Would it be safer to read the parameter into a local variable once using
READ_ONCE() to avoid this race condition?

> +	case TRACKPAD2_HAPTIC_CLICK_SILENT_LOW:
> +		click_feedback = TRACKPAD2_HAPTIC_SILENT_CLICK;
> +		release_feedback = TRACKPAD2_HAPTIC_SILENT_RELEASE;
> +		break;
> +	case TRACKPAD2_HAPTIC_CLICK_OFF:
> +		click_feedback = TRACKPAD2_HAPTIC_OFF;
> +		release_feedback = TRACKPAD2_HAPTIC_OFF;
> +		break;
> +	default:
> +		hid_warn(hdev, "invalid haptic_click value %u\n", haptic_click);
> +		return -EINVAL;
> +	}

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260511203115.104087-1-christian@fressl.at?part=1

  reply	other threads:[~2026-05-13  0:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11 20:31 [PATCH] HID: magicmouse: add haptic click configuration for Magic Trackpad 2 Christian Fressl
2026-05-13  0:16 ` sashiko-bot [this message]
2026-05-14 17:15   ` [PATCH v2] " Christian Fressl

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=20260513001649.E9EE5C2BCB0@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=christian@fressl.at \
    --cc=dmitry.torokhov@gmail.com \
    --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