lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250724202349.11200-2-vishnuocv@gmail.com>
Date: Fri, 25 Jul 2025 05:23:48 +0900
From: Vishnu Sankar <vishnuocv@...il.com>
To: dmitry.torokhov@...il.com,
	hmh@....eng.br,
	hansg@...nel.org,
	ilpo.jarvinen@...ux.intel.com
Cc: mpearson-lenovo@...ebb.ca,
	linux-input@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	ibm-acpi-devel@...ts.sourceforge.net,
	platform-driver-x86@...r.kernel.org,
	vsankar@...ovo.com,
	Vishnu Sankar <vishnuocv@...il.com>
Subject: [PATCH v2 2/2] platform/x86: thinkpad_acpi: Use trackpoint doubletap interface via sysfs

TrackPoint devices supporting doubletap expose a sysfs attribute under
/sys/devices/.../trackpoint/doubletap_enabled. This patch enables
thinkpad_acpi to detect if the system has a TrackPoint device with
doubletap capability, and allows toggling the feature via sysfs.

This avoids direct linking between subsystems and relies on sysfs
as the interface for coordination between input and platform drivers.

Signed-off-by: Vishnu Sankar <vishnuocv@...il.com>
Suggested-by: Mark Pearson <mpearson-lenovo@...ebb.ca>
Suggested-by: Dmitry Torokhov <dmitry.torokhov@...il.com>
---
Changes in v2:
- Updated commit message to clarify dependency on trackpoint driver
- Now handling sysfs read/write of trackpoint driver using file read/write
- Removed sysfs attribute creation of trackpoint double tap here.
- Reversed the logic and return false right away
- Dropped unnecessary debug messages
- Using dev_dbg() instead of pr_xxxx()
---
 drivers/platform/x86/thinkpad_acpi.c | 155 +++++++++++++++++++++++++--
 1 file changed, 147 insertions(+), 8 deletions(-)

diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index b59b4d90b0c7..cb981de9bbb2 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -72,6 +72,13 @@
 #include <linux/units.h>
 #include <linux/workqueue.h>
 
+#include <linux/fs.h>
+#include <linux/file.h>
+#include <linux/err.h>
+#include <linux/fcntl.h>
+#include <linux/namei.h>
+#include <linux/kernel_read_file.h>
+
 #include <acpi/battery.h>
 #include <acpi/video.h>
 
@@ -373,7 +380,8 @@ static struct {
 	u32 hotkey_poll_active:1;
 	u32 has_adaptive_kbd:1;
 	u32 kbd_lang:1;
-	u32 trackpoint_doubletap:1;
+	u32 trackpoint_doubletap_state:1;
+	u32 trackpoint_doubletap_capable:1;
 	struct quirk_entry *quirks;
 } tp_features;
 
@@ -2879,6 +2887,107 @@ static DEVICE_ATTR_RW(hotkey_poll_freq);
 
 #endif /* CONFIG_THINKPAD_ACPI_HOTKEY_POLL */
 
+/*
+ * Trackpoint doubletap handlers
+ * These set of functions will communicate with the sysfs attributes of TrackPoint driver
+ * Attribute : /sys/bus/serio/devices/seriox/doubletap_enabled
+ */
+
+/* Global buffer to reuse path */
+static char trackpoint_doubletap_path[128];
+
+/* Function to find the correct serio path with TrackPoint attribute "doubletap_enabled" */
+static int thinkpad_find_trackpoint_path(void)
+{
+	struct path serio_path;
+	char path_buf[128];
+	int i;
+
+	for (i = 0; i < 10; i++) {
+		snprintf(path_buf, sizeof(path_buf),
+		"/sys/bus/serio/devices/serio%d/doubletap_enabled", i);
+
+		if (!kern_path(path_buf, LOOKUP_FOLLOW, &serio_path)) {
+			path_put(&serio_path);
+			snprintf(trackpoint_doubletap_path, sizeof(trackpoint_doubletap_path),
+				"%s", path_buf);
+			pr_info("ThinkPad ACPI: TrackPoint doubletap found at %s\n",
+				trackpoint_doubletap_path);
+			return 0;
+		}
+	}
+	return -ENODEV;
+}
+
+/* Writing to the sysfs attribute of Trackpoint "doubletap_enabled" */
+static int write_doubletap_sysfs_value(const void *buf, size_t count, loff_t *pos)
+{
+	struct file *filp;
+	ssize_t written;
+
+	if (!buf)
+		return -EINVAL;
+
+	filp = filp_open(trackpoint_doubletap_path, O_WRONLY | O_CREAT, 0644);
+	if (IS_ERR(filp))
+		return PTR_ERR(filp);
+
+	/* Required to avoid EINVAL from vfs checks in some cases */
+	if (!(filp->f_mode & FMODE_CAN_WRITE)) {
+		filp_close(filp, NULL);
+		return -EINVAL;
+	}
+
+	/* Write using kernel_write */
+	written = kernel_write(filp, buf, count, pos);
+	filp_close(filp, NULL);
+
+	return written < 0 ? written : 0;
+}
+
+/* Function to read the TrackPoint doubletap status */
+static int trackpoint_read_doubletap_status(bool *enabled)
+{
+	struct file *filp;
+	loff_t pos = 0;
+	char buf[8];
+	ssize_t ret;
+
+	if (!enabled)
+		return -EINVAL;
+
+	if (!trackpoint_doubletap_path[0])
+		return -ENODEV;
+
+	filp = filp_open(trackpoint_doubletap_path, O_RDONLY, 0);
+	if (IS_ERR(filp))
+		return PTR_ERR(filp);
+
+	ret = kernel_read(filp, buf, sizeof(buf) - 1, &pos);
+	filp_close(filp, NULL);
+
+	if (ret < 0)
+		return ret;
+
+	buf[ret] = '\0'; // Safe: ret < sizeof(buf)
+
+	*enabled = (buf[0] == '1');
+
+	return 0;
+}
+
+/* Function to check the TrackPoint doubletap status */
+static int thinkpad_set_doubletap_status(bool enable)
+{
+	const char *val = enable ? "1" : "0";
+	loff_t pos = 0;
+
+	if (!trackpoint_doubletap_path[0])
+		return -ENODEV;
+
+	return write_doubletap_sysfs_value(val, strlen(val), &pos);
+}
+
 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
 static ssize_t hotkey_radio_sw_show(struct device *dev,
 			   struct device_attribute *attr,
@@ -3326,6 +3435,8 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 	bool radiosw_state  = false;
 	bool tabletsw_state = false;
 	int hkeyv, res, status, camera_shutter_state;
+	bool dt_state;
+	int rc;
 
 	vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_HKEY,
 			"initializing hotkey subdriver\n");
