From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 B76AF3E0C7E for ; Mon, 20 Jul 2026 10:14:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784542492; cv=none; b=Hq6FZKaBALobotyEX5G3ovhO19RRfH/NbNHopO0Hwx+uXxky2+qDSR1yhZuewdAwQvovhMJXjj7tPGuHmVr3FWD5/sKyGpPOS12v6oT6kAXLBwGaqVxNLdTuymZoykKCEIRReKTjLnnJWDo3S8EqgfLPr6t5xHxa5fWwfR622KY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784542492; c=relaxed/simple; bh=4olgis/+UK7LivGkbVIiRcuHyl1sNyQgXPWAGbpQwxE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BP81oxDfwSl7yMcacivc9o5Vyht3n3BRMwa3UY5yYTWKwMmRyY5FJwJ7Rz4MyiOXgagZTpfNgxvebGYkb5o2IQbO++Rfqtkc964TFvWmOh+EC+YebVQvH1ykWgvubD4/GgQTZlmtB6PbUb2zIS6T91oSh8Vm/EC7w3KDGMj7xzY= 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.210.176 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-pf1-f176.google.com with SMTP id d2e1a72fcca58-8485ef63b68so9586698b3a.1 for ; Mon, 20 Jul 2026 03:14:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784542483; x=1785147283; 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=qUJCDmAKuwvWzvfCdV4S2qqsvo7USEen3xkhjOW/vGU=; b=GKKDrY5A+sfU/mFrHQRUymw3YC1ZjIDIjZ87gZYGMrIHZlczddPmidUQZJAslNfOXH CiPojA4tqXZ6hAhPaLeqLO03cU7r4GmT6GUIj1O8R+nvmA0r9BVDCnYtQwHTRZuBnCV2 9emceLaOkudr92XrKqOd7OWssInQ2jUfk4+gqiKYVdhPmQPthRbJufEjrsr8OHOqGf0D CLh49dJ2DSZcCeg4B+EBDNBsj0FUVdBjZLAVjIMPM+EsUwTY/YMGCaSCRvqfpo+PjpSc t3HZfQgFKNCdFluJaQWrScAZ6sntg0cOTecRjmaqMFp93CGqXTLcZhLUKXHuJkU9zygy S0JQ== X-Forwarded-Encrypted: i=1; AHgh+Rr8gv7JJF2fApFoReyRbnyjycnkk98BFG1THdDCi90mXOm8ycgP/K1T0lEjTixUS5GnDEdR+jUET6iNXtE=@vger.kernel.org X-Gm-Message-State: AOJu0YxwwsvVkrHZ2nG4iSnvUn1nUChTjwkmfV8XhjOJycDNb/EmEQZF pdBvV22mjACE0ajeApNKulwBAjhPIBtbu8EImSzbOuPQdxaLzemwN/Q= X-Gm-Gg: AfdE7ck5jU0gXxN0xiLDrekcxGpsmqObfkEHdLjfyeiwLyyk8bbUn3yo/wyjVTt2kjQ rCmguvburAzwJNe3W+YBJMYOMq5EoReS6HFd33w1EOwTlwTx2HCHn0bYtVZEu3V2emsNC7HVlni RD20OafirIxa597KuGfTXwYpMZ4FGGOogHi6GQGLXaBh/LdgFu2/lRHLZPI2phsltLsUphpiQW5 ATongzdSqcxqzTAUn2tBWgMq3mW4DZ6rtSBvj4ouN4ZtiZ8NslxrEZZMIIbPgKMuBBYi8wBSVjs XXe8yPF/wwc2n6W6w+3OTcsQfFkO3tsD/IlY+JZgU1eolWYfAykmdOvi3DSSPHkggCeoB2JQb5J 20VV+weYwt1M2wlaPwV9SfVSHnqrF2pwKqm60j18gekGQpvRNwNKWMO08s8nvf7mVJtVK6CNWqz OZedQ0m8Y0SrYIqvlLFyaYiVuiDRqoLedslXO7kBkQrT7yQJlFNbsbHGsP0PdRZs4tFASI7Kgz0 mg/HgZN3V7jt+RI6A== X-Received: by 2002:a05:6a00:1f09:b0:845:e440:d0ca with SMTP id d2e1a72fcca58-84c292a0323mr13167391b3a.8.1784542482681; Mon, 20 Jul 2026 03:14:42 -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 41be03b00d2f7-cb517f94c31sm4411321a12.13.2026.07.20.03.14.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2026 03:14:42 -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 v2 1/5] Input: applespi - use unified wait queue with timeouts for drain Date: Mon, 20 Jul 2026 18:14:31 +0800 Message-Id: <20260720101435.13612-2-fourdollars@debian.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260720101435.13612-1-fourdollars@debian.org> References: <20260720101435.13612-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 The driver currently maintains a dedicated wait queue 'drain_complete' specifically to wait for outstanding write requests to complete. Consolidate this with other wait events by renaming it to 'wait_queue' to make resource management cleaner. Furthermore, using wait_event_lock_irq() without a timeout risks blocking the thread indefinitely during driver unbinding (remove) or PM transition phases if the hardware fails to respond or interrupts are missed. Replace wait_event_lock_irq() with wait_event_lock_irq_timeout() in applespi_drain_writes() and applespi_drain_reads() with a 3-second timeout. This ensures the driver can gracefully recover and avoid lockups under unresponsive hardware conditions. Signed-off-by: Shih-Yuan Lee --- drivers/input/keyboard/applespi.c | 32 +++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/input/keyboard/applespi.c b/drivers/input/keyboard/applespi.c index b5ff71cd5a70..64bbeba85ea9 100644 --- a/drivers/input/keyboard/applespi.c +++ b/drivers/input/keyboard/applespi.c @@ -417,7 +417,7 @@ struct applespi_data { bool suspended; bool drain; - wait_queue_head_t drain_complete; + wait_queue_head_t wait_queue; bool read_active; bool write_active; @@ -677,7 +677,7 @@ static int applespi_setup_spi(struct applespi_data *applespi) return sts; spin_lock_init(&applespi->cmd_msg_lock); - init_waitqueue_head(&applespi->drain_complete); + init_waitqueue_head(&applespi->wait_queue); return 0; } @@ -725,7 +725,7 @@ static void applespi_msg_complete(struct applespi_data *applespi, applespi->write_active = false; if (applespi->drain && !applespi->write_active) - wake_up_all(&applespi->drain_complete); + wake_up_all(&applespi->wait_queue); if (is_write_msg) { applespi->cmd_msg_queued = 0; @@ -1415,7 +1415,7 @@ static void applespi_got_data(struct applespi_data *applespi) applespi->read_active = false; applespi->write_active = false; - wake_up_all(&applespi->drain_complete); + wake_up_all(&applespi->wait_queue); } return; @@ -1793,21 +1793,33 @@ static int applespi_probe(struct spi_device *spi) static void applespi_drain_writes(struct applespi_data *applespi) { - guard(spinlock_irqsave)(&applespi->cmd_msg_lock); + unsigned long flags; + + spin_lock_irqsave(&applespi->cmd_msg_lock, flags); applespi->drain = true; - wait_event_lock_irq(applespi->drain_complete, !applespi->write_active, - applespi->cmd_msg_lock); + wait_event_lock_irq_timeout(applespi->wait_queue, + !applespi->write_active, + applespi->cmd_msg_lock, + msecs_to_jiffies(3000)); + + spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); } static void applespi_drain_reads(struct applespi_data *applespi) { - guard(spinlock_irqsave)(&applespi->cmd_msg_lock); + unsigned long flags; + + spin_lock_irqsave(&applespi->cmd_msg_lock, flags); - wait_event_lock_irq(applespi->drain_complete, !applespi->read_active, - applespi->cmd_msg_lock); + wait_event_lock_irq_timeout(applespi->wait_queue, + !applespi->read_active, + applespi->cmd_msg_lock, + msecs_to_jiffies(3000)); applespi->suspended = true; + + spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); } static void applespi_remove(struct spi_device *spi) -- 2.39.5