From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E52403ACEFF for ; Mon, 20 Jul 2026 16:22:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784564556; cv=none; b=sjVUgrQhWf50VITz8/5eikPx2vY3haWeWizO1xnfFvqAtmpT2xAxWepVt5Bmh885KmrE3n9TQRAhSB5w4+e3qTwn0KKX36gqrC8GvguAaxcL/nTkVTRZJ3MXO0SjIqejv6nRzexBCeNzNZsYdpxzaE8McqkT/yFjV5rfFXGW0Xk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784564556; c=relaxed/simple; bh=lMEL/guzYTtbgyFldhZtTjCpjd6NFbDQi30FdOkNlHU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=l3aj8ldYLUK886g7RLu58Fa7wG5+y8v6mYc6f4hItoOj8cJ8SPmCelFEpX+9nno/uv8s6pJ6s9ESrVFVenEtILLTHe7v1Vc+fL0HSpuC31WW2KvDa8CtXm04NkQNxf4OHp/KMgj9XROdUIc/j/omNSGbQnd89wGzFClxvC4DWNY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.216.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-38e041ea211so8163116a91.0 for ; Mon, 20 Jul 2026 09:22:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784564549; x=1785169349; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=4QSVvjgeOnTqjGkk31K3nbyNNkT3S+X+wqvMTCP4ZKo=; b=GgvHqzmEiO+YaUsJAlPh5kTymvgWWr9BbG/Yi36MxnImPHZrKjh20OwlInLildzIM/ XwtJB2QKR2hW76/+UeyucnDl7gym6KQUlG8sE7FrMAoFCxxLSCNUpScfL/r6mmiw3lOC u9vwWzIp1UZyv30s+vTMxByZhccd8JXaaNS3iuPNIG7Y0cFwNEPo1ebmhRW5sj0i1FrV 4kMo5e7UeWXOewx66vlmGhWgIZMqkLXi4OhadsbpWkyqFHMK2d0Iq9Ieu5HHz/uSERrQ EcTDDDbAHdIt7lCnvKbsDTK45soNcPmV2BFnptda+gnfhm8cVEzhAp6jAlHJtD2+/TgK /FPw== X-Forwarded-Encrypted: i=1; AHgh+RrCiljyUCL2KxTwBE4Nj6+GN+Z7th6E8Ft38QLCRtSKE1le9W+ph/cqv/n8hO4n3isOQfpS62i2Y9ZiHtk=@vger.kernel.org X-Gm-Message-State: AOJu0YyPIB2UqgWri5TbPbj18LDqTkMmhkM/zukWj5+I4giqVoaSlF5T UwUF0pspRLESQcAdiANYR2i9PxrF+IKEvKdwExA2YI6Hqp5HCA7ubjE= X-Gm-Gg: AR+sD10+SGeQWzL9vbRKRPaQP6tXvBQ3/hyTgsctWtcUEaIXm3HD3oAb8/Qszg6h0hU x11S0QvxzIREte21ReEz6ptvJb8tU+vjzn8VH0zE/aY8cPONcjSbJBH2iPrKJWUOiKGVAfZG6eX qX1xfEWt3wZOEEaPIvjKcHehrDYTGXCvSUisKa20hueVOWsA+viVpEAsvHiGs8SkcL1xayFZyU3 nw9xe5ZDMIRGIYuBtfkTEIGYXaveeyG4um2Y8mJERgYwAeMOOZbkZIdpJ7XG8QBMVEiYkmgVm8E w/rMDo6+pUIi3ayCkuGIEx4sUOeVrP9z9T8MXlki2kaogAzjA980+w+B6VJq0+3PPQc41DrwqUr Zk1cw6aeiW67VRih5+O4or1bDtmuxEJsSoiU1+DWI5derPHXOajmbDlgTxxaPGy7lbcs4qtcRY/ 3ypnyKgOI9Vi/lNi3+YLMol7RNkX+31BB1+M/Y5T6osErfeEq1sCsLFWWBu4g5pNF7VL5oyWwQd YVEZsLi+o/jQVHg2w== X-Received: by 2002:a17:90a:d646:b0:381:50ab:1594 with SMTP id 98e67ed59e1d1-38e4b51be59mr16272082a91.27.1784564549188; Mon, 20 Jul 2026 09:22:29 -0700 (PDT) Received: from penguin.tail0a1999.ts.net (61-228-16-100.dynamic-ip.hinet.net. [61.228.16.100]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-38e9205d358sm29366a91.3.2026.07.20.09.22.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2026 09:22:28 -0700 (PDT) From: Shih-Yuan Lee To: Dmitry Torokhov Cc: Mark Brown , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Shih-Yuan Lee Subject: [PATCH v3 3/5] Input: applespi - register touchpad synchronously in probe Date: Tue, 21 Jul 2026 00:22:17 +0800 Message-Id: <20260720162219.32324-4-fourdollars@debian.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260720162219.32324-1-fourdollars@debian.org> References: <20260720162219.32324-1-fourdollars@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Replace the asynchronous worker for touchpad registration with synchronous registration during driver probe. Wait up to 3 seconds for the device info packet and fallback to keyboard-only mode if a timeout occurs. Prevent a kernel panic in debugfs by checking for a NULL touchpad_input_dev in applespi_tp_dim_open() before dereferencing it, returning -ENODEV if the device is operating in keyboard-only mode. Protect rcvd_tp_info from data races by creating a local copy under cmd_msg_lock before passing it to applespi_register_touchpad_device(). Signed-off-by: Shih-Yuan Lee --- drivers/input/keyboard/applespi.c | 60 ++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/drivers/input/keyboard/applespi.c b/drivers/input/keyboard/applespi.c index c9bbceaf0671..6db4eeca3060 100644 --- a/drivers/input/keyboard/applespi.c +++ b/drivers/input/keyboard/applespi.c @@ -427,7 +427,7 @@ struct applespi_data { } spi_complete[2]; bool cancel_spi; - struct work_struct work; + bool have_tp_info; struct touchpad_info_protocol rcvd_tp_info; struct dentry *debugfs_root; @@ -1030,6 +1030,9 @@ static int applespi_tp_dim_open(struct inode *inode, struct file *file) { struct applespi_data *applespi = inode->i_private; + if (!applespi->touchpad_input_dev) + return -ENODEV; + file->private_data = applespi; snprintf(applespi->tp_dim_val, sizeof(applespi->tp_dim_val), @@ -1390,26 +1393,20 @@ applespi_register_touchpad_device(struct applespi_data *applespi, return 0; } -static void applespi_worker(struct work_struct *work) -{ - struct applespi_data *applespi = - container_of(work, struct applespi_data, work); - - applespi_register_touchpad_device(applespi, &applespi->rcvd_tp_info); -} - static void applespi_handle_cmd_response(struct applespi_data *applespi, struct spi_packet *packet, struct message *message) { + unsigned long flags; + if (packet->device == PACKET_DEV_INFO && le16_to_cpu(message->type) == 0x1020) { - /* - * We're not allowed to sleep here, but registering an input - * device can sleep. - */ + spin_lock_irqsave(&applespi->cmd_msg_lock, flags); applespi->rcvd_tp_info = message->tp_info; - schedule_work(&applespi->work); + applespi->have_tp_info = true; + spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); + + wake_up_all(&applespi->wait_queue); return; } @@ -1677,6 +1674,7 @@ static int applespi_probe(struct spi_device *spi) acpi_handle spi_handle = ACPI_HANDLE(&spi->dev); acpi_status acpi_sts; int sts, i; + unsigned long flags; unsigned long long gpe, usb_status; /* check if the USB interface is present and enabled already */ @@ -1694,8 +1692,6 @@ static int applespi_probe(struct spi_device *spi) applespi->spi = spi; - INIT_WORK(&applespi->work, applespi_worker); - /* store the driver data */ spi_set_drvdata(spi, applespi); @@ -1823,6 +1819,25 @@ static int applespi_probe(struct spi_device *spi) /* trigger touchpad setup */ applespi_init(applespi, false); + /* set up the touchpad as a separate input device if info is received */ + sts = wait_event_timeout(applespi->wait_queue, + READ_ONCE(applespi->have_tp_info), + msecs_to_jiffies(3000)); + if (!sts) { + dev_warn(&applespi->spi->dev, + "Timed out waiting for touchpad info, continuing keyboard-only\n"); + } else { + struct touchpad_info_protocol tp_info; + + spin_lock_irqsave(&applespi->cmd_msg_lock, flags); + tp_info = applespi->rcvd_tp_info; + spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); + + sts = applespi_register_touchpad_device(applespi, &tp_info); + if (sts) + goto cancel_spi; + } + /* * By default this device is not enabled for wakeup; but USB keyboards * generally are, so the expectation is that by default the keyboard @@ -1855,6 +1870,19 @@ static int applespi_probe(struct spi_device *spi) &applespi_tp_dim_fops); return 0; + +cancel_spi: + acpi_disable_gpe(NULL, applespi->gpe); + acpi_remove_gpe_handler(NULL, applespi->gpe, applespi_notify); + + spin_lock_irqsave(&applespi->cmd_msg_lock, flags); + applespi->cancel_spi = true; + wait_event_lock_irq(applespi->wait_queue, + !applespi_async_outstanding(applespi), + applespi->cmd_msg_lock); + spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); + + return sts; } static void applespi_drain_writes(struct applespi_data *applespi) -- 2.39.5