@@ -3557,9 +3668,22 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 
 	hotkey_poll_setup_safe(true);
 
-	/* Enable doubletap by default */
-	tp_features.trackpoint_doubletap = 1;
+	/* Checking doubletap status by default */
+	rc = thinkpad_find_trackpoint_path();
+	if (rc) {
+		dev_dbg(&tpacpi_pdev->dev, "Could not find TrackPoint doubletap sysfs path\n");
+		tp_features.trackpoint_doubletap_capable = false;
+		return 0;
+	}
+	tp_features.trackpoint_doubletap_capable = true;
 
+	rc = trackpoint_read_doubletap_status(&dt_state);
+	if (rc) {
+		/* Disable if access to register fails */
+		dt_state = false;
+		dev_dbg(&tpacpi_pdev->dev, "Doubletap failed to check status\n");
+	}
+	tp_features.trackpoint_doubletap_state = dt_state;
 	return 0;
 }
 
@@ -3863,9 +3987,7 @@ static bool hotkey_notify_8xxx(const u32 hkey, bool *send_acpi_ev)
 {
 	switch (hkey) {
 	case TP_HKEY_EV_TRACK_DOUBLETAP:
-		if (tp_features.trackpoint_doubletap)
-			tpacpi_input_send_key(hkey, send_acpi_ev);
-
+		*send_acpi_ev = true;
 		return true;
 	default:
 		return false;
@@ -11194,6 +11316,7 @@ static struct platform_driver tpacpi_hwmon_pdriver = {
 static bool tpacpi_driver_event(const unsigned int hkey_event)
 {
 	int camera_shutter_state;
+	int rc;
 
 	switch (hkey_event) {
 	case TP_HKEY_EV_BRGHT_UP:
@@ -11285,8 +11408,24 @@ static bool tpacpi_driver_event(const unsigned int hkey_event)
 		mutex_unlock(&tpacpi_inputdev_send_mutex);
 		return true;
 	case TP_HKEY_EV_DOUBLETAP_TOGGLE:
-		tp_features.trackpoint_doubletap = !tp_features.trackpoint_doubletap;
-		return true;
+		if (tp_features.trackpoint_doubletap_capable) {
+			rc = thinkpad_set_doubletap_status(!tp_features.trackpoint_doubletap_state);
+
+			if (rc) {
+				dev_dbg(&tpacpi_pdev->dev, "Trackpoint doubletap toggle failed\n");
+			} else {
+				tp_features.trackpoint_doubletap_state =
+					!tp_features.trackpoint_doubletap_state;
+				dev_dbg(&tpacpi_pdev->dev, "Trackpoint doubletap is %s\n",
+						tp_features.trackpoint_doubletap_state ? "enabled" : "disabled");
+				return true;
+			}
+		}
+		/*
+		 * Suppress the event if Doubletap is not supported
+		 * or if the trackpoint_set_doubletap_status() is failing
+		 */
+		return false;
 	case TP_HKEY_EV_PROFILE_TOGGLE:
 	case TP_HKEY_EV_PROFILE_TOGGLE2:
 		platform_profile_cycle();
-- 
2.48.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