From patchwork Thu Sep 5 04:17:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791681 Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (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 726FB1552E0; Thu, 5 Sep 2024 04:17:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509868; cv=none; b=G/cUykWofGONwULkza4zMHfmSgJk5mFrcs3jpwPydb6eYLvmGwO9bWI0cBU40Hjr/6nVA6QUBBMQ2dJmceqNMwsJF1vEFPQqUN2F0ewg8P6NURUqKfCm4hydvE+CZXbY4ejUFVQlumJ44F63jgSpiE05RFB/yDFpxDGvjrdfsgE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509868; c=relaxed/simple; bh=6p25Gf4otRQlWovvwdYJlg/QmPufJ3SpgDun2WG9K0U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ub2+hHRbcVLH0yPgmvOQxRdMyVUyuU2cLY/oxI9GdhPkhorwL9HqrYL1oPHWcgCl5QB3bZYfqvY35isBtAhHvCdE3tbe0Kh4NIHfj9XFxXfZ5+5z/8Pkw9I5LrNQ8ZTgp5KJSg+h7VOjvJgpqYDZpRRwAJdrnCM6GU5SVoDtPwM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Nso2Bgyr; arc=none smtp.client-ip=209.85.167.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Nso2Bgyr" Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-3df096e70f1so170311b6e.3; Wed, 04 Sep 2024 21:17:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509864; x=1726114664; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jSQ5nHDaIzTNEy48GC2iLuCGQVf+qFQuSKyHZ16Sx1U=; b=Nso2Bgyrn4QIQVh3Jncgdo91yYrdPo+4UOO5KySe+bwhrDXvI0JRmjsXxZaDUjJoet Aqs1/hVHLBDbu95URtZAWWKNQbt/wCcl5culcVJmyAEzOwSeMbex1SboPqnY4egRdKOd 9EyhSS6WGVGhKqGxlx+PiTlx4QBeS7+K3a5beTcm+Szbbc7lVmwzpR3HAJIfI9G+05W/ 6D8vPU9MPJejYHXvdJ3Q3db27jCHGRtivVXXcGdxJAKw7tE+nNdOpnurljrSNtxTkzMz snvMPrKbf4LqXQ6rwPmIdIihJNxSvD1Lf4Z2IU3l9Nbz3XhWZcJRJyqZAgz+uDr4kR2D e0Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509864; x=1726114664; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jSQ5nHDaIzTNEy48GC2iLuCGQVf+qFQuSKyHZ16Sx1U=; b=iKbOFaFetas7SNEwyf5Ted0hH4rfAbZCR6F/mclYwReP1LMPzwR67PXVLnOVUum0jF /JeHSvbewQm0PvnGqlgQ79N3rufK33WFXYUT2uufjbwvueMnmK9YUO9nOSCj77k5HbFh hZZmuIcHbhPRW/ZHWvscqnjLqStMTlaUV+re80HmXrtQ1myR1B2lzn/8nhbxFeLeukMe RvMre3cvawWco6qgiPHPc9Pkzbipk0cScbt8qfLH/pwkvnltZMljmPAMTd4BHmEmro5K kqfzZolfotDqJdpAjcN9kuxhCcfP/Z6TK2zXoxepjRZRY1mP+6vTTgA8ZNJE5KCR6/0r 0UnQ== X-Forwarded-Encrypted: i=1; AJvYcCUNPWZQknYBtGMEh9+LR8I6l0ePWoUARKC18AhPWClRa2d/NVfMe7XzqfZtfKMBBHKJcto3V11Y6gOcXKVH@vger.kernel.org, AJvYcCUdj9vcWneX/Zg1UlHHell7Wd91QS5IW8/zmFlmA+vp4Acivzf8YOWNe5scOU61mx8aWba7l80VC52+Fbc=@vger.kernel.org X-Gm-Message-State: AOJu0YzXaY+Qk5SeSHSAEsF5YuL6aBFunZkMgXtm4MDmC/4BA/1P2GTV WVvqv34Ocbk3X/ySNKmi53BQy6Ob6rOfLtqvlidyHSPjfEG1L3/sePUQKA== X-Google-Smtp-Source: AGHT+IFOWA+kffVJfvYihB03juJQybTpapwcpoQKqlaiy/ZyXN6NKX8+I0jp6NbDCWaxTJ0rpgLL2A== X-Received: by 2002:a05:6808:10c3:b0:3d9:e109:a6d3 with SMTP id 5614622812f47-3df1c98f83dmr19335301b6e.26.1725509864123; Wed, 04 Sep 2024 21:17:44 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.17.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:17:43 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 01/24] Input: serio - define serio_pause_rx guard to pause and resume serio ports Date: Wed, 4 Sep 2024 21:17:06 -0700 Message-ID: <20240905041732.2034348-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 serio_pause_rx() and serio_continue_rx() are usually used together to temporarily stop receiving interrupts/data for a given serio port. Define "serio_pause_rx" guard for this so that the port is always resumed once critical section is over. Example: scoped_guard(serio_pause_rx, elo->serio) { elo->expected_packet = toupper(packet[0]); init_completion(&elo->cmd_done); } Signed-off-by: Dmitry Torokhov --- include/linux/serio.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/serio.h b/include/linux/serio.h index 1911827bbe0d..f4ca0aa37553 100644 --- a/include/linux/serio.h +++ b/include/linux/serio.h @@ -6,6 +6,7 @@ #define _SERIO_H +#include #include #include #include @@ -161,4 +162,6 @@ static inline void serio_continue_rx(struct serio *serio) spin_unlock_irq(&serio->lock); } +DEFINE_GUARD(serio_pause_rx, struct serio *, serio_pause_rx(_T), serio_continue_rx(_T)) + #endif From patchwork Thu Sep 5 04:17:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791682 Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) (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 6357A34CDD; Thu, 5 Sep 2024 04:17:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509869; cv=none; b=XP2seQk0mncqHB4Ui+1VoYxKULxcytwFLvH02xBGFrUFnedLx91nkSY7OEftKxWS5Laih/VrxFVIni1VZe2YVb7c4p2XlIPgpMXCg5/T0VOJLYu92AJhZNMnht63AHn9L/El7+uAVOyDX4P4p7YNCk2gUQfkF0W6zSTsN30BOJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509869; c=relaxed/simple; bh=lhvjV7Fn/6qUD++5apj3ZBU0dququYNw1dir73W7S1M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OBfxQg3kqWl6+6n1NpNEoEGt4ATJg9esBFIHCNWxVSHueL2ej4Za7FiSrsfFmZJSP1Jioub+FWVkFMatgqt26r6bQrN5xM/P25paLna7XMhdQJTpsImyuY29B8zvgaFyCtK97AwVkSYj5Zx+CYaLPLU41sjUykV/pyhL8W29q9Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Qy0P1ySN; arc=none smtp.client-ip=209.85.219.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Qy0P1ySN" Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-e026a2238d8so391988276.0; Wed, 04 Sep 2024 21:17:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509867; x=1726114667; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YscGpXPa0igYUdPp8o8oV5VkpUTxqWDGqD7B4LMXPvo=; b=Qy0P1ySN7KgYG8qOa0/KeJen+sZ9pDq1VCUbDsa5/OjXhukBIKi+y7VrBoLKEkBK03 W/1eQReeRWJixHkmteNYbBgQmJHbN8hbD5l69xYJmE+L26C4sSUM9hYe95/lxBqGeOlg ePXUnWQIccLBMgoNZBuPcaXQE8mAIP8xFMiErLaeCMALcU3irjMDY6Oeg/2ZqGpCTdo0 vxlWXKwoCg3IQtqqwJRUuJ353NBN8XYD/pzuw4wqXI7R2iz5P3glyLXA6JScNUZATdzf 1dAZHSBiNEiMevp1metbC+AL7u8Fkhdb9+0rkwqXdNFYdLh/jo5HAGI0rmM5UTTvSA/5 3pcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509867; x=1726114667; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YscGpXPa0igYUdPp8o8oV5VkpUTxqWDGqD7B4LMXPvo=; b=fTIM7nlSRTlsiRFUATyD478jylZZeynTygn70F+TI+lBhxUREHBNTJSMMD6FhWuZkI 6M1SU8nothD3EcyUUraWRHKVARFNsxffqYsK1iZL8Vi8CQcnHGSvN2iU3ab3JExP+UZY oycq4yL0n0rZkz225Ky8CP7Ds2hdkEweRTsrHAWGLykvNa0ozMQrCcagu8qDGXLt2x/q MbbGwf1n0/M7EMUeKn/pCofQ18gVjETmjUwWPcgA30m+LQiAKIRJM07aE0AujAqPUV2N m2ci71D4/YXJF5x7KlLBD9w+CdIs8GerGcGbmJjRQbcwzAetmChQTWzGdRyT7l+3WjgV xIjg== X-Forwarded-Encrypted: i=1; AJvYcCW4NG8F79LcOpIVJ5yo0xnyyeZYHXPMj/o+t7Y4wR4e+oezKaceXPNX2iQqaVP4FCKzFdoSboFZG/Z44VQ=@vger.kernel.org, AJvYcCWjMm6QR+VVIjHt/PYo4P1lWQkr+G2ccgXEkmTFX4juV9Vx1fTtjHyTDq2QgFtLw4wBqDKWuxURE1dB+dGb@vger.kernel.org X-Gm-Message-State: AOJu0YzpBDFXw5IjseYjbQRJ6tmSHUa6N+c3u2Uy+y1g3+p+PPfQUDWB S0R49dhEhD0hKN9rpRs2XJdMMu6S9153xOv879IQTvHRIK0uezSKF0bSFA== X-Google-Smtp-Source: AGHT+IG2n4QttKo2Kk6OwZ6xAkRc+KBcDbR2JtYsfVRI0Ayw5MYcw6SGH0iMQHCRmBjRsLLZm2riig== X-Received: by 2002:a05:6902:1106:b0:e13:d834:604f with SMTP id 3f1490d57ef6-e1a7a3cf59emr21411841276.50.1725509866951; Wed, 04 Sep 2024 21:17:46 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.17.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:17:45 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 02/24] Input: libps2 - use guard notation when temporarily pausing serio ports Date: Wed, 4 Sep 2024 21:17:07 -0700 Message-ID: <20240905041732.2034348-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that serio ports are resumed in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/libps2.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/input/serio/libps2.c b/drivers/input/serio/libps2.c index 6d78a1fe00c1..c22ea532276e 100644 --- a/drivers/input/serio/libps2.c +++ b/drivers/input/serio/libps2.c @@ -108,13 +108,11 @@ int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout) { int retval; - serio_pause_rx(ps2dev->serio); + guard(serio_pause_rx)(ps2dev->serio); retval = ps2_do_sendbyte(ps2dev, byte, timeout, 1); dev_dbg(&ps2dev->serio->dev, "%02x - %x\n", byte, ps2dev->nak); - serio_continue_rx(ps2dev->serio); - return retval; } EXPORT_SYMBOL(ps2_sendbyte); @@ -162,10 +160,10 @@ void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout) ps2_begin_command(ps2dev); - serio_pause_rx(ps2dev->serio); - ps2dev->flags = PS2_FLAG_CMD; - ps2dev->cmdcnt = maxbytes; - serio_continue_rx(ps2dev->serio); + scoped_guard(serio_pause_rx, ps2dev->serio) { + ps2dev->flags = PS2_FLAG_CMD; + ps2dev->cmdcnt = maxbytes; + } wait_event_timeout(ps2dev->wait, !(ps2dev->flags & PS2_FLAG_CMD), @@ -224,9 +222,9 @@ static int ps2_adjust_timeout(struct ps2dev *ps2dev, * use alternative probe to detect it. */ if (ps2dev->cmdbuf[1] == 0xaa) { - serio_pause_rx(ps2dev->serio); - ps2dev->flags = 0; - serio_continue_rx(ps2dev->serio); + scoped_guard(serio_pause_rx, ps2dev->serio) + ps2dev->flags = 0; + timeout = 0; } @@ -235,9 +233,9 @@ static int ps2_adjust_timeout(struct ps2dev *ps2dev, * won't be 2nd byte of ID response. */ if (!ps2_is_keyboard_id(ps2dev->cmdbuf[1])) { - serio_pause_rx(ps2dev->serio); - ps2dev->flags = ps2dev->cmdcnt = 0; - serio_continue_rx(ps2dev->serio); + scoped_guard(serio_pause_rx, ps2dev->serio) + ps2dev->flags = ps2dev->cmdcnt = 0; + timeout = 0; } break; @@ -283,6 +281,10 @@ int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command) memcpy(send_param, param, send); + /* + * Not using guard notation because we need to break critical + * section below while waiting for the response. + */ serio_pause_rx(ps2dev->serio); ps2dev->cmdcnt = receive; From patchwork Thu Sep 5 04:17:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791683 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.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 76F3915574D; Thu, 5 Sep 2024 04:17:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509870; cv=none; b=dsZIFF80rI8NO6kMNxaVStQwN6YP3ilMC7V43bTWDAxhizXWY3cgeu4f7gJxlFRdU4sNBmFKz8TrYd166888WU+/6V96Vv7e6TuenSxnAQukD60bY6U+xlMwQjCVnu58+WStcx9xeKJW5J9xrus2E/PjuXCIIP8FePpzKLWEsck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509870; c=relaxed/simple; bh=z+lGZlowZLX9dvF58rYUpc9T2wArxI80gBzLlyOWaSk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p4e/BNTIwsXG9wbcZn0ZyY9kiCZJViGg4XG9q2CG1KK7LojuPhntPEiSHgvs8BdbsxY1Nlk0nULPh48KtomHaeAT23BUQsoo6CDFBGxzhqv8tRnLjprUGmpetfl+HoCQM2drKQoH23OmSujkrc3ZcNIv/X4BKC/4IykTW0E5heA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kyX28won; arc=none smtp.client-ip=209.85.210.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kyX28won" Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-70f6732a16dso268004a34.3; Wed, 04 Sep 2024 21:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509868; x=1726114668; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kOurL+niKTuTYRrWkCUZcFZDU3uO6ZkmtonuLPtkVjM=; b=kyX28wonQbYyvWDeyqReX2vVHkqPHyV1Wm9zdD8yWnATI49DMsOGFp6uQAgcRCTSzF ZKqtKlQX4VaS4gUi7JkxkI4i4GdSPRxDhDyWOybwyuRrF7iN+PL+ipLb3+bZiFluT4Py ln+XorXJe8wBai5cIqgdWLx0AmYbWflawXvai4/8F3ArPByVjd4GEc2zHiY6747CAxMn 5JTY4j4cpB89yLJxA8760ZHvX/1zc/OmKvCwN4nXcRZDzs1a2pPOAhcjaLuF4UHe6ALJ GJLUWQ9v6Tz53uH4uUwcnU1dZkNi4PPME0qaDPS5nahhghqa///qlM/LJrjxSfOD75Jl VdPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509868; x=1726114668; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kOurL+niKTuTYRrWkCUZcFZDU3uO6ZkmtonuLPtkVjM=; b=DyTQBJ1UfDlzuSjtMFQs5JhxrwoNTVzeij6MGvVHvMoZs7iQ+KQABbWCvdlmq2XGaM xkibIsHMguVvolABnHKlyk75U9zB95J7aY6oUo04mKCvcROyvLbHWYyhhhjL6JZGIwwB 7HyWsIkk2tPBPXk2b0TY3r6zMoligQOTg+FELiv/dUu6PPsIcRlsHhKWd3VUWeTShZNk laKNXB1yAFvopJ6+0q5VzHq209QW2boJQA04Nt4hT/BTslSEVcWZ2VFEjaYUlfDDNgTE GkLL+PEudGHJzKm7hL0kw660Tl+oyLtGSr6pt15+b+qJwlR7Hy++Ahgt+pIS0j94+l2Z Ff1w== X-Forwarded-Encrypted: i=1; AJvYcCUn8J5RuhlcHMl0jO1xMmgiNF9sBIPUofRhkDy4x23k3DT6+K9fBNK2qcipPOS8+d3I8TAebaqUvZN2D0qW@vger.kernel.org, AJvYcCXFKRweE8X4uVLvlFo1HCQzavMa+peSODx3DZnMMUmv2aKeT9FRrY9+f5kOkAnoDLwHBrsosZisKrRdTqw=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8blRhDXhmEcOD8Q0gvcMOe0PF+lNshTQ9gyn6kBKHtWrZeprT TASMX+NEGo09dGSPNGZjxYeu1CSZ1Fc0NgF5YEhc2NnP03Y4ypEVUUhY9A== X-Google-Smtp-Source: AGHT+IGv36a3rXrN6zFd3TS7W1uho2zPf6Uqpg1TIUhSE/xaGckBL/aTYfQZ78HZQTFPboprAViM+w== X-Received: by 2002:a05:6830:268f:b0:70a:948c:6b3f with SMTP id 46e09a7af769-710aada57c6mr9102268a34.12.1725509868353; Wed, 04 Sep 2024 21:17:48 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:17:47 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 03/24] Input: alps - use guard notation when pausing serio port Date: Wed, 4 Sep 2024 21:17:08 -0700 Message-ID: <20240905041732.2034348-4-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that serio ports are resumed in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov Acked-by: Pali Rohár --- drivers/input/mouse/alps.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c index 4e37fc3f1a9e..0728b5c08f02 100644 --- a/drivers/input/mouse/alps.c +++ b/drivers/input/mouse/alps.c @@ -1585,7 +1585,7 @@ static void alps_flush_packet(struct timer_list *t) struct alps_data *priv = from_timer(priv, t, timer); struct psmouse *psmouse = priv->psmouse; - serio_pause_rx(psmouse->ps2dev.serio); + guard(serio_pause_rx)(psmouse->ps2dev.serio); if (psmouse->pktcnt == psmouse->pktsize) { @@ -1605,8 +1605,6 @@ static void alps_flush_packet(struct timer_list *t) } psmouse->pktcnt = 0; } - - serio_continue_rx(psmouse->ps2dev.serio); } static psmouse_ret_t alps_process_byte(struct psmouse *psmouse) From patchwork Thu Sep 5 04:17:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791684 Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (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 D703B156886; Thu, 5 Sep 2024 04:17:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509872; cv=none; b=nTetBYk8D3979VD3QARj/HAZkAIxsO7VUiUzVjVeR84x9RvhUrRU//dLLhmGriJdlh4eS8AYhSGxfOxLFJXzfLyZsXl5wTeFYQJJXZWAk06tK9m08IB1zO4nLRkFBwy4bGblsoTGcPz9eFDLOr8dm4Vu4ibNmWVG8LdpVYwUvss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509872; c=relaxed/simple; bh=jD9Ue/cXOL5pkFXSYKDYrZ35NLToW/Fmj0WfDt8SVLg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l9pm8WvMdh1rHTVZPAJoIqQoEepEB/QNkqjrGJdDFDa8o+ia8Remvhhsqn0q+3wCYq80UqfCBBwOTp+k/rQX26TCqMKCdKkS4UJFYEzJB6/RuEY50wuqcwVlQvLT0+VkO5O56e/+5o8BD0/1oDN8WNdJtvYJDSv2p+ex1lVHQJE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ai5gc5AP; arc=none smtp.client-ip=209.85.210.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ai5gc5AP" Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-7092dd03223so112190a34.1; Wed, 04 Sep 2024 21:17:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509870; x=1726114670; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8RnFN3EVlk3VoY/i2sKWDmOIShT35NS9PrPlyqQEJBY=; b=ai5gc5APIYzYm4TmxHqeFhbuDrOqOnqrIqV+WzazqIeN7yte9NrtZTtX9mCeXC8U6J 3HTLujqPnPHmg9ReAri7c3z8EDvfJv7bV4JDxJLRDd79NgVFOMqNBVT3HSSNg/2cA1Li zEny0hUjcesBxh1tijmLfovj6If1KBjPoisvVVUa8Ftx8bLHeo9YsDZl9UCRVJomBwma JrNPUXHk6OWyeFyPCYNWssZRxM3LwnFoiZnzPCUwPulWfFhd+K2imdMbdghb83IeHIQ1 dYjmeRAyKurZMkMNwZIBxcUpEGoGAhXNVAH7Ic4cWicRb2jtjrbAKXQamrDcCCgnzpaz jCUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509870; x=1726114670; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8RnFN3EVlk3VoY/i2sKWDmOIShT35NS9PrPlyqQEJBY=; b=VoUuH9nTXZXAjPSaAzKT5dApZm1F3Kz1mhcNB/JJZdR6bRnIPXCQ/jSOh9ZMQTUWzV kYoQy0QKU/fuPIft/8jzBSqutXNNXXSg/qBPZXXuRmyF9+jHpQ1/aFZ3QsiZz0oROlEv J7XkHgq8biS9NQACaMLWK8qRabL2FP0/KjmoyeSPqdYaGNNtbNkZUgtVYZ6h/MQwdOrv wI7KcNRE3AawGwzh+rfhjhDTPbKQfrkOpqyT3zSaQtX4F19AOxFpX8UDFPHiIREDKDan g1vJwPXRc++9wtQNUxeUfr9NjUY7UDRrw3xrWZ4EfDgQyDQVAeymUiapGIlXIXMB1n3o Pggg== X-Forwarded-Encrypted: i=1; AJvYcCV8spZDYeaiWnZ80Colp9EwUeGfChMtX6lrVbhqHvHOC5GxB1voxFDD/Fk8EhD4/xgfq5zmzLgs3JExne4=@vger.kernel.org, AJvYcCVw+XS0OT0/8nFQZRRFLKunldD1WPOl7B8f0hXR6LXZzSa3YGPYpblaUC+a/CgmJsW5YMepxs2Ya/F/YsVA@vger.kernel.org X-Gm-Message-State: AOJu0YyGiVUBNRCA90RWSM+OHBOhaPrXhn94KCA4jBLzz46td4aBxqWB +4+aqJ3IA0HRZlLNJIc07zogPKUAlYXeXbRncdUeYNCBxLNQbPbY6H0nzw== X-Google-Smtp-Source: AGHT+IErwMioNhwmn1dsG6jz5WUbE6Tfb09I0yh8Z59wc3+setGX3kYdpiz4wU4pA3/BcQ951wC+fg== X-Received: by 2002:a05:6830:2709:b0:70d:f448:575c with SMTP id 46e09a7af769-70f706e362amr17541035a34.7.1725509869713; Wed, 04 Sep 2024 21:17:49 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.17.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:17:49 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 04/24] Input: byd - use guard notation when pausing serio port Date: Wed, 4 Sep 2024 21:17:09 -0700 Message-ID: <20240905041732.2034348-5-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that serio ports are resumed in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/byd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/input/mouse/byd.c b/drivers/input/mouse/byd.c index 221a553f45cd..654b38d249f3 100644 --- a/drivers/input/mouse/byd.c +++ b/drivers/input/mouse/byd.c @@ -254,13 +254,12 @@ static void byd_clear_touch(struct timer_list *t) struct byd_data *priv = from_timer(priv, t, timer); struct psmouse *psmouse = priv->psmouse; - serio_pause_rx(psmouse->ps2dev.serio); + guard(serio_pause_rx)(psmouse->ps2dev.serio); + priv->touch = false; byd_report_input(psmouse); - serio_continue_rx(psmouse->ps2dev.serio); - /* * Move cursor back to center of pad when we lose touch - this * specifically improves user experience when moving cursor with one From patchwork Thu Sep 5 04:17:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791685 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) (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 2FC8A1714BE; Thu, 5 Sep 2024 04:17:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509874; cv=none; b=kOGXJvGwkWlWhC53qL68E2vgE81GjehidsNveAuH2MoQxxR5JaiwIFFBKem7YDFyQgTqd6STD6+9iBwPMAvR6oJYP5VBIRzUl5q81Yx2JP4iL8fvJNyR30hInURirF4ThhdeYmdqWNC+cOx6RWTcZH8TG47SdKoOeRLZkmKq4T0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509874; c=relaxed/simple; bh=GTMszsxFP3FUMteNDzoBJGZ+be0o81i435ERu6zYnMc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VupOeacwCV5ptDU1PIgRirrZT+cGzPbrdSEbMLAmhHg5n3EZmEZcmUNSGjCrYnfqseZvTXq/3NenI9/fFFqciV+GZJQFycMy/5qhDs3oCidxcmwrFVpmf9bzqXNWxwHsNqAv9TasdhRczpCfAKSM2Sv84zL9WETnp4mM8cswNUE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bvTyAI9t; arc=none smtp.client-ip=209.85.167.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bvTyAI9t" Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-3df07fe03acso184744b6e.3; Wed, 04 Sep 2024 21:17:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509871; x=1726114671; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S0EXapSSsCRGMYSuYgIhJLIKriJqRLmvnrfU3aGsX6c=; b=bvTyAI9t2F9FolUWhSfgWsFF76fJQKw/NTnf6MxDFuLyOqVpdimQVaZ1+wT27+DLWi DWX+4POH3AUmGRcIp4oHUyOJXgYCy8e/iGgWa4a5MkwRxOepHGpBoBtgkcRK2Y2GextX XysEp4PrbP/WbhIv4MhQbYbj/6kWU+kI1iFPmyyMuahYflH30ajZxnrmAUd2B534Hg41 eK7Y669/eF8AtBfeS/MThboiY6JNnBPJuKFNQaDWdFZzNm6Ih6Q/FOK1xY1fM0cUlerb MVvHdCOhUsOq4rRSv1F6FAfpW5WLFaCSvJUYY7aXTZ3BAAvM+CAkq2oNXo30LFXE9lDn bk9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509871; x=1726114671; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S0EXapSSsCRGMYSuYgIhJLIKriJqRLmvnrfU3aGsX6c=; b=Csz8xXMmUJZRSFm0S0BMbgdqKbGGlqSoAivBIHfb35PPrFZMXciWnA1BwadD3xEitw ODI5G90H8kZyLY2VhSBY2PAXFqpscUPjGRypJMcNVY5M6vkUizEof4H1f86Pd2xuBDMf ZyL9S/khwIUNGbkASlocT1GaIh8rSAB7QvBDnbbGV4Qv7sSSNFqPl5IHYoMMe7L5b+V1 GAXU8rXJxgz5+lgvA6++kaA4/zDnKVUnkGPGfmU9L0H85NjJi4HkktEki9g7a16+kHeF zw9HUw97MANHJu9zo/8papEtstUXbeu7ORmbcYTIjnE/4+xd2AbMMr4OmlkXxtifOK6Y 1Iqg== X-Forwarded-Encrypted: i=1; AJvYcCWOTJJZ9cypeDQDFozCE+ENlaVn4fE3E/tIOsdmN0lpGvdRYTCTbK+adPZjyFiyKv1/XEvMF/7aIAo7An3W@vger.kernel.org, AJvYcCWSWzq3TjN1naNXWO/bX4TQQJ5CljpV0D65z8xpA9jgBvWSMKgRwPIbIsqfCpXsUUqZczad3NKXkkvmtnM=@vger.kernel.org X-Gm-Message-State: AOJu0Yxw8qIXODev4bu5WrgtsWYSHo1ZBsGkpJy1oddJADS/OobbXm+M 710NivqtcZlTAPy0GX30xzfri9lfthTKNFJqr26QH3Mo4jMJp3pRy+KAPA== X-Google-Smtp-Source: AGHT+IGhPGvVxRbF3Iu8u5rEKkCm3Ue+quK2XnAYIQLdPlMcym1uORvuIvaEIla7+lCAvI2New5hng== X-Received: by 2002:a05:6808:3197:b0:3da:aae9:7182 with SMTP id 5614622812f47-3df1d5b87b5mr19628930b6e.2.1725509871047; Wed, 04 Sep 2024 21:17:51 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.17.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:17:50 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 05/24] Input: synaptics - use guard notation when pausing serio port Date: Wed, 4 Sep 2024 21:17:10 -0700 Message-ID: <20240905041732.2034348-6-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that serio ports are resumed in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/synaptics.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c index 380aa1614442..2735f86c23cc 100644 --- a/drivers/input/mouse/synaptics.c +++ b/drivers/input/mouse/synaptics.c @@ -650,9 +650,8 @@ static int synaptics_pt_start(struct serio *serio) struct psmouse *parent = psmouse_from_serio(serio->parent); struct synaptics_data *priv = parent->private; - serio_pause_rx(parent->ps2dev.serio); + guard(serio_pause_rx)(parent->ps2dev.serio); priv->pt_port = serio; - serio_continue_rx(parent->ps2dev.serio); return 0; } @@ -662,9 +661,8 @@ static void synaptics_pt_stop(struct serio *serio) struct psmouse *parent = psmouse_from_serio(serio->parent); struct synaptics_data *priv = parent->private; - serio_pause_rx(parent->ps2dev.serio); + guard(serio_pause_rx)(parent->ps2dev.serio); priv->pt_port = NULL; - serio_continue_rx(parent->ps2dev.serio); } static int synaptics_is_pt_packet(u8 *buf) From patchwork Thu Sep 5 04:17:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791686 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (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 C3064176AD7; Thu, 5 Sep 2024 04:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509875; cv=none; b=jqJZ/6JEokeAHldV12K9AluDzr7oPayycdRahUznM0F1WuMqGp9XF4Wc+U9Ab+7Mu45wO0u5U+UjWg9IWJHoEfsCI8qMwf0oRNsHV/aIL3cskC9LDBS5gCuzzwzDp0c89mzwj9AYjXjv0WvY31rcBGcmcrD/ufWJ9q7dI+sEjUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509875; c=relaxed/simple; bh=K3lNfpiPv/q6z+V6V8RF6mvsiNWEY/iFwwY6BFi6TGU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k9wwwuNMs0A1WXFSFEfiEp5rAyhJD/bSeEMSb2VB0fAsXgKvZF/MAsWfvKRE3SC8GpD5bEZva5i64zj2FP8e+GXNgK+f6IJMBj2ksKwggd1xV1OsTeqO7ijI+6qwNiR095AHJFBM0kqZOMq5HKvsTOgIItIKQJZb4o/+HdbYGUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XbU5zWSh; arc=none smtp.client-ip=209.85.215.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XbU5zWSh" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-7cd830e0711so220030a12.0; Wed, 04 Sep 2024 21:17:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509873; x=1726114673; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T7/TrOieKDmokvB+76CstcAo/MHXLXuZvmD2LpyYQbI=; b=XbU5zWShgI/YkYhjSPPQow7zNGaV49Y9dd7lD3xz56fnSPzXjCS7+VmHfMTRGx6vQR JKjsTJKn43z+Ff4PzeDupAuP2jx9QPMzccPergBh5mzrndzm0xNnPQpCV7GHG+XWz2Ao tkyy4qblZv+2zX1hjs6+3ixnQfGICN/u19FY7I17KI+fxiLYjf+SFZRhh72tO9OUz3IR 1s2+YmdzcgXbSJ30EH+ULjooN0Ig4U7P7Xh2rxxgzOLPK51+6revZBfywsmWILWWl3xu P9fmUm7h8f7BSGa11TMcqbgZsVZEVqkbhk+nNqDLtu4KfGt/cnsZGs6hUPBkmPBzqYcM ozAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509873; x=1726114673; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T7/TrOieKDmokvB+76CstcAo/MHXLXuZvmD2LpyYQbI=; b=fufy1ikHT0IxFbx90EUBWxU1qHaJeYMjnCDoPTTKSxqtMliZh/9aZnNX2xzq/+0KiZ QlRvx71hWpTshnZD3oW666TwWVryLo19esV4wlJ/RLtt+/yeRa7ScRnpRv+lJN8sXXlY 1sZ8tMDeYX77cH7Yd0cE0oFyAu8IVYM7IATYGLAjpgMSpEtt5QOVkEUq9clG3yE9pPA0 XxW2vEj/eq5B9QvdRIK1kwQbBVem0IBzOWcXcHuQk1nC6uGX2iwjDHurtmlneO7p7Eis 1G4LsdsWswMH342ndTqXJmo9sOIhkfY13Cv+qIrOIJ7lslalsSuBtvMT8Y+Uja01j2kG P7yg== X-Forwarded-Encrypted: i=1; AJvYcCVjmv/j1xCD8/ooD0YpaWzgkBiyfkxKjNUsd9e5grhFjzXOFqM8in8p+jI7rAc2QO2b8eIBseeEToHovDw=@vger.kernel.org, AJvYcCXhjIG2m2ch7lPpHWkYfvR2icMGdXL+a1olG+oNNGShGxt2KaCXSykTdpuZjhflUnUbIzKx4mEmJR02FJpW@vger.kernel.org X-Gm-Message-State: AOJu0YzcCQfKBM8Qj4zwgb58b++igA8oMWlOoxlg/P7eV+q30TptR3co TsFhJo93aHNT8hejtmxswWW4wqNyO3gUzruEDb3goXNXt4BUD6/ZGMv+dQ== X-Google-Smtp-Source: AGHT+IEVTNgBOGvJQB0FLDExyZ1paUWKmbJHsocyoE4L6WqC4aDyBtqt1vWJsKWhqiIBmoYibKVEkg== X-Received: by 2002:a17:902:e5ce:b0:206:a6fe:2343 with SMTP id d9443c01a7336-206b7d0aaf2mr83347615ad.8.1725509872338; Wed, 04 Sep 2024 21:17:52 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.17.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:17:52 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 06/24] Input: atkbd - use guard notation when pausing serio port Date: Wed, 4 Sep 2024 21:17:11 -0700 Message-ID: <20240905041732.2034348-7-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that serio ports are resumed in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/atkbd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c index 5855d4fc6e6a..ec94fcfa4cde 100644 --- a/drivers/input/keyboard/atkbd.c +++ b/drivers/input/keyboard/atkbd.c @@ -713,9 +713,9 @@ static int atkbd_event(struct input_dev *dev, static inline void atkbd_enable(struct atkbd *atkbd) { - serio_pause_rx(atkbd->ps2dev.serio); + guard(serio_pause_rx)(atkbd->ps2dev.serio); + atkbd->enabled = true; - serio_continue_rx(atkbd->ps2dev.serio); } /* @@ -725,9 +725,9 @@ static inline void atkbd_enable(struct atkbd *atkbd) static inline void atkbd_disable(struct atkbd *atkbd) { - serio_pause_rx(atkbd->ps2dev.serio); + guard(serio_pause_rx)(atkbd->ps2dev.serio); + atkbd->enabled = false; - serio_continue_rx(atkbd->ps2dev.serio); } static int atkbd_activate(struct atkbd *atkbd) From patchwork Thu Sep 5 04:17:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791687 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) (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 1A4241714B2; Thu, 5 Sep 2024 04:17:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509876; cv=none; b=U5d6LIK5oX28ZthgnEzmk4IUXgjWULasOLGn1ICC2ROhVosjluXdsX6QPe6KMNM7hgrJhQegkDg6Qkv1nnzFXdLSrBmOprHffpw8auWqz8LeOU6eXXNg8uHXmvH8I2LdGkrozBAT50U3ZQmF2ATPq5Gs5jeyIGvp7msuA8b1vx4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509876; c=relaxed/simple; bh=BenMc1sLXCG+5vmkHGPDz29enhWQ1tx8bPuULH06bMo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SgZmuuOgLLG1gRNyirFC1pM/PfD2W4NS6i7rVkLUi+3BUlcTEydb3R9acruTwm9zERFoMMxrK6305GS7eGrfJdU1tf46z87u+m91AaS8vOICys8P3ZUlzyWqwddc9Xct3DDh/OHhnx6OC6dXLSzeF7VlrTORrlrjhRcdAxH2XEY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=htwOStRQ; arc=none smtp.client-ip=209.85.161.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="htwOStRQ" Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-5e017808428so224216eaf.1; Wed, 04 Sep 2024 21:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509874; x=1726114674; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j8VPXswHBHTUlmDFHKrQ5BC1wv3BR4y3AP5bfe5KlEs=; b=htwOStRQ7J6xBt/RMC8R8qa2cIMgxhVe6KJaTNZhIDLAfZPEjJ7S1qcPjlrPb+xOQZ kwHqwPGTsyc74GB1ehwt8w9mxdpEJNM4c8b8kDplIlDb7zga0v3ZuTSh0SFQcHIGyf2u xC7ggh93hUToCJ9rZg09kCqIWfHOBJ7jnpqESA7J8Zr3bxPkPiAwGyJRn675AzWNu3t0 ZwLfr9UibxWTs2FhEYc8qwA7qRddm6qVOsisE7ve+7OCycSPSrIA8Ek63Z0vObT/a95d S+YS4RI3TnWnDfzDYYeto8/engvdbSm9FaZE0IWWyum55iL2Y0d+qDM5HCrR8Z8xUp1O tvCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509874; x=1726114674; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j8VPXswHBHTUlmDFHKrQ5BC1wv3BR4y3AP5bfe5KlEs=; b=kvgw+3OKAfj27ukEhVb1NzZGBWUuUhCnS8UWh1LVSLYOT7FwOltqzT7Zm101qd/g+b UqGH9BzYEuHcwAConcUQh9xx1TR9cNxm/RHefIfmSdWDgEWbs0PSQXfGsOESuzFf0o/n SbcNnyt0hDud12wAM8SE47MemBYp6kxT7nmOsjU8K6G7pZSd6WZc3KGfphejUmBB7yJx HNVSnGH76/Ew6/Cx/xyjJnbjKUXvidm5RBQDNJ9hHevpVVbyupV9vuY3bil/xu4sZQSF PEIn1l7ZWmpLbaqqXfUjPgIqEET5WrsrC8vV/Hx50UpU9Sg5HU8zgmcZRvH+egHRWWsA CEHA== X-Forwarded-Encrypted: i=1; AJvYcCVCylg8thQF+xqnjEV8+fcmIX6LH2OzRexN4z51jFOLExIUnqqPqkjx3kx1fGkXUU+gpc6zJRZJcq51fnY=@vger.kernel.org, AJvYcCVhfX/Uga+sk7Pu0coT4tLnIZFDN4WHM3qZpKoKdYT53gcjXkow9MG9KbpiZ9LocE8K+HdI7QGBVfYjeUAf@vger.kernel.org X-Gm-Message-State: AOJu0YxHuYyY9DconNtdle3Zm8cnVXunqwzqgK9pR17t92LA65c2MuMs u5yrju1Hu4wO4DL20EP1H7FERJvQEPWpKe+fsdE3Aok3LSoBgYQr7sC1fQ== X-Google-Smtp-Source: AGHT+IGI2QjJK2UofL6z1AHMX7SrEpAd/PMAyIbsnSlBJf71WYXVl7JagSZR9Rgb4HVgwu3bRh55Vg== X-Received: by 2002:a05:6358:898:b0:1b8:f18:3e53 with SMTP id e5c5f4694b2df-1b8117bcb29mr1047970355d.9.1725509874043; Wed, 04 Sep 2024 21:17:54 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:17:53 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 07/24] Input: sunkbd - use guard notation when pausing serio port Date: Wed, 4 Sep 2024 21:17:12 -0700 Message-ID: <20240905041732.2034348-8-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that serio ports are resumed in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/sunkbd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/input/keyboard/sunkbd.c b/drivers/input/keyboard/sunkbd.c index 72fb46029710..3299e1919b37 100644 --- a/drivers/input/keyboard/sunkbd.c +++ b/drivers/input/keyboard/sunkbd.c @@ -241,9 +241,8 @@ static void sunkbd_reinit(struct work_struct *work) static void sunkbd_enable(struct sunkbd *sunkbd, bool enable) { - serio_pause_rx(sunkbd->serio); - sunkbd->enabled = enable; - serio_continue_rx(sunkbd->serio); + scoped_guard(serio_pause_rx, sunkbd->serio) + sunkbd->enabled = enable; if (!enable) { wake_up_interruptible(&sunkbd->wait); From patchwork Thu Sep 5 04:17:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791688 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (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 B4B0D153BED; Thu, 5 Sep 2024 04:17:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509878; cv=none; b=KR7aI0hqgHDlDe+U8i7JoCJuQlXai9p8P48sA5JMvYjdu0XhCiuLThgG6GfK/ANDqRvSBIJnxZvL1y6Ny+8mEHlKMpCHgf+jOozWu88klVAXpyOdPevmgzybXU0D/xY4YUtEliBua35nH7uihDOYQdL0bnd6Bz9LnnekINL75P0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509878; c=relaxed/simple; bh=YBqMCDM4+M0yOaTIf2DxfFz/daeISV5+YgDaRESvbI0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TPMWkMBEqjdsH8V52ax5ldELfCQB0CSoUexmK1B3w7gz9auFZZyW6c9KUmOO13anXIvIaXCuX9xdzxwiYbQq+DWf2JM0rqIylr+oQ5EeisZ1Vz4t/4OAHpqEZz+P+vYfVE2x1KG/sj6qgjQBhLARhGvWa/FNL4mNGilIVyiGSOk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fx/iADOE; arc=none smtp.client-ip=209.85.210.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fx/iADOE" Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-70f73ca989aso254898a34.2; Wed, 04 Sep 2024 21:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509875; x=1726114675; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4mhjJvDJNhv2xHoY3ut/g1TUbMfaB7j2eg1v0tOHhm4=; b=fx/iADOEB7g7DI+kFxafGPr83AiTBoDcuNdMucXXAL8S4adUfYdUIeQ353WZNTJXRt LDHD9lnUf942LWuXzEOpt1zXEgcAdWOjpRzOiHpkKcYi6ciCsyn6/VcHuaRjLHlwzXGG btWphKyg8sKr4WDmKm7qhqx0AAxw03ylpDM1TCKYnX2q03J0gSzzFMMxQSlqDVKgpxEV dnc76N4caZeAl8HkJBVHZKQlY1g6VAA7XBbeBdfJxte5ak9qNvmfpzJqBdBCd4xLGrpx Wz9xSuclJBwkrYz9BKOqYAsLBhdIYQlODBo1VpW8nW2ZVlJpvYmVECjGmLvTLpN/CPgb KlMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509875; x=1726114675; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4mhjJvDJNhv2xHoY3ut/g1TUbMfaB7j2eg1v0tOHhm4=; b=V51QZdI7BZx1TBHFv5uKHTxknGbcF+Qhvow2XC78W6R2w6CvHxE+gzkeJ9xBuBWd7Y xFxxNVOeWk1Q/gRBxPu6bR5ysIGEJhNvLwk5xjmhaCENorJe4jXvrDbz9IJBn+iF91O9 pS4OjNA4tsxy3susq4/Tpa1mDidUa3rxgCnw2eYchdOX1PVXlT2JHWzOLVT9J/BKycBR 12PWYYuNzfo/QWknF1ewpFTz0TINBBNhJpWVhAnPSUx1iasgzijCIhTRTbDk2cyU/792 nhvQRJ8T8X3s0K8pAKBMGivNZqVG5o+FD2r9odeDtaGqDsocmQtoNgr4yr5s/zlH2Ilv t0RQ== X-Forwarded-Encrypted: i=1; AJvYcCU3LU+r0ddrUGLdSwiDayFTZ9VFvP2x5Qzgcl5/Rk/WqKnbdAPkNNvuWc+VWNYbxirEQvv5tOmKz6MQjIw=@vger.kernel.org, AJvYcCW8tjbKMgjy+AF20wZD6bEM+ECIyUOLWzaxk2mvMmjVb0RHl2WsGDr9izSzWfSDJUCBeF7Q5gS9VkdZwwVP@vger.kernel.org X-Gm-Message-State: AOJu0Yx9iQKCZaWySNYrRmAxxyaLc4Q5u81W1JX4WOURyRzsIZfCNG7E 9Skk6pG8R9j6M0zd2sKCa88Pz1DHIWkgQW2zqiUTzfOnGIziuCcA6qwwdg== X-Google-Smtp-Source: AGHT+IH0JYEg6QtSOGjiEfpDAKUS/a7YvjIKxseySaiP7VkfsPIL/Y4j2nA5ofHv3vaP5pULVvdK1g== X-Received: by 2002:a05:6359:5f9e:b0:1b5:a36f:cf52 with SMTP id e5c5f4694b2df-1b603bee046mr2609562155d.2.1725509875510; Wed, 04 Sep 2024 21:17:55 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.17.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:17:55 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 08/24] Input: synaptics-rmi4 - use guard notation when pausing serio port in F03 Date: Wed, 4 Sep 2024 21:17:13 -0700 Message-ID: <20240905041732.2034348-9-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that serio ports are resumed in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/rmi4/rmi_f03.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/input/rmi4/rmi_f03.c b/drivers/input/rmi4/rmi_f03.c index 1e11ea30d7bd..e1157ff0f00a 100644 --- a/drivers/input/rmi4/rmi_f03.c +++ b/drivers/input/rmi4/rmi_f03.c @@ -61,14 +61,14 @@ void rmi_f03_commit_buttons(struct rmi_function *fn) struct f03_data *f03 = dev_get_drvdata(&fn->dev); struct serio *serio = f03->serio; - serio_pause_rx(serio); + guard(serio_pause_rx)(serio); + if (serio->drv) { serio->drv->interrupt(serio, PSMOUSE_OOB_EXTRA_BTNS, SERIO_OOB_DATA); serio->drv->interrupt(serio, f03->overwrite_buttons, SERIO_OOB_DATA); } - serio_continue_rx(serio); } static int rmi_f03_pt_write(struct serio *id, unsigned char val) From patchwork Thu Sep 5 04:17:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791689 Received: from mail-oo1-f54.google.com (mail-oo1-f54.google.com [209.85.161.54]) (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 331F1186615; Thu, 5 Sep 2024 04:17:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509879; cv=none; b=ZBNgfNPOgm8k2k7A105DDzYjIQ8v6WOheUkJvzZWTntHGf85XA7T2JvtECtaaVrjkatZqY4R9T0maubFDbg/zNI+JpBmE/bFrMPqceWzixFKA1qzS1P2Y2dCub6jaaljexwXLjCMiTTzsZYhxm8Ui+TBC3kyK3ncRSY2s+6mHI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509879; c=relaxed/simple; bh=vydiQbG1/1szEzLjhnhj91G7z0QVE9gqOa1tJ68qVcs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=grOzfwAXxhBoJ8J2nuLOGbQPuciteeY0gNSOz/VhwfzuOjT9GiOxD46XNiRKOFK7atkD/kqiUthRKKdU0sH5HizaMTOY38H0uo7v+QznTh/uspE6k4lFYuOorlk9IAeGaQOgwxUfr4IAzAUBnpjptrErdZ/5SNxbVl48QFIEE3A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MqK5arM7; arc=none smtp.client-ip=209.85.161.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MqK5arM7" Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-5e16cb56d4aso190383eaf.1; Wed, 04 Sep 2024 21:17:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509877; x=1726114677; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Mdzi002JGx1/VTYSFinhnta06n3PxzWkqyJNw8JR4ro=; b=MqK5arM7iAr2Gg/hs+A3kvFn8gemAJGQmWsXnh9j4NwW7XYSi7cffZGS4p0jUvlz9K yEVSCSlVYI74ERPaEDKBAyZxJj5z6snUdcjIyrQkQoTicTl77sPChyJpr7Lk37fI7rpJ G0EQZubDXb5zYpuMgmmhCfd/0Ig3IPEAGv3yYPPDrh7aoKl68Z8Qq57abcBZ74Q1szxe PlBuRECyRIBk/Q3RzAwwx0kHaiqTSoM45ZD0nvmPZwQ+rZh/QwYk0SWqKOuao2Lar1ov LUO6i0W7ny9tWneV/hlMHjqCadtnPCxTOAO2cDdAhBJ8l3I8JT4zxeOepnFsGnjCPxGw PTmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509877; x=1726114677; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Mdzi002JGx1/VTYSFinhnta06n3PxzWkqyJNw8JR4ro=; b=FrMYZbqfllqpHpQB2Y+tsxfdj9vQ/+m/rG5PWb3+mH7wj8Ej42SaaIpAU0aZLsicSV efHY06KOoRJu9CKG977G+TaOQuUB08D4Rhj7oKDXPdk9mz+1ruxWxE9kRt/6gswi15D7 EYIY+suyltjOliarFvID/yu/MwdE1YP6g2xidG8Y0LCcaJ2oN6stuk+UpHktbRCEAKQN Lhc2G8mSGe/eVDZngAEY6ZXz7XZr2LSglkMXzEogeMGNcR2kssDOCAlxhwpl4UOw30XE yZDGynOZDD1HQCo3AP3161xvn4jsPjaYa4XgMC43cqp7nccmCFQ3ajTf3uTOO9ufZIcU t+EQ== X-Forwarded-Encrypted: i=1; AJvYcCWxvK+ik/dHYBtlfdXD3LtsvkqcaHguRyE3ClhoLlpRCFXgNTpwoY34kMPyctJrC6imAU8ayzw6S1lW9FUX@vger.kernel.org, AJvYcCXhrB69tpJ7A2qnVuk4WV2bIA0dq2lJx+cKg/owjdIzE5S1Z7ZJTauTf/Niv5l8ex2+67QiNwermP2+xl4=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2ygfedqQ54GJg9OIXw1NqNegb7krd6ZzgIm4l39bbVIFT8gFs Cpj9IIDm8yBB5QxNtF8UgG6auBFFZh7ulUn0AYoQJvnC/mncIFmVx0O1vA== X-Google-Smtp-Source: AGHT+IEeegP8PYdaxOx1oJdq99u2b/mnBeID80CKAiS5INtYMrMJc2IOIAmttT7NOBEVZS4HWjLcJw== X-Received: by 2002:a05:6870:3d8c:b0:270:1dab:64a9 with SMTP id 586e51a60fabf-277c8055c7dmr17330298fac.14.1725509877129; Wed, 04 Sep 2024 21:17:57 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.17.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:17:56 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 09/24] Input: elo - use guard notation when pausing serio port Date: Wed, 4 Sep 2024 21:17:14 -0700 Message-ID: <20240905041732.2034348-10-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that serio ports are resumed in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/touchscreen/elo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/input/touchscreen/elo.c b/drivers/input/touchscreen/elo.c index eb883db55420..ad209e6e82a6 100644 --- a/drivers/input/touchscreen/elo.c +++ b/drivers/input/touchscreen/elo.c @@ -225,10 +225,10 @@ static int elo_command_10(struct elo *elo, unsigned char *packet) mutex_lock(&elo->cmd_mutex); - serio_pause_rx(elo->serio); - elo->expected_packet = toupper(packet[0]); - init_completion(&elo->cmd_done); - serio_continue_rx(elo->serio); + scoped_guard(serio_pause_rx, elo->serio) { + elo->expected_packet = toupper(packet[0]); + init_completion(&elo->cmd_done); + } if (serio_write(elo->serio, ELO10_LEAD_BYTE)) goto out; From patchwork Thu Sep 5 04:17:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791690 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 9BE86154439; Thu, 5 Sep 2024 04:17:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509881; cv=none; b=PXDct0osM9qQYKBE/iL8vqc0y1NHhA/K7ldCZFQG+YVQc3jtr1GQ7cVzBbTOh/w92O64JXtkVmw7o4DrNSTKjUvldtFhnzY9rNOXtb5k/EbjDBeB++65OZ/Jv837wEqSsVeSP8+Rq+Hq2Kri3Q2rKOXpyhoe0AHs55xrLuUDV2s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509881; c=relaxed/simple; bh=19U38uZCXEvKhulVokOxaN0gRvDzLtZltpAHJeXQyMk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JPxzN1n1TWJkyzCRQGZC8emMwG1n8McPDKc1b3catJ6Ama5Tb/e/21ssCVz3BTiyKI08fVllyWsJtFc9K/6l3M53DB2cbhj3CY0RMUBcDj16HIR3QdrEEdZ70Hg9cq1hOh3UVvbxEeSmTmOESmRJUKf5Z8b7lUFMuq+tAiqHP5Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Urdgh20n; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Urdgh20n" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-7179069d029so85104b3a.2; Wed, 04 Sep 2024 21:17:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509878; x=1726114678; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5IVs44o6ciGNOoB3tvSvkl1E7l7ddGpRPi+mMdxWbfc=; b=Urdgh20n+x7tD9FwoWeqC8l68BfjfLb9ePTnbd8tnwOzlU14beI8FAzD0tBaMURakN 7DvV7KMNeRJS5eOzA8uJjHZhEmB9tB3ckoK2qpT2xT4Wx9N5/o/rHh3kqf1CAFldLQh+ T7JH97RnKmkChPLeq2m7l+BXsAq9yHDHv+13AG5q4Ua5pAjxSRle4/WTEYcI8XvZK77x Nq7WBib5+KJ2eEZd4yB1/fJzuS04MdG2ofJPjx1b3rrNZ2/2pYk1dD3geGmbCtuf5VLT M8Xa2kZ9bURUav5qF2mksSa1OlfS4OI+FOvYNnXe2bsVsbPxuJEm82UfdTAkNjr++69R C9xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509878; x=1726114678; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5IVs44o6ciGNOoB3tvSvkl1E7l7ddGpRPi+mMdxWbfc=; b=jU1Y3rQmYnhteKSul5/CEQ2Ou9lKCZ2u+S2nbZdZyJONXoryI778FP7W0Z0eO11T3y d6XcGhSoEezr2gNlLAgg6Z0ai2Xqf6ARFILmeB6l+fKnBJF+dHjUn6+ovHVnkSsjUCie HZsM1FgBGUnfkk2lgww/Gncr2vOL338DJJO4lF+GEnAZjbMBqVFxPBkzjPhkzrIBJLBU jNDUezYIuvzjNoN+0auKcvwHDWr92D0ef6mCgVg1Rll+fn0vS1qac2l978b8mC4gt+tk wxkTVhylsWkkMVY2CMch8sy0I6Sh5PZf3k3WIk7/g0ue9jogad+WOhtYCyJaa77InPAP m/Tg== X-Forwarded-Encrypted: i=1; AJvYcCW+w/0qWEhaR3epYZJcizYOOThmNJwYXt3WIh7lXILhuJ1o6JJC63nSCj5Jq35qqMqPU0D7lbDv8C0AmznH@vger.kernel.org, AJvYcCXEq0dTy0nrK8d7rITmGa68BuT/yltfQdALqnVShg+34jmcCaGpxyxkk76i6J6m5uCuOL5Nki0E5F20sbs=@vger.kernel.org X-Gm-Message-State: AOJu0YwnKcLYO9Yvu5z4uVaiQqj2rxkoS000EFUqq0q6lVJRfHLI9sNj pYL2quUthiMCt/mH9wqeJz4Jlq4wj2mL6wBZEAOaodQlepM690MwClvb+g== X-Google-Smtp-Source: AGHT+IHw/pyP6EniZwd1+0N9t+8Gq3aDd7Fq8D4lnLSFHwaJBTj9phdK/nCIOoeA80+G8TcVQfUhXg== X-Received: by 2002:a05:6a00:2da8:b0:70e:8070:f9d0 with SMTP id d2e1a72fcca58-7173fa40bcfmr14087981b3a.9.1725509878530; Wed, 04 Sep 2024 21:17:58 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.17.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:17:58 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 10/24] Input: gscps2 - use guard notation when acquiring spinlock Date: Wed, 4 Sep 2024 21:17:15 -0700 Message-ID: <20240905041732.2034348-11-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that locks are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/gscps2.c | 114 +++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 52 deletions(-) diff --git a/drivers/input/serio/gscps2.c b/drivers/input/serio/gscps2.c index d94c01eb3fc9..cf0603d1a113 100644 --- a/drivers/input/serio/gscps2.c +++ b/drivers/input/serio/gscps2.c @@ -145,7 +145,6 @@ static void gscps2_flush(struct gscps2port *ps2port) static inline int gscps2_writeb_output(struct gscps2port *ps2port, u8 data) { - unsigned long flags; char __iomem *addr = ps2port->addr; if (!wait_TBE(addr)) { @@ -156,9 +155,8 @@ static inline int gscps2_writeb_output(struct gscps2port *ps2port, u8 data) while (gscps2_readb_status(addr) & GSC_STAT_RBNE) /* wait */; - spin_lock_irqsave(&ps2port->lock, flags); - writeb(data, addr+GSC_XMTDATA); - spin_unlock_irqrestore(&ps2port->lock, flags); + scoped_guard(spinlock_irqsave, &ps2port->lock) + writeb(data, addr+GSC_XMTDATA); /* this is ugly, but due to timing of the port it seems to be necessary. */ mdelay(6); @@ -177,19 +175,19 @@ static inline int gscps2_writeb_output(struct gscps2port *ps2port, u8 data) static void gscps2_enable(struct gscps2port *ps2port, int enable) { - unsigned long flags; u8 data; /* now enable/disable the port */ - spin_lock_irqsave(&ps2port->lock, flags); - gscps2_flush(ps2port); - data = gscps2_readb_control(ps2port->addr); - if (enable) - data |= GSC_CTRL_ENBL; - else - data &= ~GSC_CTRL_ENBL; - gscps2_writeb_control(data, ps2port->addr); - spin_unlock_irqrestore(&ps2port->lock, flags); + scoped_guard(spinlock_irqsave, &ps2port->lock) { + gscps2_flush(ps2port); + data = gscps2_readb_control(ps2port->addr); + if (enable) + data |= GSC_CTRL_ENBL; + else + data &= ~GSC_CTRL_ENBL; + gscps2_writeb_control(data, ps2port->addr); + } + wait_TBE(ps2port->addr); gscps2_flush(ps2port); } @@ -203,15 +201,56 @@ static void gscps2_reset(struct gscps2port *ps2port) unsigned long flags; /* reset the interface */ - spin_lock_irqsave(&ps2port->lock, flags); + guard(spinlock_irqsave)(&ps2port->lock); gscps2_flush(ps2port); writeb(0xff, ps2port->addr + GSC_RESET); gscps2_flush(ps2port); - spin_unlock_irqrestore(&ps2port->lock, flags); } static LIST_HEAD(ps2port_list); +static void gscps2_read_data(struct gscps2port *ps2port) +{ + u8 status; + + do { + status = gscps2_readb_status(ps2port->addr); + if (!(status & GSC_STAT_RBNE)) + break; + + ps2port->buffer[ps2port->append].ste = status; + ps2port->buffer[ps2port->append].data = + gscps2_readb_input(ps2port->addr); + } while (true); +} + +static bool gscps2_report_data(struct gscps2port *ps2port) +{ + unsigned int rxflags; + u8 data, status; + + while (ps2port->act != ps2port->append) { + /* + * Did new data arrived while we read existing data ? + * If yes, exit now and let the new irq handler start + * over again. + */ + if (gscps2_readb_status(ps2port->addr) & GSC_STAT_CMPINTR) + return true; + + status = ps2port->buffer[ps2port->act].str; + data = ps2port->buffer[ps2port->act].data; + + ps2port->act = (ps2port->act + 1) & BUFFER_SIZE; + rxflags = ((status & GSC_STAT_TERR) ? SERIO_TIMEOUT : 0 ) | + ((status & GSC_STAT_PERR) ? SERIO_PARITY : 0 ); + + serio_interrupt(ps2port->port, data, rxflags); + } + + return false; +} + /** * gscps2_interrupt() - Interruption service routine * @@ -229,47 +268,18 @@ static irqreturn_t gscps2_interrupt(int irq, void *dev) struct gscps2port *ps2port; list_for_each_entry(ps2port, &ps2port_list, node) { + guard(spinlock_irqsave)(&ps2port->lock); - unsigned long flags; - spin_lock_irqsave(&ps2port->lock, flags); - - while ( (ps2port->buffer[ps2port->append].str = - gscps2_readb_status(ps2port->addr)) & GSC_STAT_RBNE ) { - ps2port->buffer[ps2port->append].data = - gscps2_readb_input(ps2port->addr); - ps2port->append = ((ps2port->append+1) & BUFFER_SIZE); - } - - spin_unlock_irqrestore(&ps2port->lock, flags); - + gscps2_read_data(ps2port); } /* list_for_each_entry */ /* all data was read from the ports - now report the data to upper layer */ - list_for_each_entry(ps2port, &ps2port_list, node) { - - while (ps2port->act != ps2port->append) { - - unsigned int rxflags; - u8 data, status; - - /* Did new data arrived while we read existing data ? - If yes, exit now and let the new irq handler start over again */ - if (gscps2_readb_status(ps2port->addr) & GSC_STAT_CMPINTR) - return IRQ_HANDLED; - - status = ps2port->buffer[ps2port->act].str; - data = ps2port->buffer[ps2port->act].data; - - ps2port->act = ((ps2port->act+1) & BUFFER_SIZE); - rxflags = ((status & GSC_STAT_TERR) ? SERIO_TIMEOUT : 0 ) | - ((status & GSC_STAT_PERR) ? SERIO_PARITY : 0 ); - - serio_interrupt(ps2port->port, data, rxflags); - - } /* while() */ - - } /* list_for_each_entry */ + if (gscps2_report_data(ps2port)) { + /* More data ready - break early to restart interrupt */ + break; + } + } return IRQ_HANDLED; } From patchwork Thu Sep 5 04:17:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791691 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (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 1CCCB188920; Thu, 5 Sep 2024 04:18:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509882; cv=none; b=MjeRPa3Do7Aw7pI2zpvZ1GLZpYj3thYEmCXC5pnqigifmKY0f/0JgJuxMxvbI9zzSh5Qa2AJFK2d6OdUpdDCCZYObKpOYIao59gaE/AZFBqSseIOUrY/0MdSfkgd6tg98z+sHM/VzPUS7ykntz1NB3mSmVvVWZqAQLsQkmtDiz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509882; c=relaxed/simple; bh=i9osRIZI2r8pLinAa1PuSzq4Uf0jxagbDh5hgtSxDZo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZWYavPbpawSBmF8oATxjkGy8Tj99pujbJCwpOQpy9jFK0eAVg7sJPTcRjrO/vl218Utt3PzbhAnT8ez0hsN3Jh0VinHBwAsbs0Cr7pwWr9w73Xqf9jdEKPX6mM3KukCvx5ghc70e0Kwa65J//GGf5IqAvt2YtFU750VtOZcKYyw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aHa602Pf; arc=none smtp.client-ip=209.85.167.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aHa602Pf" Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3df02c407c4so180216b6e.1; Wed, 04 Sep 2024 21:18:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509880; x=1726114680; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wySGI9scoJi4TljRD+Hpmp4oNTGGODlyYEe5tlANPZw=; b=aHa602Pf0n975Sm6HlK+2pW/bKvHjAV5We7bFzYUNHPXY5AzzAouMflQwOBPsnee6U TG0coeM7EyqtfPtcrG448qm0WbE3qoBzosFaD30cX3WGSEkDN3CJ7670cOcc5bIpDK+r QOQ5uRMRfPmXzS3eR1pQzd1L6WEsJT0bu3X86qeuctZvH/T6wbPBcGxEC+AhPxkpV8kz 1t+7m0lAr6LB9+bIhfa72JZEwYhkebaOarOMtBiXONOze5bcWC/peKZRwx5GTOWbgjr8 C7ymwERdjI0iVsUv99gGQzbYLPApdUmwdt9Z0N/p6HROJenoC1GYd1ydAa59BOyGb9y1 maiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509880; x=1726114680; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wySGI9scoJi4TljRD+Hpmp4oNTGGODlyYEe5tlANPZw=; b=eS+mbq1CQWDwNYz5Vy5GSAbTZNKchYWM7l4IOdqd15J4A3UG8EGPtuuRHKXA4a0oox hcITZlFGOeczmKlvLIKvYAjoP3EEf97H1ACTr0Apw0L0Wc2o3K7EoWD7le2l0Ik0JatX oo3bmkoaWqi/y+x5Y2Jl0BQ304RBKsW9cVc0kPVPaEsoL+pFRvE5KBTf4d+tdOfG7F0E KhFOvjvH+xx2dPQxa1uOmJM0hpMjgPfWsEeT76UrKh7f8VWzP/2jWX3UQwS8GMvuokuJ E06xwEGl7SKyuPftBOMEfoF16cO7kxMKEwQ2ig0JiWBGde+3hxirXA1H+wFfVv8WWSKt jP0g== X-Forwarded-Encrypted: i=1; AJvYcCVf/3uaRk131eAXpekEbBS3UR+JNKkM572G4mwyNqa6hvYKFizN/3De6Qmwmq6F+70ufmOsRO/aoz9wfmth@vger.kernel.org, AJvYcCWt8kMLr4sQTD1tm99kIh4unm4atVuhr10EnGywWsKZfCfHy6PXTo2+uDTK3AekH5ZuDVgk9srqglwVlNQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3ZklvIqogDv+uM9Mj6j724oHTLe7IxotIIGbImVJGBhGk7V+A SAre9jQPTa7FI+Ce/oXLK3kaD+XFcv4ijssxqo/60h9YdU0armTOxaCN8w== X-Google-Smtp-Source: AGHT+IEQOPemQhEEQd4JD206/3mLVfaYjNo57sTDwNHwWOJ0RwSvTidH6chDqJAiBF7WrpAvcYyjrQ== X-Received: by 2002:a05:6808:11c5:b0:3dc:39e9:e04 with SMTP id 5614622812f47-3df22106d0fmr17555384b6e.20.1725509879905; Wed, 04 Sep 2024 21:17:59 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.17.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:17:59 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 11/24] Input: hyperv-keyboard - use guard notation when acquiring spinlock Date: Wed, 4 Sep 2024 21:17:16 -0700 Message-ID: <20240905041732.2034348-12-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that locks are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/hyperv-keyboard.c | 38 +++++++++++++-------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/drivers/input/serio/hyperv-keyboard.c b/drivers/input/serio/hyperv-keyboard.c index 31d9dacd2fd1..0ee7505427ac 100644 --- a/drivers/input/serio/hyperv-keyboard.c +++ b/drivers/input/serio/hyperv-keyboard.c @@ -102,7 +102,6 @@ static void hv_kbd_on_receive(struct hv_device *hv_dev, { struct hv_kbd_dev *kbd_dev = hv_get_drvdata(hv_dev); struct synth_kbd_keystroke *ks_msg; - unsigned long flags; u32 msg_type = __le32_to_cpu(msg->header.type); u32 info; u16 scan_code; @@ -147,21 +146,22 @@ static void hv_kbd_on_receive(struct hv_device *hv_dev, /* * Inject the information through the serio interrupt. */ - spin_lock_irqsave(&kbd_dev->lock, flags); - if (kbd_dev->started) { - if (info & IS_E0) - serio_interrupt(kbd_dev->hv_serio, - XTKBD_EMUL0, 0); - if (info & IS_E1) - serio_interrupt(kbd_dev->hv_serio, - XTKBD_EMUL1, 0); - scan_code = __le16_to_cpu(ks_msg->make_code); - if (info & IS_BREAK) - scan_code |= XTKBD_RELEASE; + scoped_guard(spinlock_irqsave, &kbd_dev->lock) { + if (kbd_dev->started) { + if (info & IS_E0) + serio_interrupt(kbd_dev->hv_serio, + XTKBD_EMUL0, 0); + if (info & IS_E1) + serio_interrupt(kbd_dev->hv_serio, + XTKBD_EMUL1, 0); + scan_code = __le16_to_cpu(ks_msg->make_code); + if (info & IS_BREAK) + scan_code |= XTKBD_RELEASE; - serio_interrupt(kbd_dev->hv_serio, scan_code, 0); + serio_interrupt(kbd_dev->hv_serio, + scan_code, 0); + } } - spin_unlock_irqrestore(&kbd_dev->lock, flags); /* * Only trigger a wakeup on key down, otherwise @@ -292,11 +292,10 @@ static int hv_kbd_connect_to_vsp(struct hv_device *hv_dev) static int hv_kbd_start(struct serio *serio) { struct hv_kbd_dev *kbd_dev = serio->port_data; - unsigned long flags; - spin_lock_irqsave(&kbd_dev->lock, flags); + guard(spinlock_irqsave)(&kbd_dev->lock); + kbd_dev->started = true; - spin_unlock_irqrestore(&kbd_dev->lock, flags); return 0; } @@ -304,11 +303,10 @@ static int hv_kbd_start(struct serio *serio) static void hv_kbd_stop(struct serio *serio) { struct hv_kbd_dev *kbd_dev = serio->port_data; - unsigned long flags; - spin_lock_irqsave(&kbd_dev->lock, flags); + guard(spinlock_irqsave)(&kbd_dev->lock); + kbd_dev->started = false; - spin_unlock_irqrestore(&kbd_dev->lock, flags); } static int hv_kbd_probe(struct hv_device *hv_dev, From patchwork Thu Sep 5 04:17:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791692 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (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 994FF188A19; Thu, 5 Sep 2024 04:18:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509884; cv=none; b=f1Nd0UD4YsMT9T+uQAeZ0TNrPqyTfJE7rcLwMcMvWEGmR9LBv9va+Lf47Y+F4bAWL5rR5eao4VxowjUWk0+4eXGTcSglMO8v3ysFTIR35hqO480vbJOavpBOpY2Vq/R4T/RyhiByKv5rYa1Lz9rNczPW7jUXGixNYqOPLpvrBgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509884; c=relaxed/simple; bh=TuG6oHmVqngpDPeAfcj+CxwUpX/mVzV+qPba3GW+Jtw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PfGo9UTihJZgLtTuBB30VFiihhAx05vLHI2Rq4MQOy56sOKBIjxbylK+LoWghBgcA9Z8fj7qH2P6f5BWIDF3JuWL8nUcenDtTAIPDXcDJaGqsM/+jS6zRg8ydM7le+mhqxYzreBd4Jr1HrGQiKDQDyBl25IYBCLP/EBMUOK7/cA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HKyppWd2; arc=none smtp.client-ip=209.85.210.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HKyppWd2" Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-70f645a30dcso287366a34.3; Wed, 04 Sep 2024 21:18:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509881; x=1726114681; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IJ0f2V5xQlnWNK4EvLWQUiJbt0aWje4MjkaawAE2fXI=; b=HKyppWd2LW2FcAfwwqfdecQ/VkXwgMRLKCKSDmRopGiasUqRBacT4hGfRZOXSReesM btVLv2xX/QkX+QJoTVfK2UywbqCLqiCyGOFwCdw1ozMeso5kIYST0tlhS3ZD/rUH4jDH gTBywGvyDSFu1Ql9p3BrnGiAxCHROuoOHreniZPE2EqFAo7LjPxbp/c4KGq4+InAlkyJ Vdt0I5n+cTAyAx9W69lSjiDwWd/m7dxIds9YoedILmtsk+8TDKtF3IOEtlBWoEYoR1vo CyeHIyn4oF/Ztz4knxWfwQ9ti3SgoXohs+E8VNWci6IU3nqnvecdafurY4yu+dWH52oj OZjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509881; x=1726114681; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IJ0f2V5xQlnWNK4EvLWQUiJbt0aWje4MjkaawAE2fXI=; b=uXmAmJ0UTBcf0um/DukV9D2He24acwyIkC4HWBAccKer75zCZNHHxWq8OQ2+CmmXLy l7tUBxjy4iR9ogMiabSSFZNsCgkptR7LyLrKMWk9VAj3gT73Oqfd8RiCjzMLYfydtcrY TQGmcU7Cko7UE6ar960dtmlv6/DES/QTUKwt9M+dq56e6+HWSpfu85wskhDigPrLnfZH gi/4S4KdWuH6aJr9RwE2zDB3vgfb1N5Fk7wdL5Recy4SX2KmdLzkNPKIfMQQvmIau1RH dZWfWaM3A5hfSUvypSKtKJCNOUBCFyqYgnmy1cDv2Th1cXGQlrvJpIH73efSKmFHE+eg +f+A== X-Forwarded-Encrypted: i=1; AJvYcCUj92OtztnEVIiDuwLh/CMYLwiNbMqWX0vj988rGR0CebeugJtfNgEYMMGi9H4UfOmesFEcVbAuZ8IqDFNe@vger.kernel.org, AJvYcCVFH1U67ba+gnf0YaQoV2lGd+A66vS/d5h+PLDgdrofHtq/coTIe6EHadGTWtygc2PaIW3jCvt5IEUWW+A=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0ThQlxaT6frQqzK6jmwuT4MJbN+yF0ODLq/nVgsP4KtMHHiVC UX7sICfV5J68l4ejSQ5LbY+ovLqSI6Bo0EH/6p3lSDywAcMSVj7GwZyriA== X-Google-Smtp-Source: AGHT+IFfwqWs2Krwm9FKRLXZTcp8pEOgI1FCBF6/QQpcb7fZKh+2/hIYDHYeoNIAXonuZwb4W4JP/Q== X-Received: by 2002:a05:6830:2d8b:b0:710:b588:2552 with SMTP id 46e09a7af769-710b5882e6bmr5386695a34.12.1725509881402; Wed, 04 Sep 2024 21:18:01 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.18.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:18:00 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 12/24] Input: i8042 - tease apart interrupt handler Date: Wed, 4 Sep 2024 21:17:17 -0700 Message-ID: <20240905041732.2034348-13-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In preparation to using guard notation when acquiring mutexes and spinlocks factor out handling of active multiplexing mode from i8042_interrupt(). Signed-off-by: Dmitry Torokhov --- drivers/input/serio/i8042.c | 139 +++++++++++++++++++++--------------- 1 file changed, 83 insertions(+), 56 deletions(-) diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c index 8ec4872b4471..674cd155ec8f 100644 --- a/drivers/input/serio/i8042.c +++ b/drivers/input/serio/i8042.c @@ -178,7 +178,7 @@ static unsigned char i8042_suppress_kbd_ack; static struct platform_device *i8042_platform_device; static struct notifier_block i8042_kbd_bind_notifier_block; -static irqreturn_t i8042_interrupt(int irq, void *dev_id); +static bool i8042_handle_data(int irq); static bool (*i8042_platform_filter)(unsigned char data, unsigned char str, struct serio *serio); @@ -434,7 +434,7 @@ static void i8042_port_close(struct serio *serio) * See if there is any data appeared while we were messing with * port state. */ - i8042_interrupt(0, NULL); + i8042_handle_data(0); } /* @@ -518,12 +518,68 @@ static bool i8042_filter(unsigned char data, unsigned char str, } /* - * i8042_interrupt() is the most important function in this driver - - * it handles the interrupts from the i8042, and sends incoming bytes - * to the upper layers. + * i8042_handle_mux() handles case when data is coming from one of + * the multiplexed ports. It would be simple if not for quirks with + * handling errors: + * + * When MUXERR condition is signalled the data register can only contain + * 0xfd, 0xfe or 0xff if implementation follows the spec. Unfortunately + * it is not always the case. Some KBCs also report 0xfc when there is + * nothing connected to the port while others sometimes get confused which + * port the data came from and signal error leaving the data intact. They + * _do not_ revert to legacy mode (actually I've never seen KBC reverting + * to legacy mode yet, when we see one we'll add proper handling). + * Anyway, we process 0xfc, 0xfd, 0xfe and 0xff as timeouts, and for the + * rest assume that the data came from the same serio last byte + * was transmitted (if transmission happened not too long ago). */ +static int i8042_handle_mux(u8 str, u8 *data, unsigned int *dfl) +{ + static unsigned long last_transmit; + static unsigned long last_port; + unsigned int mux_port; + + mux_port = (str >> 6) & 3; + *dfl = 0; + + if (str & I8042_STR_MUXERR) { + dbg("MUX error, status is %02x, data is %02x\n", + str, *data); + + switch (*data) { + default: + if (time_before(jiffies, last_transmit + HZ/10)) { + mux_port = last_port; + break; + } + fallthrough; /* report timeout */ + case 0xfc: + case 0xfd: + case 0xfe: + *dfl = SERIO_TIMEOUT; + *data = 0xfe; + break; + case 0xff: + *dfl = SERIO_PARITY; + *data = 0xfe; + break; + } + } -static irqreturn_t i8042_interrupt(int irq, void *dev_id) + last_port = mux_port; + last_transmit = jiffies; + + return I8042_MUX_PORT_NO + mux_port; +} + +/* + * i8042_handle_data() is the most important function in this driver - + * it reads the data from the i8042, determines its destination serio + * port, and sends received byte to the upper layers. + * + * Returns true if there was data waiting, false otherwise. + */ +static bool i8042_handle_data(int irq) { struct i8042_port *port; struct serio *serio; @@ -532,63 +588,24 @@ static irqreturn_t i8042_interrupt(int irq, void *dev_id) unsigned int dfl; unsigned int port_no; bool filtered; - int ret = 1; spin_lock_irqsave(&i8042_lock, flags); str = i8042_read_status(); if (unlikely(~str & I8042_STR_OBF)) { spin_unlock_irqrestore(&i8042_lock, flags); - if (irq) - dbg("Interrupt %d, without any data\n", irq); - ret = 0; - goto out; + return false; } data = i8042_read_data(); if (i8042_mux_present && (str & I8042_STR_AUXDATA)) { - static unsigned long last_transmit; - static unsigned char last_str; - - dfl = 0; - if (str & I8042_STR_MUXERR) { - dbg("MUX error, status is %02x, data is %02x\n", - str, data); -/* - * When MUXERR condition is signalled the data register can only contain - * 0xfd, 0xfe or 0xff if implementation follows the spec. Unfortunately - * it is not always the case. Some KBCs also report 0xfc when there is - * nothing connected to the port while others sometimes get confused which - * port the data came from and signal error leaving the data intact. They - * _do not_ revert to legacy mode (actually I've never seen KBC reverting - * to legacy mode yet, when we see one we'll add proper handling). - * Anyway, we process 0xfc, 0xfd, 0xfe and 0xff as timeouts, and for the - * rest assume that the data came from the same serio last byte - * was transmitted (if transmission happened not too long ago). - */ - - switch (data) { - default: - if (time_before(jiffies, last_transmit + HZ/10)) { - str = last_str; - break; - } - fallthrough; /* report timeout */ - case 0xfc: - case 0xfd: - case 0xfe: dfl = SERIO_TIMEOUT; data = 0xfe; break; - case 0xff: dfl = SERIO_PARITY; data = 0xfe; break; - } - } - - port_no = I8042_MUX_PORT_NO + ((str >> 6) & 3); - last_str = str; - last_transmit = jiffies; + port_no = i8042_handle_mux(str, &data, &dfl); } else { - dfl = ((str & I8042_STR_PARITY) ? SERIO_PARITY : 0) | - ((str & I8042_STR_TIMEOUT && !i8042_notimeout) ? SERIO_TIMEOUT : 0); + dfl = (str & I8042_STR_PARITY) ? SERIO_PARITY : 0; + if ((str & I8042_STR_TIMEOUT) && !i8042_notimeout) + dfl |= SERIO_TIMEOUT; port_no = (str & I8042_STR_AUXDATA) ? I8042_AUX_PORT_NO : I8042_KBD_PORT_NO; @@ -609,8 +626,17 @@ static irqreturn_t i8042_interrupt(int irq, void *dev_id) if (likely(serio && !filtered)) serio_interrupt(serio, data, dfl); - out: - return IRQ_RETVAL(ret); + return true; +} + +static irqreturn_t i8042_interrupt(int irq, void *dev_id) +{ + if (unlikely(!i8042_handle_data(irq))) { + dbg("Interrupt %d, without any data\n", irq); + return IRQ_NONE; + } + + return IRQ_HANDLED; } /* @@ -1216,13 +1242,14 @@ static int i8042_controller_resume(bool s2r_wants_reset) if (i8042_mux_present) { if (i8042_set_mux_mode(true, NULL) || i8042_enable_mux_ports()) pr_warn("failed to resume active multiplexor, mouse won't work\n"); - } else if (i8042_ports[I8042_AUX_PORT_NO].serio) + } else if (i8042_ports[I8042_AUX_PORT_NO].serio) { i8042_enable_aux_port(); + } if (i8042_ports[I8042_KBD_PORT_NO].serio) i8042_enable_kbd_port(); - i8042_interrupt(0, NULL); + i8042_handle_data(0); return 0; } @@ -1253,7 +1280,7 @@ static int i8042_pm_suspend(struct device *dev) static int i8042_pm_resume_noirq(struct device *dev) { if (i8042_forcenorestore || !pm_resume_via_firmware()) - i8042_interrupt(0, NULL); + i8042_handle_data(0); return 0; } @@ -1290,7 +1317,7 @@ static int i8042_pm_resume(struct device *dev) static int i8042_pm_thaw(struct device *dev) { - i8042_interrupt(0, NULL); + i8042_handle_data(0); return 0; } From patchwork Thu Sep 5 04:17:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791693 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (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 5B5AD189500; Thu, 5 Sep 2024 04:18:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509886; cv=none; b=IePzCy87emHYxNeU7KQLPmOFGgl9J34BTtd/mevOosPBp9ap1aT6bW3TJfU5eVCkPjpzRxQ/eZBy6BdryENTvCvEe45HYZoIrKphKOEMBq0RLWdDnMQ/cD2P/gtOzpS5yoKFay42bzWGt9/hhIlS84uSg0SILdUJLYYbAmQZmN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509886; c=relaxed/simple; bh=XHDF65UMYbcNN1J2ncDViDYDlOQox8KGEG4MrzcKBVg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cj0rLaO/4t4UZ/cOqCPkxKcx8g5qECVu6Auz7OwgAww0tVxdJFmjjoq/y91V4pdLHBUdGE4nSH81/hgkm1xz3hDGbJf4KzX67cw78Cypu+VpihhgACdxHOjGeg6cFZHS/SwvvAZUIWt4Nw317iJREVk0OJARyxZJPSiBWXt79nU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OXBTPBvN; arc=none smtp.client-ip=209.85.210.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OXBTPBvN" Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-70f79f1e1fbso207902a34.1; Wed, 04 Sep 2024 21:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509883; x=1726114683; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JXmUmnslyZHyZJLR+Zy+r2EKZKWq2y74P1oax/HM5cE=; b=OXBTPBvNN1DKxLSeGyvkinnG51zJYOJmEnpFjDE7mWf2u+18Q5yoAX8tB4yjZi2O0N 0undt3aTfq5ark0Qa83i1LwG9H04IGVWZGCcGPdSqxouFY+eBG7O4g1HhDbMAMp2VU5U SR88UCRz9JlFG8ngN8K9kBgu1CB11fXyEtCfsieT6HfEhgo53gyG97QZ4S+zuPoBeUOa JwOYPp4gYh6IjnhGM8MNlQF0oLE7rSEuK+RPcde+PdUBOyiZnaVVL9xX0BiObtiUInWo xlu2uH7VtPgNSdLCOwsphVJsS+saqTwBbH6QQgF2zkMI2+Mq38sC75a337IPhliKSIWK 0xtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509883; x=1726114683; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JXmUmnslyZHyZJLR+Zy+r2EKZKWq2y74P1oax/HM5cE=; b=SOvLnhj3t0IH58l1loV1ru2ouOrPO27HvjVY9msFEqYQBcZVSWS8Dc84XpFjYlqAJ4 LfuAApUWexjTE2PCdGK2Cl8nX+guqsmgVawPXYvFAa3eT3d0yJyiA0A/FIvy9rE1qDsB MOWBp3NuYiJazdF/XwWs0HrCW+MHpV3l0TLKtHP2KbavAIz7pNQp5WivxMTB/HEOCUnK XVIOCnswQl9ixMUXLD810YAdD5X4hQhEdMnOzShHf8b8xTUTT0308zGy3DmTDIz68m+6 6BwYvGoeOQPSpIEEgs1mZtBnuD3r5pY42ivH8OqaVNo3+HwVSfI+qh9r4uKGO8CJnhRI GT7g== X-Forwarded-Encrypted: i=1; AJvYcCUj6X8Swu3bCoeLDmbGCKo+HNzjd0YiLcFIJRGV85FDw8hdDWMWVJKOm7sqfIgBjGU5UYOXIpbN796/LvI=@vger.kernel.org, AJvYcCW+zsUONP0EypQU4cdyr0usK4LcwHBLtfVXJ2rorFnMs5go4LR2YOuiRsmeo3YBw6xMvmZfQB/hUifMflh8@vger.kernel.org X-Gm-Message-State: AOJu0YzE5ccAmcHYlt8yjId+XDqiXbv6xutBfATthNa8Mc0S5sDVvvjL i26g6CxowsMCjYdKHvFVbx3OH19ByajsB1v3OySLp/m8ptb7OEYxnJfwgg== X-Google-Smtp-Source: AGHT+IHcMsyUFlTpAfo6lJFBaVdiWg5Gnvhy6xBpLteR2E7XriaKtgwaYzGHtMaMdLGv9PUE1ZycOA== X-Received: by 2002:a05:6830:4111:b0:709:4060:1093 with SMTP id 46e09a7af769-70f5c467082mr29658656a34.22.1725509882956; Wed, 04 Sep 2024 21:18:02 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.18.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:18:02 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 13/24] Input: i8042 - use guard notation when acquiring spinlock Date: Wed, 4 Sep 2024 21:17:18 -0700 Message-ID: <20240905041732.2034348-14-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that locks are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/i8042.c | 204 +++++++++++++++--------------------- 1 file changed, 82 insertions(+), 122 deletions(-) diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c index 674cd155ec8f..86916fe3925f 100644 --- a/drivers/input/serio/i8042.c +++ b/drivers/input/serio/i8042.c @@ -197,42 +197,26 @@ EXPORT_SYMBOL(i8042_unlock_chip); int i8042_install_filter(bool (*filter)(unsigned char data, unsigned char str, struct serio *serio)) { - unsigned long flags; - int ret = 0; + guard(spinlock_irqsave)(&i8042_lock); - spin_lock_irqsave(&i8042_lock, flags); - - if (i8042_platform_filter) { - ret = -EBUSY; - goto out; - } + if (i8042_platform_filter) + return -EBUSY; i8042_platform_filter = filter; - -out: - spin_unlock_irqrestore(&i8042_lock, flags); - return ret; + return 0; } EXPORT_SYMBOL(i8042_install_filter); int i8042_remove_filter(bool (*filter)(unsigned char data, unsigned char str, struct serio *port)) { - unsigned long flags; - int ret = 0; - - spin_lock_irqsave(&i8042_lock, flags); + guard(spinlock_irqsave)(&i8042_lock); - if (i8042_platform_filter != filter) { - ret = -EINVAL; - goto out; - } + if (i8042_platform_filter != filter) + return -EINVAL; i8042_platform_filter = NULL; - -out: - spin_unlock_irqrestore(&i8042_lock, flags); - return ret; + return 0; } EXPORT_SYMBOL(i8042_remove_filter); @@ -271,28 +255,22 @@ static int i8042_wait_write(void) static int i8042_flush(void) { - unsigned long flags; unsigned char data, str; int count = 0; - int retval = 0; - spin_lock_irqsave(&i8042_lock, flags); + guard(spinlock_irqsave)(&i8042_lock); while ((str = i8042_read_status()) & I8042_STR_OBF) { - if (count++ < I8042_BUFFER_SIZE) { - udelay(50); - data = i8042_read_data(); - dbg("%02x <- i8042 (flush, %s)\n", - data, str & I8042_STR_AUXDATA ? "aux" : "kbd"); - } else { - retval = -EIO; - break; - } - } + if (count++ >= I8042_BUFFER_SIZE) + return -EIO; - spin_unlock_irqrestore(&i8042_lock, flags); + udelay(50); + data = i8042_read_data(); + dbg("%02x <- i8042 (flush, %s)\n", + data, str & I8042_STR_AUXDATA ? "aux" : "kbd"); + } - return retval; + return 0; } /* @@ -349,17 +327,12 @@ static int __i8042_command(unsigned char *param, int command) int i8042_command(unsigned char *param, int command) { - unsigned long flags; - int retval; - if (!i8042_present) return -1; - spin_lock_irqsave(&i8042_lock, flags); - retval = __i8042_command(param, command); - spin_unlock_irqrestore(&i8042_lock, flags); + guard(spinlock_irqsave)(&i8042_lock); - return retval; + return __i8042_command(param, command); } EXPORT_SYMBOL(i8042_command); @@ -369,19 +342,18 @@ EXPORT_SYMBOL(i8042_command); static int i8042_kbd_write(struct serio *port, unsigned char c) { - unsigned long flags; - int retval = 0; + int error; - spin_lock_irqsave(&i8042_lock, flags); + guard(spinlock_irqsave)(&i8042_lock); - if (!(retval = i8042_wait_write())) { - dbg("%02x -> i8042 (kbd-data)\n", c); - i8042_write_data(c); - } + error = i8042_wait_write(); + if (error) + return error; - spin_unlock_irqrestore(&i8042_lock, flags); + dbg("%02x -> i8042 (kbd-data)\n", c); + i8042_write_data(c); - return retval; + return 0; } /* @@ -460,9 +432,8 @@ static int i8042_start(struct serio *serio) device_set_wakeup_enable(&serio->dev, true); } - spin_lock_irq(&i8042_lock); + guard(spinlock_irq)(&i8042_lock); port->exists = true; - spin_unlock_irq(&i8042_lock); return 0; } @@ -476,10 +447,10 @@ static void i8042_stop(struct serio *serio) { struct i8042_port *port = serio->port_data; - spin_lock_irq(&i8042_lock); - port->exists = false; - port->serio = NULL; - spin_unlock_irq(&i8042_lock); + scoped_guard(spinlock_irq, &i8042_lock) { + port->exists = false; + port->serio = NULL; + } /* * We need to make sure that interrupt handler finishes using @@ -583,45 +554,41 @@ static bool i8042_handle_data(int irq) { struct i8042_port *port; struct serio *serio; - unsigned long flags; unsigned char str, data; unsigned int dfl; unsigned int port_no; bool filtered; - spin_lock_irqsave(&i8042_lock, flags); - - str = i8042_read_status(); - if (unlikely(~str & I8042_STR_OBF)) { - spin_unlock_irqrestore(&i8042_lock, flags); - return false; - } - - data = i8042_read_data(); + scoped_guard(spinlock_irqsave, &i8042_lock) { + str = i8042_read_status(); + if (unlikely(~str & I8042_STR_OBF)) + return false; - if (i8042_mux_present && (str & I8042_STR_AUXDATA)) { - port_no = i8042_handle_mux(str, &data, &dfl); - } else { + data = i8042_read_data(); - dfl = (str & I8042_STR_PARITY) ? SERIO_PARITY : 0; - if ((str & I8042_STR_TIMEOUT) && !i8042_notimeout) - dfl |= SERIO_TIMEOUT; + if (i8042_mux_present && (str & I8042_STR_AUXDATA)) { + port_no = i8042_handle_mux(str, &data, &dfl); + } else { - port_no = (str & I8042_STR_AUXDATA) ? - I8042_AUX_PORT_NO : I8042_KBD_PORT_NO; - } + dfl = (str & I8042_STR_PARITY) ? SERIO_PARITY : 0; + if ((str & I8042_STR_TIMEOUT) && !i8042_notimeout) + dfl |= SERIO_TIMEOUT; - port = &i8042_ports[port_no]; - serio = port->exists ? port->serio : NULL; + port_no = (str & I8042_STR_AUXDATA) ? + I8042_AUX_PORT_NO : I8042_KBD_PORT_NO; + } - filter_dbg(port->driver_bound, data, "<- i8042 (interrupt, %d, %d%s%s)\n", - port_no, irq, - dfl & SERIO_PARITY ? ", bad parity" : "", - dfl & SERIO_TIMEOUT ? ", timeout" : ""); + port = &i8042_ports[port_no]; + serio = port->exists ? port->serio : NULL; - filtered = i8042_filter(data, str, serio); + filter_dbg(port->driver_bound, + data, "<- i8042 (interrupt, %d, %d%s%s)\n", + port_no, irq, + dfl & SERIO_PARITY ? ", bad parity" : "", + dfl & SERIO_TIMEOUT ? ", timeout" : ""); - spin_unlock_irqrestore(&i8042_lock, flags); + filtered = i8042_filter(data, str, serio); + } if (likely(serio && !filtered)) serio_interrupt(serio, data, dfl); @@ -779,24 +746,22 @@ static bool i8042_irq_being_tested; static irqreturn_t i8042_aux_test_irq(int irq, void *dev_id) { - unsigned long flags; unsigned char str, data; - int ret = 0; - spin_lock_irqsave(&i8042_lock, flags); + guard(spinlock_irqsave)(&i8042_lock); + str = i8042_read_status(); - if (str & I8042_STR_OBF) { - data = i8042_read_data(); - dbg("%02x <- i8042 (aux_test_irq, %s)\n", - data, str & I8042_STR_AUXDATA ? "aux" : "kbd"); - if (i8042_irq_being_tested && - data == 0xa5 && (str & I8042_STR_AUXDATA)) - complete(&i8042_aux_irq_delivered); - ret = 1; - } - spin_unlock_irqrestore(&i8042_lock, flags); + if (!(str & I8042_STR_OBF)) + return IRQ_NONE; + + data = i8042_read_data(); + dbg("%02x <- i8042 (aux_test_irq, %s)\n", + data, str & I8042_STR_AUXDATA ? "aux" : "kbd"); + + if (i8042_irq_being_tested && data == 0xa5 && (str & I8042_STR_AUXDATA)) + complete(&i8042_aux_irq_delivered); - return IRQ_RETVAL(ret); + return IRQ_HANDLED; } /* @@ -837,7 +802,6 @@ static int i8042_check_aux(void) int retval = -1; bool irq_registered = false; bool aux_loop_broken = false; - unsigned long flags; unsigned char param; /* @@ -921,18 +885,15 @@ static int i8042_check_aux(void) if (i8042_enable_aux_port()) goto out; - spin_lock_irqsave(&i8042_lock, flags); - - init_completion(&i8042_aux_irq_delivered); - i8042_irq_being_tested = true; - - param = 0xa5; - retval = __i8042_command(¶m, I8042_CMD_AUX_LOOP & 0xf0ff); - - spin_unlock_irqrestore(&i8042_lock, flags); + scoped_guard(spinlock_irqsave, &i8042_lock) { + init_completion(&i8042_aux_irq_delivered); + i8042_irq_being_tested = true; - if (retval) - goto out; + param = 0xa5; + retval = __i8042_command(¶m, I8042_CMD_AUX_LOOP & 0xf0ff); + if (retval) + goto out; + } if (wait_for_completion_timeout(&i8042_aux_irq_delivered, msecs_to_jiffies(250)) == 0) { @@ -1020,7 +981,6 @@ static int i8042_controller_selftest(void) static int i8042_controller_init(void) { - unsigned long flags; int n = 0; unsigned char ctr[2]; @@ -1057,14 +1017,14 @@ static int i8042_controller_init(void) * Handle keylock. */ - spin_lock_irqsave(&i8042_lock, flags); - if (~i8042_read_status() & I8042_STR_KEYLOCK) { - if (i8042_unlock) - i8042_ctr |= I8042_CTR_IGNKEYLOCK; - else - pr_warn("Warning: Keylock active\n"); + scoped_guard(spinlock_irqsave, &i8042_lock) { + if (~i8042_read_status() & I8042_STR_KEYLOCK) { + if (i8042_unlock) + i8042_ctr |= I8042_CTR_IGNKEYLOCK; + else + pr_warn("Warning: Keylock active\n"); + } } - spin_unlock_irqrestore(&i8042_lock, flags); /* * If the chip is configured into nontranslated mode by the BIOS, don't From patchwork Thu Sep 5 04:17:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791694 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (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 815B014A0B7; Thu, 5 Sep 2024 04:18:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509886; cv=none; b=ZutwQijYEDPYzp3kubf4diBaYwDf40EjX4NRCJm5vSpxlVH4CFTQO6lMoSan4EUEbJj1sJlrYwdzfbuYH1QeJtWZOnfEe1cK6VZb9GYXyF1jzbxtC1bxsojR3UJ+49bYjx39V+6bEHTuFLZnkWgw3NvxnC8p+d5CHavLgf0whqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509886; c=relaxed/simple; bh=6OZz/CQ5C04CYHdb2al2sR2aCuKWbUvrddF0iZDtVw8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jXHHTpflfyGAMSsRI37UbI+S4hyuZp3uiUOSMamEby7p56Si9Gf34+BRaUGB/szehF7FfLOws+EpKNPwNIuhs3lC41bL2krx53zvxlxTPMUi8qb0hkXR31LmzrdBNZFwxJlIOZmjGyEbF494LsTEHsA7FE/HXfCvHx/58zni2Vw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ljD7Mk73; arc=none smtp.client-ip=209.85.210.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ljD7Mk73" Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-70f6a7c4dcdso251221a34.1; Wed, 04 Sep 2024 21:18:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509884; x=1726114684; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p3btFCntery0ta6nV0jjerZVdR60/Gk5jQnmpE6Mqz8=; b=ljD7Mk73zUhiF6Tl5xKQYRZPAMrHI41kgfxhWyjUXJIz+08F3SYBZohHM1URC8bvU0 TjVkT8qeqygdCvqQ+YDvuoYfVRC8F9AY9FBz5TpRRWeiOpc0cPmG9ZdLQWfMKZ0QJoBK qFXwuOYWy5JSwm7OBPL58ZQ88t1YZaFJvbKh63McheN6xesAFZezOYrta+KcY03KjtcO EUrntRXrRJOoG2/wru/ueSMPY/Lxxgf1U9SxOjhwJ1C5/QgsFjWXMUu6F7qyIbgj7AsA 1UeE4AZTU9k7sTmzYiNGgYa2WNYp7EGWMda1RzQ+78YOEPZZIU69SR7TqKaMxMnlsyNv 2z1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509884; x=1726114684; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p3btFCntery0ta6nV0jjerZVdR60/Gk5jQnmpE6Mqz8=; b=EISWYRP7+pU17x5/zSD1qiNebpNK8mYkKt0Uk1vswXgIvWlL3+0xBxj+C7IG/BBmP2 FynMSAAxaUFQj3rB+eBmYgVKsJTlw9nCpyvGgdTG6gBuOpIf1CT4Yktjlsr1Zjh6KbvV p5milQwGJ3f17wVaGd43pT3itnumF6WO+iigeF03jWaxp5aAMuEwc6/1VERVKDG1azwr N6KQG3jqj8cSssjvL1NPJjn/6kP0MnFD+8WpNubmU1TaIlUdDPlEEhFqhgSWtNKzFgf2 9pU88CeQRcF/btCwWtIuU/MWK3brepw7LlYVufYEHTYtgmoS8rbTSMYUt18ucvXwQ5OS 6r/Q== X-Forwarded-Encrypted: i=1; AJvYcCUlLkhvFeFVO+h8x0MeFc2kPF9bPPXiwjccmAvtjGfJB/za0D83SbIUbTEFbnDJVLBbfI/f/m8jKs4MC14=@vger.kernel.org, AJvYcCVAjJIZNxHI/av6YYWTfe/iI71VYLh/OwfnM2r+ZT7wMkKpIsZxh420T2Kpx6cKevtRnUPCSaOE3VjHLSpx@vger.kernel.org X-Gm-Message-State: AOJu0YyJXA/gu16XVZm+l9Q0ti6InjkWUDD0w7/02ddoNeLyICyva0pf 2e6t4Lz9z1HRKl+hV9/+YzoX48WbPs/XKu/+vWipF7WCAkvln0LwA6/ZjA== X-Google-Smtp-Source: AGHT+IFL+aSox2tT+ROcWimEdBXmALGnwGMrd8DuDbiXAmTxOicOS1tEjKJAt+iSvmj/V84cB+BBpg== X-Received: by 2002:a05:6830:349b:b0:709:4793:8757 with SMTP id 46e09a7af769-710af68fc2fmr8717442a34.2.1725509884434; Wed, 04 Sep 2024 21:18:04 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.18.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:18:04 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 14/24] Input: ps2-gpio - use guard notation when acquiring mutex Date: Wed, 4 Sep 2024 21:17:19 -0700 Message-ID: <20240905041732.2034348-15-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that mutexes are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/ps2-gpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/input/serio/ps2-gpio.c b/drivers/input/serio/ps2-gpio.c index 0c8b390b8b4f..c9c382989e55 100644 --- a/drivers/input/serio/ps2-gpio.c +++ b/drivers/input/serio/ps2-gpio.c @@ -133,12 +133,12 @@ static int ps2_gpio_write(struct serio *serio, unsigned char val) int ret = 0; if (in_task()) { - mutex_lock(&drvdata->tx.mutex); + guard(mutex)(&drvdata->tx.mutex); + __ps2_gpio_write(serio, val); if (!wait_for_completion_timeout(&drvdata->tx.complete, msecs_to_jiffies(10000))) ret = SERIO_TIMEOUT; - mutex_unlock(&drvdata->tx.mutex); } else { __ps2_gpio_write(serio, val); } From patchwork Thu Sep 5 04:17:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791695 Received: from mail-oa1-f54.google.com (mail-oa1-f54.google.com [209.85.160.54]) (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 F2141154C0A; Thu, 5 Sep 2024 04:18:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509888; cv=none; b=L+OXDNG5hKpZwhJYbvImxW9v9PYwTT0ReMl2yE3y2DptMsN1TlKgPsFFaLmdpzfb5UpS4gtW6u95HSwp8UzOFoY0F8cujuCM0x0cJxJJ72F/Owa36kSJ1qzJwUB3pOJkJemj5utDOtUWMB/BSHxbd+lZ5uZq/MhntFioEcDNQUc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509888; c=relaxed/simple; bh=XvngD4VqarzUQtOcte+139wHHgYptJyp/bfLvV9NY2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PTt/4u0r+QkS2rD3g+yBWAHox55wRfSxGdOce+ogNftABy1HMc7eea0cyw00cD1xHH/l2UeiNLWvQ1C4vH535iV4hwtjRkJ5bsiMekjYH++m0v27OfLBQt25SjwwLLJhLwiTKRX3fd1FLf1JoaQ0Ad8dX/XcuXoXQk2JpuBHkyU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UeGquxni; arc=none smtp.client-ip=209.85.160.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UeGquxni" Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-277e4327c99so232631fac.0; Wed, 04 Sep 2024 21:18:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509886; x=1726114686; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8RJDHa/X116xPB0VZS9gOnIwjZdjbYo4abWgUGhtfDc=; b=UeGquxni+Rmma1j9ZcwU4QBc8VvMNwDw0ei/+zydACzLxPqN21R8lV7LYFDqY8Rpvs hvdEXlJtAXQ/XshMajnkutukCJO64zlirAUd9S9LPbYXQQRC5b/Tyf1oyt2AP0/fLSLg nykT4lhug+oX0nuOMO/3mfy8CnkQQvVXhOqTCyIFuIVmBBjqCoex3iNgGLRbfG+1RjQt Yb2QkHB8TqRlAr4T5UHD6iboQDOCpt6H7/5EALF5P+Cv3k6XKuF0OvQI9W8+8KLG+hCh eGLt3juvb/S2vvpzrNvSU5ppIZdIhEwWcCx1mzp0vvq71mjwmsH2AtYbOSYMgSkLHJlg oFNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509886; x=1726114686; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8RJDHa/X116xPB0VZS9gOnIwjZdjbYo4abWgUGhtfDc=; b=HFyMU2po3hH+jcGsDz8E8MYUSxXZBZv0tnJId5xhUO9qPaXj7T7H3XZoW0Sy/33P1P TFKFlgXgSdFIX3IcyozAjcD2yZPdnpO6G2sYS4axi6jtpqGa6htxBvXk2Ck7hMX7eFyG hp6lvitU2pKOZVGKOevdfb7GnSTB2z3dnvMkqKQyVEK0uRz8tD/mDmWUjZalZpD/uf2/ mhznnCPLzFD1nhRL/F22lW38AfUPY2fcJdTBnGeIfe1v8cm3pVWObCY1PA3EILQdjfJ2 +hH4eD3xpTsiIANhaZGzgKs2BPe/FFonLhLf4kZyxAK7lN0r9WcJc0xe0zz5KeQZ0gUg 3Fmg== X-Forwarded-Encrypted: i=1; AJvYcCUlP0GotZ/MN7KznyixEksb8EDdf2Axc/hIVQn1MeSLjf9kmmQYDG+kiKSB8jylsP/kO6ajk9odWFrBlFm2@vger.kernel.org, AJvYcCXDeyP3lbe7J6/8BCnnd4gsCAROt7p5t/tn7jSM2I9LgLV9Bz3La2uDWUT0U0JzwXnBV/Go+yZcNaMNd3c=@vger.kernel.org X-Gm-Message-State: AOJu0YzG6YgDqrxgllV9RynekSluah7aJAjOu6zR7qkOGpzFzgzEZv76 k2fYGOMGKu/KmvXHTl/zp/M4C6QW9Ta7+MwuRmeOc+X8WCCR1X8b6muhPw== X-Google-Smtp-Source: AGHT+IH6QFeFw4VUowxHMGT9IipF2N4THVz6A6eh0ihPM11BJx1xPLmHqcSlKYJ5qoFGXbsOklObVw== X-Received: by 2002:a05:6870:6b89:b0:260:ebf7:d0e7 with SMTP id 586e51a60fabf-277d03ac4f7mr18125009fac.15.1725509885896; Wed, 04 Sep 2024 21:18:05 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:18:05 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 15/24] Input: ps2mult - use guard notation when acquiring spinlock Date: Wed, 4 Sep 2024 21:17:20 -0700 Message-ID: <20240905041732.2034348-16-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that locks are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/ps2mult.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/drivers/input/serio/ps2mult.c b/drivers/input/serio/ps2mult.c index 937ecdea491d..b96cee52fc52 100644 --- a/drivers/input/serio/ps2mult.c +++ b/drivers/input/serio/ps2mult.c @@ -76,9 +76,8 @@ static int ps2mult_serio_write(struct serio *serio, unsigned char data) struct ps2mult *psm = serio_get_drvdata(mx_port); struct ps2mult_port *port = serio->port_data; bool need_escape; - unsigned long flags; - spin_lock_irqsave(&psm->lock, flags); + guard(spinlock_irqsave)(&psm->lock); if (psm->out_port != port) ps2mult_select_port(psm, port); @@ -93,8 +92,6 @@ static int ps2mult_serio_write(struct serio *serio, unsigned char data) serio_write(mx_port, data); - spin_unlock_irqrestore(&psm->lock, flags); - return 0; } @@ -102,11 +99,10 @@ static int ps2mult_serio_start(struct serio *serio) { struct ps2mult *psm = serio_get_drvdata(serio->parent); struct ps2mult_port *port = serio->port_data; - unsigned long flags; - spin_lock_irqsave(&psm->lock, flags); + guard(spinlock_irqsave)(&psm->lock); + port->registered = true; - spin_unlock_irqrestore(&psm->lock, flags); return 0; } @@ -115,11 +111,10 @@ static void ps2mult_serio_stop(struct serio *serio) { struct ps2mult *psm = serio_get_drvdata(serio->parent); struct ps2mult_port *port = serio->port_data; - unsigned long flags; - spin_lock_irqsave(&psm->lock, flags); + guard(spinlock_irqsave)(&psm->lock); + port->registered = false; - spin_unlock_irqrestore(&psm->lock, flags); } static int ps2mult_create_port(struct ps2mult *psm, int i) @@ -148,16 +143,12 @@ static int ps2mult_create_port(struct ps2mult *psm, int i) static void ps2mult_reset(struct ps2mult *psm) { - unsigned long flags; - - spin_lock_irqsave(&psm->lock, flags); + guard(spinlock_irqsave)(&psm->lock); serio_write(psm->mx_serio, PS2MULT_SESSION_END); serio_write(psm->mx_serio, PS2MULT_SESSION_START); ps2mult_select_port(psm, &psm->ports[PS2MULT_KBD_PORT]); - - spin_unlock_irqrestore(&psm->lock, flags); } static int ps2mult_connect(struct serio *serio, struct serio_driver *drv) @@ -234,11 +225,10 @@ static irqreturn_t ps2mult_interrupt(struct serio *serio, { struct ps2mult *psm = serio_get_drvdata(serio); struct ps2mult_port *in_port; - unsigned long flags; dev_dbg(&serio->dev, "Received %02x flags %02x\n", data, dfl); - spin_lock_irqsave(&psm->lock, flags); + guard(spinlock_irqsave)(&psm->lock); if (psm->escape) { psm->escape = false; @@ -285,7 +275,6 @@ static irqreturn_t ps2mult_interrupt(struct serio *serio, } out: - spin_unlock_irqrestore(&psm->lock, flags); return IRQ_HANDLED; } From patchwork Thu Sep 5 04:17:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791696 Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) (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 5C73B18BC24; Thu, 5 Sep 2024 04:18:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509890; cv=none; b=egjd6u7CDUrssqEVEjHwGa4FyIxlOTTOsUI3eIPf0xA7H0jLAyJeVEEjIOmnF1uMQscJj/0T/5p+sCvBWEFdiLKnY13aQDxl884lMuT9zLlU+05mgfbcK7Xq9O2mOC3oYd1HJ0y42pzLdGdX3IQuBFdoErPOHppq6ZlbDjVtngc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509890; c=relaxed/simple; bh=vmkU8MnH9ykeMGj0Lb9zkmS8M2GYo6xV57O1AmagHA4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZzPvZ0wrtf10GZcs71oUmuQjrQ8h6PhDUJTykyKJh9btkED7+RobC4tiCHc6JmagEga/8O01ae46Kxq8Wih3RkI4wlaOP8uYpQMgjxAsVC2iiF5jHvaWNPCAmtOpKNJFY5oMs8njl9EgwH2ZodLg5Pi33svs5YdoOKQb3kAZ7Ww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LgadB+tS; arc=none smtp.client-ip=209.85.210.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LgadB+tS" Received: by mail-ot1-f51.google.com with SMTP id 46e09a7af769-70f6a7c4dcdso251236a34.1; Wed, 04 Sep 2024 21:18:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509887; x=1726114687; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zAvYQ5QLNfvwvbAxc5bD+RAm1KaOm8ejwTdtW3p547k=; b=LgadB+tSInEwyJcVWdnybnXRLCztZ7tylvRjv5/NU7VvjHpvNBEKWKflfPpDNSgT8y OxZbiyKCpkx7+YFPBcVC8rDaK93iMYs8j6PU0M4B9CchglWhALNPWenxz3voVK+XWB9i H95VqJwJGoJE0tTdYmjf2+JGQexjin31REqMe5SRmPYroxkJczoYSZdsNVuIL/ka0VYI g5faYigh9HwNbbkC8dQTGyE1Nu0qwEOTE4Rgf/hYFpfJY/AgsCungMDpgJiW4lQqxg9n WDJdM4DPUPQuDa12dGjS2q/FTyTnSWbOMv9KtBlSzPFeyT0RhrwxL9LJsDr5QHzpXGkf PLuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509887; x=1726114687; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zAvYQ5QLNfvwvbAxc5bD+RAm1KaOm8ejwTdtW3p547k=; b=Ger0HSCVWF9o5VncgG+rv94rXnPzQPWSiV44ldxEbiAOyZiid9n30+mJSFQ+vAMYMN SEtO2IVfZ80wVXHPFdTa9kDPmdhJ+DWK6uq3SJLadA/1oBIymUSADrlqyvXizta/BGuV GhMm1udHWPPsuSU2xqpfObwVmkF0S5n/9IDKhJ2pBxJo79OO4jP92K+Wnmc7dUHBjfrA PwXTTUUueGKKXkVTp/o9vsBVOusXFH7V9jlXS/YNFBMxRunc6CWMs842eTMMM6gEun0t Fd2wRAtWfnvumhBlG+q30kvvp2eC9EZazJqBjTpMFQnvqmzIKvrUBXBOSIzfh6+If9Vk 8WBA== X-Forwarded-Encrypted: i=1; AJvYcCUyXwizjy28/W3OKnm+lQwm6geyYk8dJjrKjIsA54WfNhLHxo0IJSO6UjiSbXJQOMdqVmGsq0hEFRJTXQOn@vger.kernel.org, AJvYcCXHjSvOkX58Gx/Pf8Ju03djQ7Juv1FDYVtkZDwnJ7zoG5GIUK/vrn12Oh/CJpv3nbH//phu0CxkfAiy4uo=@vger.kernel.org X-Gm-Message-State: AOJu0YzTfcUwcuLI1XwGymCeme2HIuoBt0kOjgvDusSebqHMt41jIhBK OF9ZVokDjQBHc8cwJQys9oa75L6qmqReRgh4cGmks8Ecji6pTyqdBAnQ2w== X-Google-Smtp-Source: AGHT+IH8XXYpPAwHhXPSp4iUYFOHjf3DLK6g5FeTGZwm65nE42PqOHWe35HEYgcGmzcKxgF6JQHDJQ== X-Received: by 2002:a05:6830:618b:b0:703:77bd:9522 with SMTP id 46e09a7af769-710af6baa99mr9458024a34.17.1725509887298; Wed, 04 Sep 2024 21:18:07 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.18.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:18:06 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 16/24] Input: q40kbd - use guard notation when acquiring spinlock Date: Wed, 4 Sep 2024 21:17:21 -0700 Message-ID: <20240905041732.2034348-17-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that locks are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/q40kbd.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/input/serio/q40kbd.c b/drivers/input/serio/q40kbd.c index cd4d5be946a3..cdd5c4ef9b36 100644 --- a/drivers/input/serio/q40kbd.c +++ b/drivers/input/serio/q40kbd.c @@ -39,17 +39,14 @@ struct q40kbd { static irqreturn_t q40kbd_interrupt(int irq, void *dev_id) { struct q40kbd *q40kbd = dev_id; - unsigned long flags; - spin_lock_irqsave(&q40kbd->lock, flags); + guard(spinlock_irqsave)(&q40kbd->lock); if (Q40_IRQ_KEYB_MASK & master_inb(INTERRUPT_REG)) serio_interrupt(q40kbd->port, master_inb(KEYCODE_REG), 0); master_outb(-1, KEYBOARD_UNLOCK_REG); - spin_unlock_irqrestore(&q40kbd->lock, flags); - return IRQ_HANDLED; } @@ -60,14 +57,11 @@ static irqreturn_t q40kbd_interrupt(int irq, void *dev_id) static void q40kbd_flush(struct q40kbd *q40kbd) { int maxread = 100; - unsigned long flags; - spin_lock_irqsave(&q40kbd->lock, flags); + guard(spinlock_irqsave)(&q40kbd->lock); while (maxread-- && (Q40_IRQ_KEYB_MASK & master_inb(INTERRUPT_REG))) master_inb(KEYCODE_REG); - - spin_unlock_irqrestore(&q40kbd->lock, flags); } static void q40kbd_stop(void) From patchwork Thu Sep 5 04:17:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791697 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) (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 00C3C155326; Thu, 5 Sep 2024 04:18:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509891; cv=none; b=T6VZC9IgZeWX/Xpq63sL5ClwWkKsv22rMpFGGYP+HrPRgAtitocEb92E9p7/k47/mN8akUMlxfgJCIRzbVYKlAEpef99pS1wHvSJ9mvvJVtnLI3+8wawL5Ys0JeSzU2OJlI7J/JOYweCHKSi01W5FlRjZdEWWgmFqqhdfeSiBX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509891; c=relaxed/simple; bh=+xmHtxPCJGTBzSClQJ+yBa81QsqtA24ObFByUE16CfE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WjgekNkN5yBwVKmiTSATAJdSxZN0qWzD34dMvNSGBIx8NQp02kxDXcc2huTZ9gFMhhXb+zGAEusDrNHffCMf3tZ7c/qLYvqRDI7YHE6pu+wUhgDe8IJWxygY4VlFXIDBSfopQ9EA2SfcHfJ4l782oI35+7cx2A8Di7ztdLk5ygE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ILDZvvdl; arc=none smtp.client-ip=209.85.161.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ILDZvvdl" Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-5df998d7a44so211997eaf.2; Wed, 04 Sep 2024 21:18:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509889; x=1726114689; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2hL/oJ8v77sFrESpjTE2muwhc7qNiYaOX9Ne/zSSlqk=; b=ILDZvvdlmDcttsrNTqqBAHO84NZqZt/83IUvkMUoWkqK6pKqzcWFVUpC3f/2IUyosf pTswE1n8oow0OXNn23gQwqbsOA9e2xbhQVfWsCu3zZpI9kJ4jD52R/QtCpFJpSzsUn+F InztcWL1ovbZX0PAb0lTZBzYo+kQyEphIJRJP+0mYOOPduw4TfAC7gvSfuHLB3jbBeka XQ/k2dK6tvegpxP0zeHd8I7SfMejLylRXMZnTkLnGwxWaUAXHH4CRyRmUy17igwMNP5Z vwJvS19Zj1j4e5W1wb9mxo/s4yex6m/FVj58x+7MvIBJJ2L2FZAiai2LtE52GmnVqKkH sPvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509889; x=1726114689; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2hL/oJ8v77sFrESpjTE2muwhc7qNiYaOX9Ne/zSSlqk=; b=qUuQ+zlzDiDkFpXHwNFNrs4BODF+CcvIgh97twpt6RFAJucdBwexTWWWDCvC8U1aGF L+vle/p52C++SHjKAqaX1sPTu2rV3X4wQEHmxbBACeetKw5zgY1WXJqzNC3HBiQ7RP2C jZ0FLSZRUI+gRuAB92lgFnTvk0gsvqWmWTxDJqCwjJWCtyWRwCUjwjgzKlFKcWvMX9EN y9gCgWjouitm/BEkPdQCK4v9g4aHJ8JpjrqcttlCc2VTQ0CfTfy32tsz45yR9cWpIWxn S+BxRtoo02SwwylEt/uyLse5XFTSMqSSpIp5rx+GVuNqf1NXGoLiwOdLAR7joJO8P9oN yFug== X-Forwarded-Encrypted: i=1; AJvYcCULLsLWf8w8TdeIxR+/t7UzTELntAoM2Y9sIagGgsg07leJg0NBKmrxdjFsXHEZ1iEQ0bgaFiRI0SxcFLZt@vger.kernel.org, AJvYcCUMewu8liXtjNyAO5r9BWz1or4O17ldlV519LjeR2/kxtlbOcF6XPPfSqJ1642brybb3JwgyubqK6oJp1M=@vger.kernel.org X-Gm-Message-State: AOJu0Yzbt7+jpjOPL0GZt1IxblU/ZBtiFbxZaDNGm74SGzU4vvPwAi9b 6HZQ770gzxd7acG7QxT9SpCbYfCiV9tC8BkwGbQv9/MuZrwWypqT4br9BA== X-Google-Smtp-Source: AGHT+IHFtlZtt/7jfalAzcdSLrrI2tqquQOXGQfEgeIl9ZKOtYpILy5RI3LJ8SU6F2JK5e0j4C+FUw== X-Received: by 2002:a05:6359:410e:b0:1b5:fa8a:791b with SMTP id e5c5f4694b2df-1b8117ef578mr1137606955d.23.1725509888625; Wed, 04 Sep 2024 21:18:08 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.18.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:18:08 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 17/24] Input: sa1111ps2 - use guard notation when acquiring spinlock Date: Wed, 4 Sep 2024 21:17:22 -0700 Message-ID: <20240905041732.2034348-18-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that locks are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/sa1111ps2.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/input/serio/sa1111ps2.c b/drivers/input/serio/sa1111ps2.c index 1311caf7dba4..375c6f5f905c 100644 --- a/drivers/input/serio/sa1111ps2.c +++ b/drivers/input/serio/sa1111ps2.c @@ -92,7 +92,8 @@ static irqreturn_t ps2_txint(int irq, void *dev_id) struct ps2if *ps2if = dev_id; unsigned int status; - spin_lock(&ps2if->lock); + guard(spinlock)(&ps2if->lock); + status = readl_relaxed(ps2if->base + PS2STAT); if (ps2if->head == ps2if->tail) { disable_irq_nosync(irq); @@ -101,7 +102,6 @@ static irqreturn_t ps2_txint(int irq, void *dev_id) writel_relaxed(ps2if->buf[ps2if->tail], ps2if->base + PS2DATA); ps2if->tail = (ps2if->tail + 1) & (sizeof(ps2if->buf) - 1); } - spin_unlock(&ps2if->lock); return IRQ_HANDLED; } @@ -113,10 +113,9 @@ static irqreturn_t ps2_txint(int irq, void *dev_id) static int ps2_write(struct serio *io, unsigned char val) { struct ps2if *ps2if = io->port_data; - unsigned long flags; unsigned int head; - spin_lock_irqsave(&ps2if->lock, flags); + guard(spinlock_irqsave)(&ps2if->lock); /* * If the TX register is empty, we can go straight out. @@ -133,7 +132,6 @@ static int ps2_write(struct serio *io, unsigned char val) } } - spin_unlock_irqrestore(&ps2if->lock, flags); return 0; } From patchwork Thu Sep 5 04:17:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791698 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (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 19F1F18F2C3; Thu, 5 Sep 2024 04:18:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509893; cv=none; b=fnbpD4C+L5rcWex9qL1Y7LNArYqyoqjZpr7kvnp1IPydP2hXj7FtIhUthOmi9d1FPtNulPXM0Lbwp3GwU1T3p7+DeFatBrnKgxZwC034sCT/JbZXXu8ut2pI37xdQNgw2WIgAwUEqJsmn8SV8uLc0DXqNEIY8KZqTJQi+jEKDus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509893; c=relaxed/simple; bh=1ANKjU3VKrs6X/QdpJ9WLabYERlHb97KjzLTZSjxQWk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XX41ubWeu+Ujw7qlNLfSu2iLLkclqMqFyxNxJCvagIQCQVXNb9Ji9eqv3uLwlbKO3VnwH46LjVCVJS+a+73VdLJZA8m67fS0zMrdrtg7fbUy37tpEKuVFe2KMKXq825vsAe4+wFSF0Hc6uZ8tMr2df6xPPMfVKTSHdQnY8UNnUQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FZ8jOGk1; arc=none smtp.client-ip=209.85.210.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FZ8jOGk1" Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-70f6e65d605so210223a34.3; Wed, 04 Sep 2024 21:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509890; x=1726114690; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zdj97WNnHfmaSgwSXHcMMW5oApE6Xxi6ExD1cTeMbgs=; b=FZ8jOGk1yZWfOKa+fHpy5E7ST+zv1Vlz7LYPzbmcgOh1hffumkdJEzb8k6jw5/bQG2 ogq9NxMdiV4qiXCdzAyTIWT6W6PUiL8MWMjORDoY2jswqNyV8yIAb55XdVsdQXZh0KJd SJ53uxXXOF/U35jPYgmmf3f5BOlm4BKhUSLzM5ngZ0MJKRweFq3HLQHTx7gZhGyqaD+K iXkRbmwFPbAOnqcquTC4yOxSWk178uu3jiLMDkS0jXa1shHoZo1IPaG3IZoyrDNzCgzd Jv4k0mg5LW+kvFScxEGY/E3vNPrNgP8391wlIBDEj+rToL7e6IEOk2dX8QP/v7LdMvHj SojA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509890; x=1726114690; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zdj97WNnHfmaSgwSXHcMMW5oApE6Xxi6ExD1cTeMbgs=; b=YCTbgSwiIr4kp+viKfC9vgKCaPyyjKhiRZjOdxnED2teIWm9wxvRxHCBEjf3fEPDrz mnbMXai55MrBpWpvbblrtGXGteA7BcsG7h0lsrdinXJ3QOYx7GK9rCKQ+9tbLH64KaUF fwXd+aVKR3bWFoAgnokfaYid4P6PBdidOXypSrPkR7xixQnYflhdsCxn9D9Zr2ePwM/l OofMO35KG9VesrQYo2R+sznOvsB+Q2xrXEGyo2j9qSdEOCUBmWhn+SnHWR30Wt9Mcy2t js+Jv4JtA4MxarL+6oRoh4wltYyppCIEz8oSNWLqQYgAIqD9b66zguPxEm39T1avwKjy vgiA== X-Forwarded-Encrypted: i=1; AJvYcCVlUvmvqvtYzgPajtLXNSFkfcSzsameyVZ8KyR7CwFizsWTnWrQyEH5k3yV6KNu+e8m0KH76IBSJDxJnWs=@vger.kernel.org, AJvYcCWPw7HmyKJbgC3wWly/FDn3iz04uMmeN0V0MMxBSxg/boK5dUWHT2aETiIlANmr50nMJAzRdlK/n8fTzkM5@vger.kernel.org X-Gm-Message-State: AOJu0YxwGAjHTWavlgWkLx9c3f2CkUVu5GKv4Ql46OvOb+6BXIXYpGX9 Lq7dgT2cW2EI42FOOa2tHWL6+A9gdV03aYsYz2MVbFWrmsJnRPao16ym3w== X-Google-Smtp-Source: AGHT+IEMAZJeCSqiHRSgN3+WWWCHuQRgdHGicuqXLtwn/x3wJa2d1mAi8u8uVrAj+0Ri9jh32shyow== X-Received: by 2002:a05:6830:6e8f:b0:70f:7752:3967 with SMTP id 46e09a7af769-70f77523c01mr18497699a34.27.1725509890118; Wed, 04 Sep 2024 21:18:10 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.18.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:18:09 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 18/24] Input: serport - use guard notation when acquiring spinlock Date: Wed, 4 Sep 2024 21:17:23 -0700 Message-ID: <20240905041732.2034348-19-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that locks are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/serport.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c index 5a2b5404ffc2..74ac88796187 100644 --- a/drivers/input/serio/serport.c +++ b/drivers/input/serio/serport.c @@ -50,11 +50,9 @@ static int serport_serio_write(struct serio *serio, unsigned char data) static int serport_serio_open(struct serio *serio) { struct serport *serport = serio->port_data; - unsigned long flags; - spin_lock_irqsave(&serport->lock, flags); + guard(spinlock_irqsave)(&serport->lock); set_bit(SERPORT_ACTIVE, &serport->flags); - spin_unlock_irqrestore(&serport->lock, flags); return 0; } @@ -63,11 +61,9 @@ static int serport_serio_open(struct serio *serio) static void serport_serio_close(struct serio *serio) { struct serport *serport = serio->port_data; - unsigned long flags; - spin_lock_irqsave(&serport->lock, flags); + guard(spinlock_irqsave)(&serport->lock); clear_bit(SERPORT_ACTIVE, &serport->flags); - spin_unlock_irqrestore(&serport->lock, flags); } /* @@ -118,14 +114,13 @@ static void serport_ldisc_receive(struct tty_struct *tty, const u8 *cp, const u8 *fp, size_t count) { struct serport *serport = tty->disc_data; - unsigned long flags; unsigned int ch_flags = 0; int i; - spin_lock_irqsave(&serport->lock, flags); + guard(spinlock_irqsave)(&serport->lock); if (!test_bit(SERPORT_ACTIVE, &serport->flags)) - goto out; + return; for (i = 0; i < count; i++) { if (fp) { @@ -146,9 +141,6 @@ static void serport_ldisc_receive(struct tty_struct *tty, const u8 *cp, serio_interrupt(serport->serio, cp[i], ch_flags); } - -out: - spin_unlock_irqrestore(&serport->lock, flags); } /* @@ -246,11 +238,9 @@ static int serport_ldisc_compat_ioctl(struct tty_struct *tty, static void serport_ldisc_hangup(struct tty_struct *tty) { struct serport *serport = tty->disc_data; - unsigned long flags; - spin_lock_irqsave(&serport->lock, flags); - set_bit(SERPORT_DEAD, &serport->flags); - spin_unlock_irqrestore(&serport->lock, flags); + scoped_guard(spinlock_irqsave, &serport->lock) + set_bit(SERPORT_DEAD, &serport->flags); wake_up_interruptible(&serport->wait); } @@ -258,12 +248,11 @@ static void serport_ldisc_hangup(struct tty_struct *tty) static void serport_ldisc_write_wakeup(struct tty_struct * tty) { struct serport *serport = tty->disc_data; - unsigned long flags; - spin_lock_irqsave(&serport->lock, flags); + guard(spinlock_irqsave)(&serport->lock); + if (test_bit(SERPORT_ACTIVE, &serport->flags)) serio_drv_write_wakeup(serport->serio); - spin_unlock_irqrestore(&serport->lock, flags); } /* From patchwork Thu Sep 5 04:17:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791700 Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (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 177CC192584; Thu, 5 Sep 2024 04:18:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509895; cv=none; b=VCXMNa4mTBY05JhbyScVfxZFiY8MW3y4s879hMheKww+MyqolffUtXy2OddIvDrfDvtHIMkvAX2DnNPLM7TT7uCQ/LnHH9indVz0ezsmpjq5kL7VYq2FVwqcmvedJ8hQFvTbItgR+JqUSw6pslS3emhnMUwrTkqq5Lw1qRSPlDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509895; c=relaxed/simple; bh=pakshvX2RA3yQrO6ycKRxTchHdBk7nScpIeEjlcuObQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N9UTWFgzI2WL9qIPKWdo9USb32W78M9cXOoZ0nRTpmAvuSo2gllKRuUdA2NK0PkcF+HBxWo9RHTignPeJkFzykeOH+k+nm+fF/SzPAURJo4EinpL0r/9j0/Bh2rdypHLGBoIXKYxl05gGdILJ9SPXU44qZgrg2fknnUPfl/BsN4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mTR2Qcg+; arc=none smtp.client-ip=209.85.167.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mTR2Qcg+" Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3e0059dc06bso207846b6e.0; Wed, 04 Sep 2024 21:18:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509892; x=1726114692; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NPWoWt+316Jv4PRkQXpmOTDxa9BtNdvynfRmo3h2lZU=; b=mTR2Qcg+FTPbf3Fx3MuJWFtGEtM8fT14FL5OCSng7j9bad0+vslsSkVmIjc+VQj7GC mfMd9AMLh4dxSMKPq+i9vsSIDKY9Fx0VZdvFpIc38FAQtMXXciqJfNwu9wdVJNWg+Dit DGvv0larftvwh5MGq0vdajNP4ZMFVr7FCNOHs8HZQ+cp1A8ntMfFDWtloyogOpbXFFIq WXT6rfh4IQKAq85wlol4RkleXQrffaMy+vTI5ICrPah4xxGdfnzhR4FCuLk7pCNFzIEy PXYhkn02QFRjM1tE/YrIGF7clQvDJqueWnK+CVb/N0newAHMmLobe17j/WlgSmzc19HQ V2xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509892; x=1726114692; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NPWoWt+316Jv4PRkQXpmOTDxa9BtNdvynfRmo3h2lZU=; b=Q3NBu+6AzoUDEyXo/nT6o99N8/Pxp+t0BANyQYRZws0c25GIlqUlEdzF8WhOsbibvk oTo2KmK7ncVshChk74n96sFMOfAMkQlrNOp0gGK6XLZf+UmF07+FEnLdT5sr3tbPf3Xd K7XwjoKgn+Ry5CHwDVTvJRe23UWIfxgU8LXlbvC1PgP0J9sshSI8fPQtN8WENfQtk9Cz vUvxVwSxH3JUT4tJt/2XOA3IN0JphHM8VLo3Ri/onz3ri8xL6HnVmsZA2zlIx8uuk9l4 SotnAkmvJ8lXouT9O7/6GwqZSuahyYaEfM7eMNB0IJDzclWzOmKEskvFyslJCwfpuuw9 zXWQ== X-Forwarded-Encrypted: i=1; AJvYcCUbGgFw+s37DS3S46atUfhw5Wjz2WVmmOK//jgDb61hyUS1VrndzBlxI9osFOBtv+2kLXhBwBUcKBuf0+9Z@vger.kernel.org, AJvYcCWao+MYF/gSQC7b5Q5a3qNZQ0rFobhylwsaiHUcrLkRuNZ79iaN6tnMBgZLiTqkt3li3AZodJhDYfKlaAA=@vger.kernel.org X-Gm-Message-State: AOJu0YxVwdt9Cq7dnC0JIizF26yeIvGOXEXfcR/Tx9Rv2nIFgSxVPD8l 4ToCaLdvbs5T0t9uhBiE/9X36WN8dXv+it+V8iNBkD8cI2kapNb08GVAww== X-Google-Smtp-Source: AGHT+IFtOulSXoC/ctTuMj+I0PsDPFtHbtTpoHZ22Oz6oQvpBi8n8BbUuwVttzMnsxsQEnZDRv+dFQ== X-Received: by 2002:a05:6808:bd6:b0:3d6:3450:7fe0 with SMTP id 5614622812f47-3df21eea911mr18954848b6e.9.1725509891740; Wed, 04 Sep 2024 21:18:11 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.18.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:18:11 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 19/24] Input: serio - use guard notation when acquiring mutexes and spinlocks Date: Wed, 4 Sep 2024 21:17:24 -0700 Message-ID: <20240905041732.2034348-20-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that locks are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/serio.c | 164 ++++++++++++++---------------------- 1 file changed, 65 insertions(+), 99 deletions(-) diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c index 29a2b13a8cf5..aa386eb37a16 100644 --- a/drivers/input/serio/serio.c +++ b/drivers/input/serio/serio.c @@ -37,33 +37,27 @@ static void serio_reconnect_subtree(struct serio *serio); static int serio_connect_driver(struct serio *serio, struct serio_driver *drv) { - int retval; - - mutex_lock(&serio->drv_mutex); - retval = drv->connect(serio, drv); - mutex_unlock(&serio->drv_mutex); + guard(mutex)(&serio->drv_mutex); - return retval; + return drv->connect(serio, drv); } static int serio_reconnect_driver(struct serio *serio) { - int retval = -1; + guard(mutex)(&serio->drv_mutex); - mutex_lock(&serio->drv_mutex); if (serio->drv && serio->drv->reconnect) - retval = serio->drv->reconnect(serio); - mutex_unlock(&serio->drv_mutex); + return serio->drv->reconnect(serio); - return retval; + return -1; } static void serio_disconnect_driver(struct serio *serio) { - mutex_lock(&serio->drv_mutex); + guard(mutex)(&serio->drv_mutex); + if (serio->drv) serio->drv->disconnect(serio); - mutex_unlock(&serio->drv_mutex); } static int serio_match_port(const struct serio_device_id *ids, struct serio *serio) @@ -145,9 +139,8 @@ static LIST_HEAD(serio_event_list); static struct serio_event *serio_get_event(void) { struct serio_event *event = NULL; - unsigned long flags; - spin_lock_irqsave(&serio_event_lock, flags); + guard(spinlock_irqsave)(&serio_event_lock); if (!list_empty(&serio_event_list)) { event = list_first_entry(&serio_event_list, @@ -155,7 +148,6 @@ static struct serio_event *serio_get_event(void) list_del_init(&event->node); } - spin_unlock_irqrestore(&serio_event_lock, flags); return event; } @@ -169,9 +161,8 @@ static void serio_remove_duplicate_events(void *object, enum serio_event_type type) { struct serio_event *e, *next; - unsigned long flags; - spin_lock_irqsave(&serio_event_lock, flags); + guard(spinlock_irqsave)(&serio_event_lock); list_for_each_entry_safe(e, next, &serio_event_list, node) { if (object == e->object) { @@ -187,15 +178,13 @@ static void serio_remove_duplicate_events(void *object, serio_free_event(e); } } - - spin_unlock_irqrestore(&serio_event_lock, flags); } static void serio_handle_event(struct work_struct *work) { struct serio_event *event; - mutex_lock(&serio_mutex); + guard(mutex)(&serio_mutex); while ((event = serio_get_event())) { @@ -222,8 +211,6 @@ static void serio_handle_event(struct work_struct *work) serio_remove_duplicate_events(event->object, event->type); serio_free_event(event); } - - mutex_unlock(&serio_mutex); } static DECLARE_WORK(serio_event_work, serio_handle_event); @@ -231,11 +218,9 @@ static DECLARE_WORK(serio_event_work, serio_handle_event); static int serio_queue_event(void *object, struct module *owner, enum serio_event_type event_type) { - unsigned long flags; struct serio_event *event; - int retval = 0; - spin_lock_irqsave(&serio_event_lock, flags); + guard(spinlock_irqsave)(&serio_event_lock); /* * Scan event list for the other events for the same serio port, @@ -247,7 +232,7 @@ static int serio_queue_event(void *object, struct module *owner, list_for_each_entry_reverse(event, &serio_event_list, node) { if (event->object == object) { if (event->type == event_type) - goto out; + return 0; break; } } @@ -255,16 +240,14 @@ static int serio_queue_event(void *object, struct module *owner, event = kmalloc(sizeof(*event), GFP_ATOMIC); if (!event) { pr_err("Not enough memory to queue event %d\n", event_type); - retval = -ENOMEM; - goto out; + return -ENOMEM; } if (!try_module_get(owner)) { pr_warn("Can't get module reference, dropping event %d\n", event_type); kfree(event); - retval = -EINVAL; - goto out; + return -EINVAL; } event->type = event_type; @@ -274,9 +257,7 @@ static int serio_queue_event(void *object, struct module *owner, list_add_tail(&event->node, &serio_event_list); queue_work(system_long_wq, &serio_event_work); -out: - spin_unlock_irqrestore(&serio_event_lock, flags); - return retval; + return 0; } /* @@ -286,9 +267,8 @@ static int serio_queue_event(void *object, struct module *owner, static void serio_remove_pending_events(void *object) { struct serio_event *event, *next; - unsigned long flags; - spin_lock_irqsave(&serio_event_lock, flags); + guard(spinlock_irqsave)(&serio_event_lock); list_for_each_entry_safe(event, next, &serio_event_list, node) { if (event->object == object) { @@ -296,8 +276,6 @@ static void serio_remove_pending_events(void *object) serio_free_event(event); } } - - spin_unlock_irqrestore(&serio_event_lock, flags); } /* @@ -309,23 +287,19 @@ static void serio_remove_pending_events(void *object) static struct serio *serio_get_pending_child(struct serio *parent) { struct serio_event *event; - struct serio *serio, *child = NULL; - unsigned long flags; + struct serio *serio; - spin_lock_irqsave(&serio_event_lock, flags); + guard(spinlock_irqsave)(&serio_event_lock); list_for_each_entry(event, &serio_event_list, node) { if (event->type == SERIO_REGISTER_PORT) { serio = event->object; - if (serio->parent == parent) { - child = serio; - break; - } + if (serio->parent == parent) + return serio; } } - spin_unlock_irqrestore(&serio_event_lock, flags); - return child; + return NULL; } /* @@ -376,29 +350,26 @@ static ssize_t drvctl_store(struct device *dev, struct device_attribute *attr, c struct device_driver *drv; int error; - error = mutex_lock_interruptible(&serio_mutex); - if (error) - return error; - - if (!strncmp(buf, "none", count)) { - serio_disconnect_port(serio); - } else if (!strncmp(buf, "reconnect", count)) { - serio_reconnect_subtree(serio); - } else if (!strncmp(buf, "rescan", count)) { - serio_disconnect_port(serio); - serio_find_driver(serio); - serio_remove_duplicate_events(serio, SERIO_RESCAN_PORT); - } else if ((drv = driver_find(buf, &serio_bus)) != NULL) { - serio_disconnect_port(serio); - error = serio_bind_driver(serio, to_serio_driver(drv)); - serio_remove_duplicate_events(serio, SERIO_RESCAN_PORT); - } else { - error = -EINVAL; + scoped_cond_guard(mutex_intr, return -EINTR, &serio_mutex) { + if (!strncmp(buf, "none", count)) { + serio_disconnect_port(serio); + } else if (!strncmp(buf, "reconnect", count)) { + serio_reconnect_subtree(serio); + } else if (!strncmp(buf, "rescan", count)) { + serio_disconnect_port(serio); + serio_find_driver(serio); + serio_remove_duplicate_events(serio, SERIO_RESCAN_PORT); + } else if ((drv = driver_find(buf, &serio_bus)) != NULL) { + serio_disconnect_port(serio); + error = serio_bind_driver(serio, to_serio_driver(drv)); + serio_remove_duplicate_events(serio, SERIO_RESCAN_PORT); + return error; + } else { + return -EINVAL; + } } - mutex_unlock(&serio_mutex); - - return error ? error : count; + return count; } static ssize_t serio_show_bind_mode(struct device *dev, struct device_attribute *attr, char *buf) @@ -520,9 +491,9 @@ static void serio_add_port(struct serio *serio) int error; if (parent) { - serio_pause_rx(parent); + guard(serio_pause_rx)(parent); + list_add_tail(&serio->child_node, &parent->children); - serio_continue_rx(parent); } list_add_tail(&serio->node, &serio_list); @@ -554,9 +525,9 @@ static void serio_destroy_port(struct serio *serio) serio->stop(serio); if (serio->parent) { - serio_pause_rx(serio->parent); + guard(serio_pause_rx)(serio->parent); + list_del_init(&serio->child_node); - serio_continue_rx(serio->parent); serio->parent = NULL; } @@ -697,10 +668,10 @@ EXPORT_SYMBOL(__serio_register_port); */ void serio_unregister_port(struct serio *serio) { - mutex_lock(&serio_mutex); + guard(mutex)(&serio_mutex); + serio_disconnect_port(serio); serio_destroy_port(serio); - mutex_unlock(&serio_mutex); } EXPORT_SYMBOL(serio_unregister_port); @@ -711,12 +682,12 @@ void serio_unregister_child_port(struct serio *serio) { struct serio *s, *next; - mutex_lock(&serio_mutex); + guard(mutex)(&serio_mutex); + list_for_each_entry_safe(s, next, &serio->children, child_node) { serio_disconnect_port(s); serio_destroy_port(s); } - mutex_unlock(&serio_mutex); } EXPORT_SYMBOL(serio_unregister_child_port); @@ -780,10 +751,10 @@ static void serio_driver_remove(struct device *dev) static void serio_cleanup(struct serio *serio) { - mutex_lock(&serio->drv_mutex); + guard(mutex)(&serio->drv_mutex); + if (serio->drv && serio->drv->cleanup) serio->drv->cleanup(serio); - mutex_unlock(&serio->drv_mutex); } static void serio_shutdown(struct device *dev) @@ -822,7 +793,7 @@ void serio_unregister_driver(struct serio_driver *drv) { struct serio *serio; - mutex_lock(&serio_mutex); + guard(mutex)(&serio_mutex); drv->manual_bind = true; /* so serio_find_driver ignores it */ @@ -837,15 +808,14 @@ void serio_unregister_driver(struct serio_driver *drv) } driver_unregister(&drv->driver); - mutex_unlock(&serio_mutex); } EXPORT_SYMBOL(serio_unregister_driver); static void serio_set_drv(struct serio *serio, struct serio_driver *drv) { - serio_pause_rx(serio); + guard(serio_pause_rx)(serio); + serio->drv = drv; - serio_continue_rx(serio); } static int serio_bus_match(struct device *dev, struct device_driver *drv) @@ -906,14 +876,14 @@ static int serio_resume(struct device *dev) struct serio *serio = to_serio_port(dev); int error = -ENOENT; - mutex_lock(&serio->drv_mutex); - if (serio->drv && serio->drv->fast_reconnect) { - error = serio->drv->fast_reconnect(serio); - if (error && error != -ENOENT) - dev_warn(dev, "fast reconnect failed with error %d\n", - error); + scoped_guard(mutex, &serio->drv_mutex) { + if (serio->drv && serio->drv->fast_reconnect) { + error = serio->drv->fast_reconnect(serio); + if (error && error != -ENOENT) + dev_warn(dev, "fast reconnect failed with error %d\n", + error); + } } - mutex_unlock(&serio->drv_mutex); if (error) { /* @@ -960,21 +930,17 @@ EXPORT_SYMBOL(serio_close); irqreturn_t serio_interrupt(struct serio *serio, unsigned char data, unsigned int dfl) { - unsigned long flags; - irqreturn_t ret = IRQ_NONE; + guard(spinlock_irqsave)(&serio->lock); - spin_lock_irqsave(&serio->lock, flags); + if (likely(serio->drv)) + return serio->drv->interrupt(serio, data, dfl); - if (likely(serio->drv)) { - ret = serio->drv->interrupt(serio, data, dfl); - } else if (!dfl && device_is_registered(&serio->dev)) { + if (!dfl && device_is_registered(&serio->dev)) { serio_rescan(serio); - ret = IRQ_HANDLED; + return IRQ_HANDLED; } - spin_unlock_irqrestore(&serio->lock, flags); - - return ret; + return IRQ_NONE; } EXPORT_SYMBOL(serio_interrupt); From patchwork Thu Sep 5 04:17:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791699 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 4F50E155393; Thu, 5 Sep 2024 04:18:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509895; cv=none; b=JTU3vn6W673uvgTkN28z7WHyx7Qf6e3ipIdKE+fVWc3Wc646tzLatyvYxrnrYCoCuEOInIOM4wx9a3dVxdabswOUZeR/VNgI5j3GQYJDnV4uQfVJDhweivaqqtiRPb2a3Cp/XuA3ObfropoNdqfXsIBZNTQeErEjoLDmGOdKw7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509895; c=relaxed/simple; bh=cJYWxYF5OhQ8taYCVKZbQ3/a9KN9ESKsltEQmoM54CM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y17GHb2Xu/LtNy+qAFJXqgm1LJBCuZbTgfPnWk8JR4ERueYNG+537nLPXPVjwXk81w1J1HLb6nOf8qX3xldom80tlW0mi5Hlo7X1U+HGhJ3FI5uSGwJ9rVP0hvCguqYZ+FNACS76h7uxqf8+3SOM5dwG9J03jkrFv+R4dc/pFoQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=G88cEEzu; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G88cEEzu" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-715cdc7a153so246256b3a.0; Wed, 04 Sep 2024 21:18:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509893; x=1726114693; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j96TxrzClXBkhwjMJZl6JNr36upS20Gw21hZhz5UEQc=; b=G88cEEzuTfHbOGDMiZtix5KnsuD5JHZeJV54m49kbPyeKOQGwd1MOiiggNgEiHPW6c 2KfS7StYAQW2pwr3UVxlOPY1JmZ60XpKb0G8wy7nwF597GV8L7u2nUhoOA897FRj46s4 M12tOGVGl0EVFui2GN3x9ClKtTeFU1Fq3r5JUDd+QTvZ1Ybb4TF+WzlEInuac6PHnVxJ /elmEU/Hu0wN/vvhk0/Js+tp8ibYn3L1q4yBvjoljPCFslcIrG6+QTkBCNkFJTiCp04h E7haNGRkOY6/5+O5jybfxk3GR4IVqmeRI6tZ0ZE/feb2YVasEipuZ3Ay3TvAfUoOJpux wmxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509893; x=1726114693; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j96TxrzClXBkhwjMJZl6JNr36upS20Gw21hZhz5UEQc=; b=OF6yW0l6t0cK/xkY3gaxsji7rd8fLCDH/jjRYByvgqZZ2AR2/94yxv+6NDTlk8nJpd iAGx4gQAAsap6VqYxG5i+VYcN1x1Zsmnsa+5QAuxfjZ91kKodxxi7plZcLwKQUSQvwQw Il+9/PO3yPFAYD0Ohto/h6a2pK9GscUZs2cPntD09KfohZJsqPyWlL0voqXvCR0HWKcC mtatpr9I9CxVx5WCl5hnlVNwk9O35FdWxzhaq58WLo/7KfrJtsHNLZbjjMySQAnkzN2c w/l8L8a0716FP3y7jxEDP7KDwTTGY+UZI7dcHVoXYmOZhJTgDUpw4oAkrAPcj3OmscZy nLCQ== X-Forwarded-Encrypted: i=1; AJvYcCUPol0KTULhLqJjdY1dpAAPrMp16zmu1Htkt2+lBfsWZKi74i6NX/3Jal4Fbrunpq4zeOqfykbsQdyor8o1@vger.kernel.org, AJvYcCVD1nw2JMeEXWMNnn/IbiaOxQRwsvUTM3tFO7uf8s5yvAJveSxxoFeo9nivRCI9+INslsJieySUg8V3QTc=@vger.kernel.org X-Gm-Message-State: AOJu0YyOv7UGt7u0gQCjQ4hnGziAA9lSekFvjmIaBRLIjjAtlZcp0aWQ fm7PymWAXSCGATyGupAxA370qPYYIvTauPrHLHymXXkhTn60Ec2A/wt0uw== X-Google-Smtp-Source: AGHT+IEtbS6Hh36TyocrzyvtNt8382uDa9MHZZCYVlpcXz+bDRK1U/OJOVBLjLQwYZ/02bwTa26XXA== X-Received: by 2002:a05:6a20:4c10:b0:1cc:d5d1:fe64 with SMTP id adf61e73a8af0-1cf0803a591mr6663245637.14.1725509893151; Wed, 04 Sep 2024 21:18:13 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.18.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:18:12 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 20/24] Input: serio_raw - use guard notation for locks and other resources Date: Wed, 4 Sep 2024 21:17:25 -0700 Message-ID: <20240905041732.2034348-21-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use guard notation when acquiring mutexes and spinlocks, and when pausing and resuming serio port. Such guard notation makes the code more compact and error handling more robust by ensuring that locks are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/serio_raw.c | 121 +++++++++++++------------------- 1 file changed, 49 insertions(+), 72 deletions(-) diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c index 0186d1b38f49..aef8301313b2 100644 --- a/drivers/input/serio/serio_raw.c +++ b/drivers/input/serio/serio_raw.c @@ -75,41 +75,31 @@ static int serio_raw_open(struct inode *inode, struct file *file) { struct serio_raw *serio_raw; struct serio_raw_client *client; - int retval; - retval = mutex_lock_interruptible(&serio_raw_mutex); - if (retval) - return retval; + scoped_guard(mutex_intr, &serio_raw_mutex) { + serio_raw = serio_raw_locate(iminor(inode)); + if (!serio_raw) + return -ENODEV; - serio_raw = serio_raw_locate(iminor(inode)); - if (!serio_raw) { - retval = -ENODEV; - goto out; - } + if (serio_raw->dead) + return -ENODEV; - if (serio_raw->dead) { - retval = -ENODEV; - goto out; - } + client = kzalloc(sizeof(*client), GFP_KERNEL); + if (!client) + return -ENOMEM; - client = kzalloc(sizeof(*client), GFP_KERNEL); - if (!client) { - retval = -ENOMEM; - goto out; - } + client->serio_raw = serio_raw; + file->private_data = client; - client->serio_raw = serio_raw; - file->private_data = client; + kref_get(&serio_raw->kref); - kref_get(&serio_raw->kref); + scoped_guard(serio_pause_rx, serio_raw->serio) + list_add_tail(&client->node, &serio_raw->client_list); - serio_pause_rx(serio_raw->serio); - list_add_tail(&client->node, &serio_raw->client_list); - serio_continue_rx(serio_raw->serio); + return 0; + } -out: - mutex_unlock(&serio_raw_mutex); - return retval; + return -EINTR; } static void serio_raw_free(struct kref *kref) @@ -126,9 +116,8 @@ static int serio_raw_release(struct inode *inode, struct file *file) struct serio_raw_client *client = file->private_data; struct serio_raw *serio_raw = client->serio_raw; - serio_pause_rx(serio_raw->serio); - list_del(&client->node); - serio_continue_rx(serio_raw->serio); + scoped_guard(serio_pause_rx, serio_raw->serio) + list_del(&client->node); kfree(client); @@ -139,19 +128,15 @@ static int serio_raw_release(struct inode *inode, struct file *file) static bool serio_raw_fetch_byte(struct serio_raw *serio_raw, char *c) { - bool empty; + guard(serio_pause_rx)(serio_raw->serio); - serio_pause_rx(serio_raw->serio); - - empty = serio_raw->head == serio_raw->tail; - if (!empty) { - *c = serio_raw->queue[serio_raw->tail]; - serio_raw->tail = (serio_raw->tail + 1) % SERIO_RAW_QUEUE_LEN; - } + if (serio_raw->head == serio_raw->tail) + return false; /* queue is empty */ - serio_continue_rx(serio_raw->serio); + *c = serio_raw->queue[serio_raw->tail]; + serio_raw->tail = (serio_raw->tail + 1) % SERIO_RAW_QUEUE_LEN; - return !empty; + return true; } static ssize_t serio_raw_read(struct file *file, char __user *buffer, @@ -200,40 +185,32 @@ static ssize_t serio_raw_write(struct file *file, const char __user *buffer, { struct serio_raw_client *client = file->private_data; struct serio_raw *serio_raw = client->serio_raw; - int retval = 0; + int written; unsigned char c; - retval = mutex_lock_interruptible(&serio_raw_mutex); - if (retval) - return retval; + scoped_guard(mutex_intr, &serio_raw_mutex) { + if (serio_raw->dead) + return -ENODEV; - if (serio_raw->dead) { - retval = -ENODEV; - goto out; - } + if (count > 32) + count = 32; - if (count > 32) - count = 32; + while (count--) { + if (get_user(c, buffer++)) + return -EFAULT; - while (count--) { - if (get_user(c, buffer++)) { - retval = -EFAULT; - goto out; - } + if (serio_write(serio_raw->serio, c)) { + /* Either signal error or partial write */ + return written ?: -EIO; + } - if (serio_write(serio_raw->serio, c)) { - /* Either signal error or partial write */ - if (retval == 0) - retval = -EIO; - goto out; + written++; } - retval++; + return written; } -out: - mutex_unlock(&serio_raw_mutex); - return retval; + return -EINTR; } static __poll_t serio_raw_poll(struct file *file, poll_table *wait) @@ -379,10 +356,10 @@ static void serio_raw_hangup(struct serio_raw *serio_raw) { struct serio_raw_client *client; - serio_pause_rx(serio_raw->serio); - list_for_each_entry(client, &serio_raw->client_list, node) - kill_fasync(&client->fasync, SIGIO, POLL_HUP); - serio_continue_rx(serio_raw->serio); + scoped_guard(serio_pause_rx, serio_raw->serio) { + list_for_each_entry(client, &serio_raw->client_list, node) + kill_fasync(&client->fasync, SIGIO, POLL_HUP); + } wake_up_interruptible(&serio_raw->wait); } @@ -394,10 +371,10 @@ static void serio_raw_disconnect(struct serio *serio) misc_deregister(&serio_raw->dev); - mutex_lock(&serio_raw_mutex); - serio_raw->dead = true; - list_del_init(&serio_raw->node); - mutex_unlock(&serio_raw_mutex); + scoped_guard(mutex, &serio_raw_mutex) { + serio_raw->dead = true; + list_del_init(&serio_raw->node); + } serio_raw_hangup(serio_raw); From patchwork Thu Sep 5 04:17:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791701 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (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 AF0A11925A7; Thu, 5 Sep 2024 04:18:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509897; cv=none; b=sTTZuPuxY6PDi9IDPry+r6KNR7TI/YkvJJU5+wI5r+eGEy0584D4sBybXpkFgeXDnq2HT2CZvOLL+zWT41WEf8FwnZO1h9Fp4GthrFVwKbUkXO0/t8U1YpWFGPrFpxnds8W8gb37RmCKy1wU1LVYV7j9sKZnkx5WEcUWhL5/ywA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509897; c=relaxed/simple; bh=komCIO/1EqUhOEh024NdqNhz+3ocvxMCYj+7ZMEMtMI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CONYJ2uuZwr3KtlRownIFbFzzYTfQl5To6odufs0lWvazRYNO3A8pN4xbISJ2gfuVUh34UNC/3SHEGbgjI2CUmn4dr97LwK5Frr80PkslmJLw1LogBezfqfSBMrSBOnh4qdJWr2BL1jPhvFrtAuSzaY0KSpcuuegFa+4upK5m0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XkYKxCn1; arc=none smtp.client-ip=209.85.210.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XkYKxCn1" Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-70f5cd2fa39so271486a34.0; Wed, 04 Sep 2024 21:18:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509894; x=1726114694; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nD0rUo0iZKECgz1mfgeWlPajiiX/VTTiXfcH67/TdcA=; b=XkYKxCn1A1dEKAtXEzy+NxebodU3P1lZiRzQU6f4Jl8zcC2ZduCAr6KINzvSHsD9ma NMqYh2ilpBedMGDxLKKluHe3gGq2yT39Sat9Ut1xoFLBe2e4vjKxeski8aafOwSh5UH8 Iu9YNrKyKbhISxTEQyf7M7mLTHIAoNcvsEFmt1QbHvzc1tClklYGTg4IF2FYllQpGE9U SJ5p2G4YOkU1j05lC24fh8fyP3r5fmf0lfbMSZ9m6CxGy6KJaPXFVx7OAwyS1Z31j994 mfoUfJ2pAwyJ1Lea92NXBo648mcXitJOdySXcW+TxbzyVgUXbPtnVwEHimxUJq9vy37S 7JPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509894; x=1726114694; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nD0rUo0iZKECgz1mfgeWlPajiiX/VTTiXfcH67/TdcA=; b=wadsu93y0ivOHwSzCDoFJ2jEl3l2mWGOzO5hH+j2Evib6o4BY9aI1fzbn5o1LGMM2a mZfvb0Vi/9HnF/4mbYdExKyzOH8wztSUOht3wLpamXx+hJkNyF4wWHsAFjbFsK+xwuJw GC3WaoqEU9bC1FxXDZDgqUnic2LBte1ik8HCJ+g7SJ3NZV7jTca1mGlrL3ldaAkmHkoO OnrW3dAL2TrckTFBA5UrcQIcciZYkvCOPjqlm1z/oJ2BuA5Uhtc/WcNFVw3z5PwtSoDS ODWCatuF3pDSxJKtdtn8obdGRwv8e1yebAG//OiFfT4/o53NHpf0NgS1mfwE1GUG/iW7 JzDg== X-Forwarded-Encrypted: i=1; AJvYcCUOTe1mSZWPqeHxAABoAFN179bl9tqGPy3MfGQPbrPrNPrZi2zMb5Pgi1A4nIWVRrTKuSykkJJICMS8nyBN@vger.kernel.org, AJvYcCXMMgIAx0tYD488RKcgSLH+Bj6ssRkgAw4QvBA68YyJdSBkQPyVSm/eJiZ2fqdSBAkGBUEROMKj9rTkx4k=@vger.kernel.org X-Gm-Message-State: AOJu0YzP7POgkSfZ4aq1A+KBA/8kSO1ok9siRL3dEcgrKYELwnydNU/5 Zudza0ZXkaZgymwjloUSNPnjON8vaWFvwVGg8FM184ZNZnzE3LMbFWUi8w== X-Google-Smtp-Source: AGHT+IFZIWBeGssZlbykHlhtPJzaOPXIEAb+m9BSaPwc6IUQXl2xcYZG1msLYwzKd+swNkLxBLV4NA== X-Received: by 2002:a05:6358:88d:b0:1b5:a034:4713 with SMTP id e5c5f4694b2df-1b7ef352898mr2009643555d.0.1725509894565; Wed, 04 Sep 2024 21:18:14 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:18:14 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 21/24] Input: serio-raw - fix potential serio port name truncation Date: Wed, 4 Sep 2024 21:17:26 -0700 Message-ID: <20240905041732.2034348-22-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When compiling with W=1 the following warnings are triggered: drivers/input/serio/serio_raw.c: In function ‘serio_raw_connect’: drivers/input/serio/serio_raw.c:303:28: error: ‘%ld’ directive output may be truncated writing between 1 and 11 bytes into a region of size 7 [-Werror=format-truncation=] 303 | "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no)); atomic_inc_return() returns an int, so there is no reason to cast it to long and print as such. Fix the issue by removing the cast, printing it as unsigned decimal, and expanding the name from 16 to 20 bytes to accommodate the largest possible port number. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/serio_raw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c index aef8301313b2..e058fef07f57 100644 --- a/drivers/input/serio/serio_raw.c +++ b/drivers/input/serio/serio_raw.c @@ -29,7 +29,7 @@ struct serio_raw { unsigned char queue[SERIO_RAW_QUEUE_LEN]; unsigned int tail, head; - char name[16]; + char name[20]; struct kref kref; struct serio *serio; struct miscdevice dev; @@ -277,7 +277,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv) } snprintf(serio_raw->name, sizeof(serio_raw->name), - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no)); + "serio_raw%u", atomic_inc_return(&serio_raw_no)); kref_init(&serio_raw->kref); INIT_LIST_HEAD(&serio_raw->client_list); init_waitqueue_head(&serio_raw->wait); From patchwork Thu Sep 5 04:17:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791702 Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) (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 19BA4192B72; Thu, 5 Sep 2024 04:18:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509898; cv=none; b=UlUOo9/8ACMmUpulrwLqK9hjqzJN2Rcz/1DhV6LkTSw8RI2Mf501tCz5lM8ku+m3RY+RLYx8ScTI6Fth83+Th1MIB1l0JLftz+XmQdz4/pW5Zhdpr54k43WKyX/E5PR/nhm0jeNv44yjHz2qEvbddDPPoQ+LthVxkRd7W07qNcI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509898; c=relaxed/simple; bh=jrCdNxs3nPBprZ1EecOJZBm3IZPKT2/NNteZ18Jw+dU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dF67uxbQrbdPiEjeMCjYAjF+QJbbYyz/xD1HaT2penZ034wpXPEvETM5/zyVHmcb57VPbZMDZ1haapWnGbUPK+1ZLFTEXnS5SS0yPHs+YKceilUhjQxCweczw1WqOMoYSbntcfqlDoc8oyZ6vS163FPSFoVgPDbE0UqPxOcyXkU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MksIINeG; arc=none smtp.client-ip=209.85.210.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MksIINeG" Received: by mail-ot1-f51.google.com with SMTP id 46e09a7af769-7093997dffdso168892a34.2; Wed, 04 Sep 2024 21:18:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509896; x=1726114696; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xz2erQSg3sDaQU8qTCUlHXjZi76BIHFsta/dILnpIUo=; b=MksIINeGNGEUAYYwSLfJGv1NFUAFtedZr2Lo7fTMlH7CXEnCtEbfmbJotrbc9JZG6K t8r/s1pU7Lq//RG1aEJuD0VL+DNj3s7dx5w9Au8hBvp3izCAGL8zjn/Ko+VCnUNhdr15 L/RBKivcN5y4bF+VmFDGMfT5++LOM9lkp2Vskx3awHsR+tiIfQ5kDgUosc7zl3DjCwLf wsXOqMP+2293xsxpYJzCPaxuorsYbheLpImR860Dni/9fhn08eJc5RoHGTLZna+9i8eF yjpi7txTZyQkY4OTBdyHik4JgYFR27Wpm/9VoKx1Hs7JKQiuemi7xjk1NQqlVeCYRFvD 7b8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509896; x=1726114696; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xz2erQSg3sDaQU8qTCUlHXjZi76BIHFsta/dILnpIUo=; b=IHbmg+/rATCGPxFNagOGPXGFQwcRzLGwP7swaoZrbvvFh49lEqcC8zAOcjjKD2qWju uJbRri6n/BlHXn5ceKKTSJn9iV8n7pbxCDLxzU8gH2ulzL54ZC7w7+ZfDGVM7gKYBCNF hFAc8VfUVe0idGZdSUg2S8gVtiY+QqujmYHYMdObPBLf5GsX0V3qqypkfU+ATWM7ZjMb saT4HqED5mCbv/LkVQ0Q3K4OCWDgoRUqDbUZ/rkxprmqQqjdIi//aZv534Tp4y+aTgym ksJISKJmEFC4/fj5hLhwz3DPbURQlnJLQihiDx6W0oEPYyad0PPFmU5Dbc1RztlTqpGD ZWAw== X-Forwarded-Encrypted: i=1; AJvYcCV3NX0aOkWHt2jIpX9mP1D23mkb4tdbAUMlLKw8mPMGBW+SuDcdVwcTUVmsn4I86uj5baMh9HuLNFYxlTA=@vger.kernel.org, AJvYcCXj3mXpaGxA8Mj8a1+67Hv5sftOjJCnnVLYaKIW2tCnoh3hBQLv8IHKfgqZPW5h74/EUOuwfdUwml6rHxU3@vger.kernel.org X-Gm-Message-State: AOJu0YyigFqCBKGgw6DGMYd+wMXEF39o5VQ4yyJCxa3D0Yc06FKtWw1p FE6VH5mDgkWyHRzkEogg5G4B4Sdk/XC7B/7m7fXBTYkhEnGjU3A/W1+6DA== X-Google-Smtp-Source: AGHT+IFPTVGs3vyKg3Li6dflqJQ+JnKv/J7SxlC09OoKIqCCU5IWw2pa42IFrQdn8vuEJ1eR5r+pIw== X-Received: by 2002:a05:6359:5f8a:b0:1b5:e9e0:2421 with SMTP id e5c5f4694b2df-1b7e37a5389mr2316618255d.6.1725509895909; Wed, 04 Sep 2024 21:18:15 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:18:15 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 22/24] Input: sun4i-ps2 - use guard notation when acquiring spinlock Date: Wed, 4 Sep 2024 21:17:27 -0700 Message-ID: <20240905041732.2034348-23-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that locks are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/sun4i-ps2.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/input/serio/sun4i-ps2.c b/drivers/input/serio/sun4i-ps2.c index 95cd8aaee65d..267214ca9b51 100644 --- a/drivers/input/serio/sun4i-ps2.c +++ b/drivers/input/serio/sun4i-ps2.c @@ -101,7 +101,7 @@ static irqreturn_t sun4i_ps2_interrupt(int irq, void *dev_id) unsigned int rxflags = 0; u32 rval; - spin_lock(&drvdata->lock); + guard(spinlock)(&drvdata->lock); /* Get the PS/2 interrupts and clear them */ intr_status = readl(drvdata->reg_base + PS2_REG_LSTS); @@ -134,8 +134,6 @@ static irqreturn_t sun4i_ps2_interrupt(int irq, void *dev_id) writel(intr_status, drvdata->reg_base + PS2_REG_LSTS); writel(fifo_status, drvdata->reg_base + PS2_REG_FSTS); - spin_unlock(&drvdata->lock); - return IRQ_HANDLED; } @@ -146,7 +144,6 @@ static int sun4i_ps2_open(struct serio *serio) u32 clk_scdf; u32 clk_pcdf; u32 rval; - unsigned long flags; /* Set line control and enable interrupt */ rval = PS2_LCTL_STOPERREN | PS2_LCTL_ACKERREN @@ -171,9 +168,8 @@ static int sun4i_ps2_open(struct serio *serio) rval = PS2_GCTL_RESET | PS2_GCTL_INTEN | PS2_GCTL_MASTER | PS2_GCTL_BUSEN; - spin_lock_irqsave(&drvdata->lock, flags); + guard(spinlock_irqsave)(&drvdata->lock); writel(rval, drvdata->reg_base + PS2_REG_GCTL); - spin_unlock_irqrestore(&drvdata->lock, flags); return 0; } From patchwork Thu Sep 5 04:17:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791703 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 38BEC192D78; Thu, 5 Sep 2024 04:18:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509899; cv=none; b=qHvyryyUImFZCOm+qyaZ4jZg+TkmgkuUFit80UpCXfpG6h8kHofoRAX3OVw84nQd1RUVHDndE46r+7YXGlm2qYOu4i4WNVIDCBvc4cQ6sbOPCxEz/T3lNn5h3G89fw9JngBnCPkiDrH3oEjeWLeGa49RiZDVzcySDkHL+UsgDEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509899; c=relaxed/simple; bh=5GigJjEmPSDI+ItuxoJq+Z/lu1obXOo3IU5s0mY7pME=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QN9XLDrVJs7WcsVEAxdCi20F4lRT6c7ZISxEMQb2jTSqSwL0b1PEKYwnINMkOCwg6agOMlwdjsO/JD4Vq8JBj5P0ybz0WowRFmxzKEQ5WnjqW/YBPEkEDWPYsyaRKTnEDG+gSg2xwMnn7Ec28r7tn9qY+zIkr7CbdtAWAUySshY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=j6+uJdtz; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j6+uJdtz" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-7176212de5cso259886b3a.0; Wed, 04 Sep 2024 21:18:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509897; x=1726114697; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KAMMGFcdQQuvbLfMZ1RSK1JtSdD6Ii5X8caybj72d5Y=; b=j6+uJdtz87BaWwSrLuBzdxwgLAeDjAyxJoYGj6oRAUrR8bRXoOAygP3ly085Qc6jWg 0q+L2ybXqFmBA7SSK8QVY7A6oh4vVGrej3t1Xyq2QS1UDR/1rrY5Cab8WVwW3p3lvCZx 3/1xh9utyIYz9hn5Wz4vG0kENC8Y9dUUV2SiD40xvGU5LeASO75DT9sPacNAltUyJJ4O snMX2L87GNbG9trjhDOzn+eeabpsXt/TObzoolZXtUDoFVn6OUeLwi1niGiLlmQRZdYD yd54SiBFgs3LAh74DxiKtTaA2r66mQFexkD2qYz/P0xLa5aIvq+xYD3gPSnBSNF0CQAR XV6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509897; x=1726114697; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KAMMGFcdQQuvbLfMZ1RSK1JtSdD6Ii5X8caybj72d5Y=; b=G30iSwnkcu3cWZbBCOthJO685moH14siwFR/YrIwGi3SUiohl14xH1poImS8shbl3l YZcarJHWPXh+gVeGWwaz9T1oWoyzcnyJQT5Qc+eRsxBU2hlIhK+dY8rrHhyANFHGf268 MegV0vJ3Bruo/BVDrDc08H4eX6Kl4fZlJYfm0+pGjv+KYZJ6WC6QvTp6vmi2TFazbBEh LfA4avDNYXOF2+gzp6N6Rrh0g53+H48w4bGXhQOt4i4y5y/vzFxufx4fpOciqXwF8xrg 7CsjV7ufaBjVBqT7eLFILGhiZPEMb6FJxWuQsfn5BkgE1D7fG051UtYVpR6pnUY+L2Uq HP4g== X-Forwarded-Encrypted: i=1; AJvYcCVJS32CMaNsoev0D2NBRjmqQvGpv8VzKPA0Mh2fzzEfqobir8IllTfvnOYoA8DCoQqdwdaYQHq3O6Xxipk=@vger.kernel.org, AJvYcCWjbN+MvD7VfXzoIRCOg/NBGpv+eTburEXZCv00yW30HF1VEBqgDAT7J/p3EvF+IIrTcPoGe5js8wIA7DEy@vger.kernel.org X-Gm-Message-State: AOJu0YwvSWT870WvKduz4DRzl9YCEJTwf9HxSlLLEBmlMtvTpiVoqD+l wVUkZTGHV9a/d9U/8hjOU3e6I9GKDyKurHhLEaVv4fVm/QCXI2hNAjuZdA== X-Google-Smtp-Source: AGHT+IFRCdJkRXUogbTin1hoFmZGnh04XwNGpXWLmx6ydoLDsoywhBNvkL2ZX38vN1+wCOtB2uPKFA== X-Received: by 2002:a05:6a00:3e1c:b0:70d:2a4d:2eeb with SMTP id d2e1a72fcca58-7173c1e3e18mr16886428b3a.3.1725509897218; Wed, 04 Sep 2024 21:18:17 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.18.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:18:16 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 23/24] Input: userio - switch to using cleanup functions Date: Wed, 4 Sep 2024 21:17:28 -0700 Message-ID: <20240905041732.2034348-24-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use __free() and guard() primitives to simplify the code and error handling. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/userio.c | 141 +++++++++++++++++------------------ 1 file changed, 70 insertions(+), 71 deletions(-) diff --git a/drivers/input/serio/userio.c b/drivers/input/serio/userio.c index a88e2eee55c3..66c9838a1fa7 100644 --- a/drivers/input/serio/userio.c +++ b/drivers/input/serio/userio.c @@ -55,18 +55,15 @@ struct userio_device { static int userio_device_write(struct serio *id, unsigned char val) { struct userio_device *userio = id->port_data; - unsigned long flags; - spin_lock_irqsave(&userio->buf_lock, flags); + scoped_guard(spinlock_irqsave, &userio->buf_lock) { + userio->buf[userio->head] = val; + userio->head = (userio->head + 1) % USERIO_BUFSIZE; - userio->buf[userio->head] = val; - userio->head = (userio->head + 1) % USERIO_BUFSIZE; - - if (userio->head == userio->tail) - dev_warn(userio_misc.this_device, - "Buffer overflowed, userio client isn't keeping up"); - - spin_unlock_irqrestore(&userio->buf_lock, flags); + if (userio->head == userio->tail) + dev_warn(userio_misc.this_device, + "Buffer overflowed, userio client isn't keeping up"); + } wake_up_interruptible(&userio->waitq); @@ -75,9 +72,8 @@ static int userio_device_write(struct serio *id, unsigned char val) static int userio_char_open(struct inode *inode, struct file *file) { - struct userio_device *userio; - - userio = kzalloc(sizeof(*userio), GFP_KERNEL); + struct userio_device *userio __free(kfree) = + kzalloc(sizeof(*userio), GFP_KERNEL); if (!userio) return -ENOMEM; @@ -86,15 +82,13 @@ static int userio_char_open(struct inode *inode, struct file *file) init_waitqueue_head(&userio->waitq); userio->serio = kzalloc(sizeof(*userio->serio), GFP_KERNEL); - if (!userio->serio) { - kfree(userio); + if (!userio->serio) return -ENOMEM; - } userio->serio->write = userio_device_write; - userio->serio->port_data = userio; + userio->serio->port_data = userio;; - file->private_data = userio; + file->private_data = no_free_ptr(userio); return 0; } @@ -118,14 +112,32 @@ static int userio_char_release(struct inode *inode, struct file *file) return 0; } +static size_t userio_fetch_data(struct userio_device *userio, u8 *buf, + size_t count, size_t *copylen) +{ + size_t available, len; + + guard(spinlock_irqsave)(&userio->buf_lock); + + available = CIRC_CNT_TO_END(userio->head, userio->tail, + USERIO_BUFSIZE); + len = min(available, count); + if (len) { + memcpy(buf, &userio->buf[userio->tail], len); + userio->tail = (userio->tail + len) % USERIO_BUFSIZE; + } + + *copylen = len; + return available; +} + static ssize_t userio_char_read(struct file *file, char __user *user_buffer, size_t count, loff_t *ppos) { struct userio_device *userio = file->private_data; int error; - size_t nonwrap_len, copylen; - unsigned char buf[USERIO_BUFSIZE]; - unsigned long flags; + size_t available, copylen; + u8 buf[USERIO_BUFSIZE]; /* * By the time we get here, the data that was waiting might have @@ -135,21 +147,8 @@ static ssize_t userio_char_read(struct file *file, char __user *user_buffer, * of course). */ for (;;) { - spin_lock_irqsave(&userio->buf_lock, flags); - - nonwrap_len = CIRC_CNT_TO_END(userio->head, - userio->tail, - USERIO_BUFSIZE); - copylen = min(nonwrap_len, count); - if (copylen) { - memcpy(buf, &userio->buf[userio->tail], copylen); - userio->tail = (userio->tail + copylen) % - USERIO_BUFSIZE; - } - - spin_unlock_irqrestore(&userio->buf_lock, flags); - - if (nonwrap_len) + available = userio_fetch_data(userio, buf, count, ©len); + if (available) break; /* buffer was/is empty */ @@ -176,40 +175,21 @@ static ssize_t userio_char_read(struct file *file, char __user *user_buffer, return copylen; } -static ssize_t userio_char_write(struct file *file, const char __user *buffer, - size_t count, loff_t *ppos) +static int userio_execute_cmd(struct userio_device *userio, + const struct userio_cmd *cmd) { - struct userio_device *userio = file->private_data; - struct userio_cmd cmd; - int error; - - if (count != sizeof(cmd)) { - dev_warn(userio_misc.this_device, "Invalid payload size\n"); - return -EINVAL; - } - - if (copy_from_user(&cmd, buffer, sizeof(cmd))) - return -EFAULT; - - error = mutex_lock_interruptible(&userio->mutex); - if (error) - return error; - - switch (cmd.type) { + switch (cmd->type) { case USERIO_CMD_REGISTER: if (!userio->serio->id.type) { dev_warn(userio_misc.this_device, "No port type given on /dev/userio\n"); - - error = -EINVAL; - goto out; + return -EINVAL; } if (userio->running) { dev_warn(userio_misc.this_device, "Begin command sent, but we're already running\n"); - error = -EBUSY; - goto out; + return -EBUSY; } userio->running = true; @@ -220,32 +200,51 @@ static ssize_t userio_char_write(struct file *file, const char __user *buffer, if (userio->running) { dev_warn(userio_misc.this_device, "Can't change port type on an already running userio instance\n"); - error = -EBUSY; - goto out; + return -EBUSY; } - userio->serio->id.type = cmd.data; + userio->serio->id.type = cmd->data; break; case USERIO_CMD_SEND_INTERRUPT: if (!userio->running) { dev_warn(userio_misc.this_device, "The device must be registered before sending interrupts\n"); - error = -ENODEV; - goto out; + return -ENODEV; } - serio_interrupt(userio->serio, cmd.data, 0); + serio_interrupt(userio->serio, cmd->data, 0); break; default: - error = -EOPNOTSUPP; - goto out; + return -EOPNOTSUPP; + } + + return 0; +} + +static ssize_t userio_char_write(struct file *file, const char __user *buffer, + size_t count, loff_t *ppos) +{ + struct userio_device *userio = file->private_data; + struct userio_cmd cmd; + int error; + + if (count != sizeof(cmd)) { + dev_warn(userio_misc.this_device, "Invalid payload size\n"); + return -EINVAL; + } + + if (copy_from_user(&cmd, buffer, sizeof(cmd))) + return -EFAULT; + + scoped_cond_guard(mutex_intr, return -EINTR, &userio->mutex) { + error = userio_execute_cmd(userio, &cmd); + if (error) + return error; } -out: - mutex_unlock(&userio->mutex); - return error ?: count; + return count; } static __poll_t userio_char_poll(struct file *file, poll_table *wait) From patchwork Thu Sep 5 04:17:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791704 Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) (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 B2DCB19308A; Thu, 5 Sep 2024 04:18:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509901; cv=none; b=X97k9P2uW+bZA7Wsp2PyBo8dARktRrbjwYsxPe0XQZzdsWDYKLehp2UPD4DHPrwnugCdSvpO9Hy9Svd4JE/jYQiipLGQax5jFdxoJ8bkI33nh/IekklTJzdJK/AC0NvPi+GBoEGSdjbsuNlk7aJLz6QCwet8OZ25DwgrSZlrZVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725509901; c=relaxed/simple; bh=MHsAD0oZqhdrdbvskc4Y/1xHUoW4vv9RJ2c2ipgeFJo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RMzKZMScGi3G8qqt4iqCA9MnfFzYPF8agOL7o3Og+s1A/1e0EayeKMP/eniXs9v83cPly0SKTKZ2HMDnpgOeK6Cx7zUCQByrEEM55sRazYuCbXmyhwUidNQX6Nh0gDI14ENcDm1SXgIWDtZSSPOPj/geDLwS8hMTFTjv6hU/yVc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Bozavwzq; arc=none smtp.client-ip=209.85.161.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bozavwzq" Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-5e174925b7bso237429eaf.0; Wed, 04 Sep 2024 21:18:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509898; x=1726114698; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zDTJQsChimFHLTafhuTJQvaUHnDbeVQTacrVKRN5TeI=; b=BozavwzqkNkXC3KFqxMCIochr+C75FCHn1Pqt18R60iPYNZJ73Af2SzK/8+cCbxf4E seiL65iWUo+IznPW9mQYYFQS4d3G2XwewGKQ/lZiLytZLhfLytzVLzHecqwQTqXmri32 thrYo1hCc02A7mwAIbPGO2e6MmIXtejaLkq+GOHP02o5thuDS+6U8cRTWMG52fbXOFYL 2yJDSHh20RTcjHCnDd19NfmqJe8gjNDgirJlTti4eu6uiejXTVnr5LB4WGFOq+iu+X+W IjRJUF0m04LFQXKd4mMsXaUinHvNadQCky4fAx2AqpELFsU1xwTJQUUBpko2qgV+CCeH WBwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509898; x=1726114698; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zDTJQsChimFHLTafhuTJQvaUHnDbeVQTacrVKRN5TeI=; b=d2UKQITRhzp45njSvY0IM80hnb1rnGfuMlFjwTV/rTpJqACg+kP6bPcxEJmX/dzPqj 9ece+90BkjHiluh/9AYR1an9D0IC3YMKQmpBU3o2qHc3NhjcP/0GuKauIhI5K1mJwzju OMnyxelmPaFT4c95xbRJQXiiHEAgXEpe/JYi8DVBrF/pHtk7f0Fly8cg7MaizedlXkna 10hBlRS5rx8uwjoRASj9vqFsXqh/i7DWnICXhHUQ8SmHlwTJXoX1LiiwYS1OCH+3k15m P0ztO7L6CIoBRNx1mt0f7mNxXnZ5b/tR6AT5I8OahO0tIHZyBSCT07lgncidQfEKg5ys LnTQ== X-Forwarded-Encrypted: i=1; AJvYcCUoP+kB6orc532Q1glUbk+GWnENdJ6od5k2U6Y6SO9/QZGNHrEx9L0LmGU7SVgNis0Wkrm24b1NtgxKDmM=@vger.kernel.org, AJvYcCWxhHoz9w9JMr0X5nuDRl3rxQTtkWUNG5IL3bwyRyUVj8DHwIuEyw1qpFm2NBLJhmQBzc8nEO5BGG569tch@vger.kernel.org X-Gm-Message-State: AOJu0YyFdXqOUYIpYPqTbWHk26wwlfzb6AuSFK4OaQ52kTA7h8F94slh wE4wiXLurgYw3b+9NuEOTJcLmQMhNe9Y6GwjXe+iNzcJtINKwbahoew8aQ== X-Google-Smtp-Source: AGHT+IF0/9UveaFIJMl/u+qc1yPJ7R6KvpVX6O3R+fF7tqh50k2XIbvJeO1Zme0x2qVQgrJC9rNwrA== X-Received: by 2002:a05:6870:1b17:b0:261:88b:36fe with SMTP id 586e51a60fabf-277c804bfc3mr18648317fac.15.1725509898618; Wed, 04 Sep 2024 21:18:18 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d4fbd8d52esm2450216a12.32.2024.09.04.21.18.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:18:18 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , Helge Deller , "K. Y. Srinivasan" , Wei Liu , Dexuan Cui , Samuel Holland , Lyude Paul , Michal Simek , Hans de Goede , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH 24/24] Input: xilinx_ps2 - use guard notation when acquiring spinlock Date: Wed, 4 Sep 2024 21:17:29 -0700 Message-ID: <20240905041732.2034348-25-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> References: <20240905041732.2034348-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Using guard notation makes the code more compact and error handling more robust by ensuring that locks are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/xilinx_ps2.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/input/serio/xilinx_ps2.c b/drivers/input/serio/xilinx_ps2.c index 1543267d02ac..0316760168e5 100644 --- a/drivers/input/serio/xilinx_ps2.c +++ b/drivers/input/serio/xilinx_ps2.c @@ -155,22 +155,17 @@ static irqreturn_t xps2_interrupt(int irq, void *dev_id) static int sxps2_write(struct serio *pserio, unsigned char c) { struct xps2data *drvdata = pserio->port_data; - unsigned long flags; u32 sr; - int status = -1; - spin_lock_irqsave(&drvdata->lock, flags); + guard(spinlock_irqsave)(&drvdata->lock); /* If the PS/2 transmitter is empty send a byte of data */ sr = in_be32(drvdata->base_address + XPS2_STATUS_OFFSET); - if (!(sr & XPS2_STATUS_TX_FULL)) { - out_be32(drvdata->base_address + XPS2_TX_DATA_OFFSET, c); - status = 0; - } + if (sr & XPS2_STATUS_TX_FULL) + return -EAGAIN; - spin_unlock_irqrestore(&drvdata->lock, flags); - - return status; + out_be32(drvdata->base_address + XPS2_TX_DATA_OFFSET, c); + return 0; } /**