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: 13791706 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F0800CD4F56 for ; Thu, 5 Sep 2024 04:19:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jSQ5nHDaIzTNEy48GC2iLuCGQVf+qFQuSKyHZ16Sx1U=; b=kdKKgvvwnDxN4hb539I/ATB6R5 a0NpqQb6kX30ZaYJrsPPcY0nZ9HoOfRVjAedphvH0e4AGxtVL2P6jtKvNFBbuIhXx6RXIens2NDX8 u3xuR4qn2jj/KurzVYu+hhW/u79FNL07g5BTOFrhxhB9ukOUbbV1hOKggUrjS+jMVrq3dsOIibdb9 V72tqRBXzoLbl0r/QfyxscG6+lMK3Iz027AEW1EGmnAcDQI5hA+OI1Bq/TbC8aQcXNarPmPzH2Unp 9r6sWmfrZcb1yw48PfOSQiWDqbs/oLp7smW4eNoTSnZJ8lRKYsEtGkIHgwxM9vBnpYROEKhS6gIE3 ad8yWIww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3yB-00000006twX-204T; Thu, 05 Sep 2024 04:19:43 +0000 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wH-00000006tKL-2IGw for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:17:46 +0000 Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3df0a54623dso175772b6e.0 for ; 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=lists.infradead.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=gANojXn+wCrXcWr25w2rwfZoM57qr6vnqtPuuYBe8/ohWt/XjsS8nd65Qt40Usvcit oIxH8D3ye0k9A4X0cj3n3XDCo8IwDcUjNMt/FX9AW3yuJPH5fGe/j9E0B4MIGfH99aD5 C96L8Sk5bcJJnZ7JLU6yXn7LVBkWfqbVnAGfevngxZg9UfT3bUk1oQGhcwtAwIS3uCz5 tr35bhRQcPYNzKN5EG1O9OftS3Na47Z6fVoHnpunW/862Sn1GAyQ6ED7++KnATRne369 aUGsgB0sxgi5xnZ1ZlsFbuLCAEHh+8L/LI44ZRbpUEp4w+5mi41rxIds22+jSbLrhk7i X0fw== 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=lZoHcUPCop8x6J2O+o9FtJErs6B9mcVGpzktrLQhRamdCykgNvmG7KkpYwfVh2nKKl +APHw0Gv/0e+4Vrk1DqNexM/tGgRZ94Q+YE1Z+BiPf0MrX77bJarOSHKlklAgj6Gnuta yLKYDvwh7K/RcOYXCbc/zSI0XCZNEjlZpmQWDMt7HSWnzbUMDdLPeDmVR0wBpLAclAV1 v1NtXE1MFHjgT3G7sT4fLLhRw9SXaruH7Dr8d1sF+RTgdf4tRVwTSPp5/G0qHWKeLZyg 4c3NjFUvRDBt9aeJr3d1x7rI4UFgAhK0WZ6twzxTB78GT7k9WVBoZ0eCdzg1XH/V7ygz +3yw== X-Forwarded-Encrypted: i=1; AJvYcCUcPDrXh/EbwIUFHmRnx6ZhUYjohh+tYj6v+wleaWyxdmaAq2yUmnDWq4WzDNito4tvP4da8FBGpnjT5GMUgNEf@lists.infradead.org X-Gm-Message-State: AOJu0YxXyQjNlunFrLrGyXgLqjbUvR4hWsvRFuLg6MqeOdn3wiZL0sJN h/KIPGFkF1esUAGX/3w/UYDQ2rSm5n6ufTvNKYZ13PXa4FHnp9+Q 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211745_626303_AC7530FE X-CRM114-Status: GOOD ( 10.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791707 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 15B3ACD4F56 for ; Thu, 5 Sep 2024 04:20:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YscGpXPa0igYUdPp8o8oV5VkpUTxqWDGqD7B4LMXPvo=; b=36PGnHKGeHQdykgozy9wQTUwO+ RLcFIz39QzGD67X02viH+gdHRLik4gtNt27MsP9bF/94K7PQfuai5FzlARZUZbHpPOKsQ737x3BRW o54YM6k9xNLpk0HAzudASYgOinzgoJLt8sxfGOPBvYXryu8ZYs3e91iC1qNXrerWyGccdFoOreNQw nY8CrXFKvQAnVLfWGut1X6vKSs+X+DDaLB67oRiBPvWwEg48ob8Y4D9YaBoUbu+HZvJOZwLlpLWOX YCX7TvsBLANlYfhrZ9AJLzCnnYnO5c3yArvcNM+BR5/nYFKK4dp2QRhtc7DlA5zGMHXVWHscqV1KD UUgjM19w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3z7-00000006uDq-1AJW; Thu, 05 Sep 2024 04:20:41 +0000 Received: from mail-yb1-xb32.google.com ([2607:f8b0:4864:20::b32]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wK-00000006tLQ-2TQF for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:17:49 +0000 Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-e1a7d43a226so419984276.3 for ; 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=lists.infradead.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=Cfc/fxXprqzbbj++nYoMpWl5msCDIO2olIaiJpWssGY82i/zU+4o0XMaJKTj68X+ju EOrbRespnA5zt0CURkvl3o6FRQe28L00wcgr3Kyl022Wh3Fl3N8gO2BwsHBdWzEeTcz/ Y1HsNrmGyfBhBStQJ3sbM0YSLRbKacBnr4+7K7NHsPD8aQWIM3tS0nakxPGq4/z1nACh LYrygMqfTU4jmlTg1IBQ+68DwSxoLxSaOZn7rSvtGQYxzHz2Cu2hfrvmeaVs37aHIkNR RbLoKWoolNYSk9HsN1L++eYB1avrKWK743aNn21FO7AG5SgCwLUNF4B6SsV/bDru1qsB Mj5w== 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=TVPJlsYy5GDHe0rbjbLCGgUqQsTuXXRg0FbmfySOJI/eGS2zvpsuUVeWVn0i0hk5dq ye4UMdtRNe0tXsLgQQUBjiiRpd7LWQSrPEPYgmC0zgmbUbg3f4PURk2hqxWIVM/uGFMF V1Ridm7ylUdrckJ/BdW5JlPvqlcnFP04qRVQWj7EORCP8LT3PUyzFpcK2n5erCu7+OtI ikWIuTJrBS/nUixkh64YEwFZazMo9lO5Gkhs4U8b5k7l/0qO+E6vv1OfxhyCB+6tI3/Q rV0duoejThHxsO5GElgdxc15MJeKTRIKJYrgaXlmYn0/YAWwP0qMgopKajrYvdYreisd erUw== X-Forwarded-Encrypted: i=1; AJvYcCUBz9gaxP6a6vosA0g2R3uTqSi/ytqSOHgFiDcJjWjM4or4DtWUC8uGFM+LaQ8fzlFq2xP11jnJIVgcrUeYJJ6O@lists.infradead.org X-Gm-Message-State: AOJu0Yw8uaBVETVEkh992i+iytbfP9bNiu18PlVCwo2CqvaVMgxd8eWm WRW0fkHXMasxihDPBX3XlDVus2QUZnHxfs30m3oWpzod9gnfG9pP 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211748_650557_5DC9C298 X-CRM114-Status: GOOD ( 12.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791708 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8E182CD4F56 for ; Thu, 5 Sep 2024 04:21:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kOurL+niKTuTYRrWkCUZcFZDU3uO6ZkmtonuLPtkVjM=; b=e1EvjotY9N3yLc0FA/SJ8GzUPc cS7I8WKFsuHDTr2Um0nQwvYFk+ST1MrAf+Zgd1HntPCwYuedSGwV1TUaDbYoqID/aucFsFryIiMId Anl5ceQY7Kcm7wlDM+0KF3kGgBkVzix9m9F/8dEhPQukR/xW4Cw5F4lxv9gsR3IoxLvyfoF8zr+/5 E+uk8JYs1wxNQA40Tb9RMiA6A8A5erM6srJ4GMMM0xBoirBacpEVBD9sUSrsw6zglp9CJxV6o8JfT aN8IinkUtFQOqcYadNeDFwQrWwR3Ys/HenduZKLUQ617FpTBiPae1rQWDHKWeYHv5kWmH28nxGxaz m3yOxjVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm402-00000006uUr-2tZ6; Thu, 05 Sep 2024 04:21:38 +0000 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wL-00000006tLl-2slJ for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:17:51 +0000 Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-709339c91f9so242588a34.0 for ; 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=lists.infradead.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=juj+dE77i4YnyBRc+GNj+dLVQlMdLpIbwDfeTWqSsOo+Wr/bZGpYhM8ZRXKbcJYb5P XcCPrQVeCRlrs5B9ROwpqbMEbs88UWG+CXN8jtsKIc97urlHRMoNgCpuIs+U+0BbiRIL hP97aH1V5rKhrpW7G980WNn62Kl/7Z9WgNV01xyRr8Hi3WzEqMQ0+Wlcn+f+gYCLmnPO 7yS3a2iQ88aeOZyeF/0+X4zm2MXM3CAw1FEBXBvxXxq2Xw08uNADS9MG40sYUxool0vr Ox8cUmI8dPbVj3v6g+TYylrUCrhJWDTNqRGqChhkJqlBCpkYSpRod+DH8PrYFgNj0CKv Is3Q== 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=XZqUlBOKKZj/eKD0zV1Gi72WAjAYjnoxKfjyLv3S0ar7R170NHsf+iNYr5ocliPJC1 176J1RSc2kBfRFCDLQ8W044tOS7Vj9u+266QcFXIBOFOCtSjI/QJv0VxZo8BKmdbvLWi xYUSN6LDJJdzjhL7J9kleCfPW2V2e9w1bJE6axMlGCT+kLqaQw1LHl2SUhSTuakXRETO +xE9Kgq40lATeQWXJ6L+XlPPfcKsgHXjrsogHji6agZowkgAAFGFSBIOx1sUxeZWbU/N xEmX4cpLWE5k5+EpA9OASGsCD1EjEj4o+K5WBlZ8JWCRRfj/dGvg8Logn8R/l0yq4pSp S50w== X-Forwarded-Encrypted: i=1; AJvYcCVLzIuVdAJuJsXVeKfFkYFizPGVbNO8yGLadwwMVhhhr4dUTfUzDhIdCD/Iw6BX+WRb5sr/2y7TaK+Zcc6vvhvK@lists.infradead.org X-Gm-Message-State: AOJu0YwUd2dF1vpQ5xlJSMDrYuB/IhGdnJg4yziRj8omCpGsCrsXg/fe nM+zwX2Im5peSRsyZ8bar5RDbg0FabfjHBxVy3DJ6zUoyO93ksDj 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211749_745723_6771A3A1 X-CRM114-Status: GOOD ( 10.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/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: 13791709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A632DCD4F55 for ; Thu, 5 Sep 2024 04:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8RnFN3EVlk3VoY/i2sKWDmOIShT35NS9PrPlyqQEJBY=; b=K61LzfLAQaIlWmnXWuZSf/fPUm qDtcYlUFCWvV/kblGI0EzBp4eaw/UgP8qdRDI6UGFbhYCsPiSdoaiV/obDe/JFWe/bViyVoBkygBo AEhCoFK/BuJKjV6YjOCUKeUgyFd+7fiKcHxU1B5D6O7isUvp1eVn8Ro0IYGwMJWy8Kj0SQh0Yd5KC /rKSvqiuSIIhdAufv1pxPFKLMJcFdeHhBPocKBxOA9bGmeMMOJs8Acy5dlQQQvfsYuP1F4kNtL7G2 0VJxglTbJZQss7EqXSYTtfznBPreILdPI8qj5MZ+YHzhsmqDl7JC/pftwsSjnkjsR4+6CYtvMpbn7 virujX9w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm40z-00000006ulV-1K93; Thu, 05 Sep 2024 04:22:37 +0000 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wM-00000006tM7-3mQ3 for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:17:52 +0000 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-70f79f75da6so241684a34.0 for ; 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=lists.infradead.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=bDo3GwdP+PeYPqjf+tWWeUZ9pJEn5Ke+WSjxpXEqcCNqCkQAhNOSma+jbpv4cTVBNM ZFS/lptSTNM/mOuDbO6Tr+rKB5qVJvbNhQahO0HINs8rpQRSyFE8lbbNfhtmjOoOqBQ3 +wykYVfpexXeypi45YgtJyt0wgjQipKy4JCB4aJC7oe8i1O5Vm8MfsDDw5B4dU7lycLf v4Rqra5AHgXOPxqn0BMTqpgLkcORzV0nSK1h8I2W1rurHMuwXgX1Z5ccJNEglICaRgik zJFATP3cQcGynU+d68wsnykk7wJ/3jQ9KKIdeoMh73PZNZdYGWZiHibJ1jCzLCbgbOkU 79HQ== 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=ZJ99Mmc2EE0eGh9xjdgLYEYaX/gLRrkLFVpUsGRrtc6NDmG3xxe+/fRTd3XiWchSul xPuUJzFAx5ls8kxz69vbBSmZSv4MTwDqHxdPYwXkA4gWOZYhjh4E6z8+R+nM0D/5yBa5 +uGdX7OkQ1mxPTvf5D+Updww//HMxl5nLy2ERQ80G0YCSEqm1gC83aFUK8PO0qJ04qXA I8f2QgzqOmjjRhpr442itCuWrYthpX0r5sJpxbjX7nLkrALbA+JM+LzIQvvhz5taDaTg ETrTFaQJnAJ3FeWkwRUUNUmGKgM6gSsaoUvQvmHN3UVsaFCD+87F8QNynQU4RYZVgOjw CzWg== X-Forwarded-Encrypted: i=1; AJvYcCUR8cns0/7qcLARiYfKZCQX5d9OB3Pzl+TpMwD4QZN4wGdpSAa172aRzWpD640JhjdZPG/2WZJy1RUp8JrS9CKo@lists.infradead.org X-Gm-Message-State: AOJu0YwDDsJkF7BI3nCjCU1MndseBTxXhgkqRy9+k1eyqpCK8wJVEcpI Ybu+H5yoQIn5ukFb68Lg6esI3MN9JAYE2OUVB9CvMJ99+4M44ycI 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211751_003412_11ECB6D4 X-CRM114-Status: GOOD ( 11.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791710 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6A716CD4F56 for ; Thu, 5 Sep 2024 04:23:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=S0EXapSSsCRGMYSuYgIhJLIKriJqRLmvnrfU3aGsX6c=; b=UnLe3FlrNZt5VPu9FhxLfWeTQv inlAaDQ7xfll07efM3X8AG6sn4zdEqGio96R0A78aSbz3qut1P/7deE+e5jEZjMtIa6SZz0QL7ck0 pAq9E5hKy6xVpZVgx0p5/c+e7IM6FbYeRGhQiRupbQd3K949OrHjHYER/CAXBb6ibZqyqtFbQQy1t 3DvJp7+cbyWB7iPzbzY/wVEtVbPgzaBWL9UZQkE+OL8Ncmp+FWkyS8A6ayQqtdpYJakE4vSo1Ya+v LWDuQUgKs/vh7GWcXj2tnU+d6B/T5NvkAW0CIaQKZSSktoVtr6sNM3OWvu5oiinTe6elo1kTYIOiE JBL8zCVQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm41v-00000006v2Z-0ajL; Thu, 05 Sep 2024 04:23:35 +0000 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wO-00000006tN2-1pZ4 for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:17:53 +0000 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3df07543ed5so235775b6e.0 for ; Wed, 04 Sep 2024 21:17:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509871; x=1726114671; darn=lists.infradead.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=WoXbGuHrhpC2MoEbA1n0h8KeMqBDEQ68/kySpw8c2a/J1nVviTZ+oJFBi8w1D5+zw6 PKVRT2w1u+1gTUV+R2AqBu+v0mYkHFUl94ap/VKSrCILdxBVvXCrW6xJ/0ZbcBbjYrjp +vwPDe2d2qsRn95VdyhPV0AOzVUx1pjEkszmt66GBzRZNQJbPed045ulr7D/+3EKVQZI Qu5jqLI+Po8QaWVH40UYQbsgyok49l/e1s4Dfl5lWUI7Z8Sy+5pfDaWFVDi2zaz4AnAZ x4bsIZaLV1No+TwlRKogQEbAaDdKwEppDlfq4WU1bUSoGFvo/zv6U2+b+YlPPtpasX7f L8NQ== 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=D7iacao++7WhxqxuVabR8G3H8ntjbNhEC0StNZBHC4ZooxY9s/+qQ9iTmvRNYb0Hff 7j8Fu9vWotzjpuYnPYGcGXZBGkXJt3Of/5Ypv6gMEQfgE6/FFhFb6UjgO6eycGIe5XRd mJOnFJoh17K6J86sfF20QfLo9ko0Q7Em6lPd0bLHr3mRpBrz4LW9ZwYA5MnMMQDTklPr o1ZmfNde3ogvwMM8ZuZi2w6V34Za0889GGooRfNuHFVrkIbmjHI7JToxZDp3l7Kf2CzB /e+IsS4Dx5VGN1KwqQ04U+vZYDnm309+COxEJdvhuQcA6pp6TYFI5WfGK4eacCCz1vGS Z/hw== X-Forwarded-Encrypted: i=1; AJvYcCWsXc3ZgKIS38rLT2tszjtteWqfEsYUiNGy4QJ7btyGyTQDu0W1RLScdFVH5DETclia6OOZf5mKsiGJqFnJXZMa@lists.infradead.org X-Gm-Message-State: AOJu0YwmeSdMlnM3oXjgSk2V7boNw7sVGVnfK9T3FsGFF5+Ta81ZcMXa uR9+SZKnYJlwkL44fFhcydsLk2+ooaH/uWTFiCgiywBSqnA9kh2L 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211752_571667_13A41CB5 X-CRM114-Status: GOOD ( 11.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791711 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 337F6CD4F56 for ; Thu, 5 Sep 2024 04:24:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=T7/TrOieKDmokvB+76CstcAo/MHXLXuZvmD2LpyYQbI=; b=X/3fOnxGni8jyByzUwoVbdn68o bBcPSHSxHoIJnVyBnUYL2WhcQL4oTaD/Wpx7ABqD0eXOzz9CUUAkZn2Ge9YnG6zBnKCc9ASFrHRFC xWbzHWQS0H6uy9BD6W3KH5O7WZ3KGwZRmhIz30RqfWuUcB33tn/gxX4gCyh5oGeN4Z5fF228pwuQU pdwYVMeHPpUcoSWDGY7BQAY92zDCCAsSWvQNJ//RhJ7KAjZAKdnpXvbGRrv0wTxPhdUtk9tTbBmNf DPtHFsMtyoMTvbxYN3aeqkL6DIbKtzuth/hPbiQhrPBaZr58kPlmKC4ltgKPne4VGbaU50/TBObve cC4o6exA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm42p-00000006vCs-2mUO; Thu, 05 Sep 2024 04:24:31 +0000 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wP-00000006tNk-4AqF for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:17:55 +0000 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-7cf5e179b68so220040a12.1 for ; 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=lists.infradead.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=bILP9RfoCOD1JOGCAvJzlZUI5MIf7nsTUQI4v22XoXGuFl4OH5zvRHovQ/YlvE4YG2 s2jLSDehNk/lZ1FeRXNg+DiTKOqlaqQd7vrlujV1DUyLgTBnLFvCOWBI2EVgOcXehfce QzZww98b028TVP9OKkUECdIZsjs5nBcpaoPpFhgrX6JDbXvVjTI20bhpIgLMcsB434r2 D9CrYFw9fgDpxeTKLdXvMEx4bQJ6vDhywIw0BU2UwARkZqPH04qi0uApXw+Z8krAkXUx C9l/hs4HVRlS6vqodJj3bsvtg2xAmVGmvWQ3+tUa+3gR80kXMfnPKjYKFvrWL1owY96H M1jQ== 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=l+3m2M6t6a6OfDNNOB2yPo7N1nXlEIgyIhp/8i/lqHR0nd461SHGijAIUtgqpoA8c5 Hh+j+KJ7UPKa/5uDaMn8QqwzceWqLkCEXWAaAdF9kEOzK2CQ47BZT2GuNRDyzYJKmGVg mpvcyymbCx6YBFcO6uh7kDFZzl4u6gz5AFnSf1KSq6fOpBexy8WBGLIMnySx8HAg0WOS mburGF+S7R7EyQMKYsKxc4Lh/UuNCOvEbxgYdm1vN2+LpI+W5LHGZtoos4zkFGXqJkld poB680l3Q8TO+8kQEd1BZ8A/MQiupOwW9uvIeDqkSueZPYTjajPiGah2ze5DOydXhAhL iwWg== X-Forwarded-Encrypted: i=1; AJvYcCWEI8+9+u1+fYTR2RmIvGoZtogxIPG3N5MIJJYYIj122mT8O01rJ8N+0sc8zxgIAyLcFqkNfqwqvvN9t6hNlOxD@lists.infradead.org X-Gm-Message-State: AOJu0YzNZpNk6lqMoo/ZCoU4BvNmv32p/gYsCcswX4BV5aWLoeMIRczt UMdiIa7OtQunt8OLkbdO7fv9jqeXcAfsW93nVgxrSoyaXHF++m/3 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211754_058564_1B034799 X-CRM114-Status: GOOD ( 10.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791712 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C4287CD4F57 for ; Thu, 5 Sep 2024 04:25:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=j8VPXswHBHTUlmDFHKrQ5BC1wv3BR4y3AP5bfe5KlEs=; b=VeC/d1cBjpvs9XibPMuAAwHT7p P/0y9Fra6yok6KtZatLjMidsZ3zUzKMrVq6zpNm/J1qhnJ4jiDzz+if66Kxs+c7izM5eoT3L7Ix+m 5cJfiLPVmy11WmYUtWOErRYozAfsZwntccZVi4ZnfybcZTUjGzF/KsBGWXre7M6Eq2pidRGyAICe0 ZKhaMnzHM4bkBrK97etRQZOorh8vLgR5j0SIPw2Aq7xqYdjuhS6u0Lco7frbboV4gU544gHbO7Zf8 NK3CaSCLMlg/H76tdd6gHOhiqzdjKa/ZP6nOJIaGfvBgeSmAokMfld/DhQ2TPUIRaWvps+UJIZLA2 c7/EkVFQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm43j-00000006vKl-3p1a; Thu, 05 Sep 2024 04:25:28 +0000 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wR-00000006tOM-1cZZ for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:17:56 +0000 Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-5df998d7a44so211921eaf.2 for ; 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=lists.infradead.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=CI+/LORN2rvmik0G4JoY7RcB8wmj+QA855R9sv9WKVgDnw/SchvKBpHSCx6NEO0OCB Ec91PbWVwB5R5YNfoDyqGfFu+rBCK/ngpdc60gM7YP9MzCC6qGp8R6EeN69jNEOFzVbW jIXgo0xLhNs1kq0G9M+eEMhgdu+kOkl+bhJfdhTM8RUhqZaxL06O7lQaSaWJbao+w6df j8hvF80T8N87WP5hi4hZv2AZOevXI/BamlYMApIx5LFjc8wsdyVd7mysGJ1amGyzBoV9 Mb5TbviXRGSjI0PPfyPc+Jjj44b2w9Y47mGTEfwVzvfpgnN7jjnTafyntrMNUZoUTfQc e6ug== 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=bWInRP+hp4cKKHReyi6WGNbFGSQ/u4ni0eK8njbRTENrAE4kGcD5pzj3CYsXMTwOpg XZAq2XLmZs6ZZ7q8inJklXDbBX4n0dEq3vVVTiuiebUJqePUKLQAvrrKs+zgLgwqjgmR RDK/FFitKezHBdO8kgwEQ3O66DJQfFXq9wve9fOfLtiEd2d2N0gDLYxCpPaEm1lTDL/s 6z689snnol9LeImf4O0x18VNPzu+/xccKtG0v+nluHzz7xYlrXpon6OIdG7PXjFEZXQG lhn3q4xWzhFL1rmSPWD20uyOTwjsl0A3ZahwdSVcaen5H9GY7rIag3t0OWCDNml/G5J1 w2dQ== X-Forwarded-Encrypted: i=1; AJvYcCXLUdEO8KBWGl6qtuJqkyTxPRiR2Awl6nOxSqPVi9/fYqhYUZF10b4Z82r4DmmUpjE98sCtJ/1gu/4QLmKLfkbt@lists.infradead.org X-Gm-Message-State: AOJu0YzBOFcy6Ld7p51r5BIhLrvTK8VcnD42160dlL0mFDY42ePm1TgU 1jDina9dA27Mznd1oCN+T+3orQpdHCkJ0uQ+Acqz9d7LjeWvU2mR 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211755_460933_985F3A7A X-CRM114-Status: GOOD ( 11.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791714 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1A474CD4F56 for ; Thu, 5 Sep 2024 04:26:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4mhjJvDJNhv2xHoY3ut/g1TUbMfaB7j2eg1v0tOHhm4=; b=Pvui8zEMNOXFJ4jyC0giWRG1yd agpO6+yDffGambTX6s4Lkft9OL4pyE++sTtfgfPMM47ZbH4VKcA8XAxVCnNVpqV9fTGYiWb8go1io Gfne/pr89iyDoH98iHdlbGTmuJQAK8nkZ7CuK42e5fT8h7HQhvbj7Jl6K50Mp5cSOel9hg93UWCkJ jzG5iK3vl6wP/fftUXf2vqjyas6+yGASXJHyJyD4r+nLJzwStrQzYHDJi70os3qSwVzCJ5r/Oop0b 8zRFOKGTVW0yYnnMB1J+nJGRqFDsL01zDDR2TC5GN4fRQJ6KVuQbV/hm1XJPF1yFiFK0VKXKY0hjZ UUVTG5DA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm44f-00000006vRP-1X99; Thu, 05 Sep 2024 04:26:25 +0000 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wS-00000006tPN-3kXY for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:17:58 +0000 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-70f73ca989aso254897a34.2 for ; 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=lists.infradead.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=N2NWZNrV8Y1GJ5QEquPbyR98mxX7Z1q4bjil0Tkt4IM/UbpWWCI8Jr1fM/7/8yJWu9 PKNqYbKBraVQ4dlKuwVxqCm/abcQdcQAiR6ubhWKmyGLXP7b0+rfzQF6NDjoA3jdfMV0 tXxwc3D4rLR89ESUASMtVeAbt9JMNDFkw2y9KqHXiCDRq5P8ioYEhc7rrS6upmKrxYiY vZWccYZ8zVwfPsI/5IsdSIlsAyZVKNekP5VcOLn8GP6EbKZIjHsW7trEoh1NtQ2zT5Jr VLYc6rUz8C1GP9j2H/CKok44x9p54HMgn4w7THT7apJi5Nf9rwVBQg0WcJsmmEE4kpID UfdQ== 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=HJ5wHqYPqaHLUBnW9m94KWVsFZcFSQXhcZTy1xiIYOmMAx8zZHMnulGvGYsXl0I4N4 /V4Lwng61SP/SIuTNQwPVm+7N4g+fJdAIa/S6NRn5LfMGTX7U5iFWiJcTh2x4LltsYxi bgpYAPGyYCB28nM6dmCb10O7qVClNxFHoX+7HhbYcFuYXJKK0ylWFvjCMV0Yi0TthZYZ r2KrEZlTZQELK5m8BGeP4Q+SRVN/2QRpkT9y3AViD7zRqPlubBFRxR9pn6n1JFFtAObr IIxtWchaC5TyAZCzKWHDKlYCLjMcZ4yya/6RxLGBEda8YWZjFYsemsVWXq7Df6Xj9QAu 2cGQ== X-Forwarded-Encrypted: i=1; AJvYcCWODYkO4LHnghYLqiEz0Qzz8MnemaBJ7yf4bNAYr3ZVL0VL0Cbeg5HORNjV1l7F0F0TioTIfhqG0bMi3pbJtZc2@lists.infradead.org X-Gm-Message-State: AOJu0Yy6RTp0meprZqybWWnu/Fjt2g6muzJGxISI9TaMsKCXYTAhQwkG DynzN5gwQeDTWK68fkHLwVHILCycVQ0g70+DPUt7kIQ75+ejePku 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211756_963674_D904A85F X-CRM114-Status: GOOD ( 12.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 556ABCD4F57 for ; Thu, 5 Sep 2024 04:27:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Mdzi002JGx1/VTYSFinhnta06n3PxzWkqyJNw8JR4ro=; b=X2bDYeo9i841gWSWIDommOSumr quQXxhvT7QBLwiUOe/qpwALPreKxyPaU/61aSErg2qHFpE2UWR2dqvpEXmHfi7x0k+LueIy1TiM5v dFfnIzikhbrLxTrgBPkEzlrmTA/0okZQBPqPvYPhznmBB3r41hIDzwaG6ljbzv4V60Y9tj+9YnsoZ vhxXZPdTDCcC83ZeMdVMo5tHAA1HpbqFo1pQ9faD8ucnk3lgqnpFbFhPa0kEA6aDm62SgY1ZSBzTm aAgtv6rmgId6bm5T0jolQpBRWUVqgsgOYXMIpPhV8319JzLm36mjUvexwqze3Rw556yUujfhLj3jK cY+dXYJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm45a-00000006vam-3dA8; Thu, 05 Sep 2024 04:27:22 +0000 Received: from mail-oa1-x2e.google.com ([2001:4860:4864:20::2e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wU-00000006tQ7-1siZ for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:17:59 +0000 Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-2700d796019so218472fac.2 for ; 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=lists.infradead.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=VecPmjgH9QNICiArHhS09dri4+efID87IcWcWBrS0xwgAf+FZ1HYWQwTQb39/7+qSN v8TsORnLAHFck0anQYE9/qSn2+Hoslplnk9S2chycrgE74Rc0Jn/9daGBFbaZC8cykJa 0vKzXszgCCS7OhAnkBl4ECU3Cu4X5XPvVZbLitwyNh72fExyLu+4OQSXJzHktRl63ETB y7cfcy8GISfJyBruJjMHlumx9Je9jJQ/bRfr6NpOFxGyZJOBk/9r9G/oVRB4SFdg/XEM kpWqnkv8hPpJ1PUctGbxBakdjzPJnq9njucLmEuKBf9DV8zXnNjADwOMgThrQlEtlpc3 /3Fg== 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=YKM+i8x1ptx62XxpOPTAua92dqgsy3KIbxg4Gmhun2NVrSG3dqiEDf/BfeIWJSDSSq pHjAIwKPuYdIRebjXJjqc9/Vl09bNDFCP1taAdeEEisn1aBfhHlu7F/znF4PQoA+BX5g QPVMIwZ4y6i1q1WYJSVsXp28277KA7HaDCezbeXVAS1zmkSXjdhBWdbNDH+EDmG2j19M j6mOAV+JtlGTbdh+Lyyb6zIWq1ivQPZCstiRzkUjkpDmrgKMCLAUT/Logh4AJ0R5lgs0 O5BBuQUdGFKO/+VZrNK7wjxDnyyacaRqC7Z0kqUSiT8hX9InmnDXqMDvteem5TlvXYYR yFmg== X-Forwarded-Encrypted: i=1; AJvYcCUkLhyI+cnKOFf8hAfTguBCSgIBH37530JAyOnv8rCdvzQ75l5OgxovM3Capxi0/hp9OYla+fnXOPShc4c5gYDT@lists.infradead.org X-Gm-Message-State: AOJu0Yw/Cv9Jfl9E5Mz7DBKmXItEvPz1X/Zgq/j5vOodGy861X+48wy9 5Q9TaGJ+o0BknmySsraEbvTYgqTyh8wU3tU77WyKXO/izg3GnPok 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211758_509151_1B8983C9 X-CRM114-Status: GOOD ( 11.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791716 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 59698CD4F50 for ; Thu, 5 Sep 2024 04:28:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=5IVs44o6ciGNOoB3tvSvkl1E7l7ddGpRPi+mMdxWbfc=; b=QZW0HAChTcJtYo+k8yqrYdgaAd UX2cydBkLW91cXMCQeu2/9zAQbvXVhviurp1HbXQgDuQBqHhnj91T1kIRzlPlvbEb+NbT44WKCq0F FjFXDSOQOqxaxd9bo9+pYKkxEEGOTL5MN7CGkvrJOTN+xATgLqgirBcyzNeONOoU03T+dugnRbUDQ rQP/dq8MzgRH0jVpCDGYzb+54l5ZHimYX75cb+BGYJEuV+zEWKLEPTLhq6lzIOts1iJDihXMQmjSn 9Kc3B7a4nhin74ZInamyH0BE72p2eLes/BtY8a8d1XgonJFN15w+wFQdk/v1oyTfIJbQDv6Tg2nEg PtVgk8sg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm46U-00000006vrH-3wrF; Thu, 05 Sep 2024 04:28:18 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wV-00000006tQU-35I1 for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:18:01 +0000 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-7143ae1b48fso210505b3a.1 for ; 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=lists.infradead.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=MtVB5W2aEjaqYi0QoUOpKOvNbFkZAlqP+f0/a1e0dCdJOUx6EUnnsErpj1D+xZNMrM 20278LxCbl3fKNTyM0aJHyHrWrMoNb2zg6mxCvBSqzcQcGTUSLsUBtvK9ZDLjm/kazi/ okDjAnKB9gN36C1nXrFn8/rxk9UCOnHyzJukgjF/KhDs/jiFHXU7pyHtaY2ndwwIvJ60 9Tr/JuANseHKxhf3w+GATpNLqKmzYQww3m9QORIWzpM2a3lTn7jVCO6poKQiIFvtaY5k s+IC5efTfwFfKap7LwRICkWB3PmWBAfAW7rTOHCmlZBdpvpkiv2OqBUWSWxsyV1wiTSY TPTg== 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=UfSZ/4gRyTPhe86XirD1ja4BLub6UZnCrN7ypcw/AMtL/mJw6TrybS47ihYZOuxPej /U3ze95jad8bC7emgWNLT29PAqyowvbDtfN0o2mojfuOqblTS6kIPGd8vfABOj3lXeGD gTTkouaugBH4jEpTMA5ucSecR64NL89VydRFVmdmMQRms8dmYqeUWGvfliZk4QsUTXwl tqSBEKnNHss4RKTpQiwtWI6ox4uQhwenNanzg53P3xnrdaDYLkgypT3nqAyMd+VZIUEU lL+rKUqkwNv0lcYnvuANuTTazkTfIB5ufia/35H2x2U46t1KJkCKBYiaoNzcjKmiVDVg NoLw== X-Forwarded-Encrypted: i=1; AJvYcCWWhthi63iQvQj5rl/TXytI2BuckCNm+YxBfg6/YtYkgT1ohT2zTty+jwyisn2uEH4/qj443IrUDEOUMu7k5B1f@lists.infradead.org X-Gm-Message-State: AOJu0YyI1OOi1ibGRpBOrIwh1U7UW9M1B6bCY+oO2W8JrdCpxY/ijF5t O7U449e2ZLEBlljab2rsdWLQLYCgPjRmEqxD/Uqq5pRArSgkSSCJA/bFTQ== 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211759_816725_AE21DEBC X-CRM114-Status: GOOD ( 17.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF0CECD4F50 for ; Thu, 5 Sep 2024 04:29:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wySGI9scoJi4TljRD+Hpmp4oNTGGODlyYEe5tlANPZw=; b=FMNon2GwxWJAkI4p8jnl05z8Yi gfdRIMDIxxlSuWuvvRMMY5h8CCDyuNI0jhCC+rr5eZ06yWP7RlyqnkPk2BUpW+PdTnt4pEIFNGUe0 06ymhU6Wxn+6tLrp3EWb5ohnzapfCjJbQFA/sy/tTY6t1XwJ+ZkHa47mcy9IHuuID3Kct5S8joCiI Z41/XeYuZ5YCvgcOchjRjoy2wzfAMWCQfAkyYfbmDO2Xacr22jtpVCbFiAXGMck934ADQa/v7jzDC v9sI0H9MIK3bH7/et/QsbGMC9iFSFdN+1IjKVycMR5yMIHI8f8IHllS82k4K7cFV45Xd0Nmhnp8m1 +j/La3PA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm47O-00000006vyF-3ZNX; Thu, 05 Sep 2024 04:29:14 +0000 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wX-00000006tQs-0mL3 for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:18:02 +0000 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3df02c407c4so180214b6e.1 for ; 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=lists.infradead.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=JSchSw9D4g82ihrwENrFqQB+NXCXiLpFCWDljt5N2i/L+STXzut+4qkPSCQwh0OUzy Z+M/CYVYRNP6xlDMDax37FMS0aTFgtwi9bewny48W9JozdVgyvmEZWrlVBLqQlfXMUud CAjcQJSPFDJfllB/RxR8e9bxANSB+1oO4r8I3S9bxLN+CdgTGBTkXxU328UdL94saWiw kWJcDhWrXlT6iTzTXycwZ0RuUy6AdzTizJPv0Yo/+fnw9XjwB7EXPVAb3vwL4RuowTPW l+X84N3rty2iR8Bn7Q/Eu6+/tXaRN2OqLgSgbjCTy7aUCzyxMbHzHQ0V7DbwCQV5WQF1 KbDg== 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=JvPOlYxZFPLq2PT/TtABS/T2iRa0Ow55MqUpWGLX9tvDWKb3a56fJo0UPzLkkXjd0r eVgg3UOLHIECstp5/gw+RkHtdKe70xGsv3qXDk+qm+EYrlsPWR1Z2gNT6+aOA9BCtth+ 8kr7UOl05PHK0erzP9MvDJ5F+ocx8D8SqQ++Ut+Q95vogKSTCM+CRc9RYmtkqiayEPys 48aIdr2jaAeRB7F7Og7R6K/BXNN1iQsCFxZYwVuUAJ9MspuNU0blzfFTU/fhVyDDzUhw PTydq2UVcc2VWlE29h6Eb/5yNaPRxBg8pi7gu2nDc5MWL64l4FaGOLe5dSPSrdCHz1KA 3jxw== X-Forwarded-Encrypted: i=1; AJvYcCXYmWYieIJiA+TnK51DH2NSW4VhFbZUzcDG1TZNKAqJJO31gWoEyAB70uIFwgt0RpY+L6lv062d+zQzJNtAkN3y@lists.infradead.org X-Gm-Message-State: AOJu0Yzbs5KsK/EtHQ/ccPMaF9bTR6uccFPFDMf/vBP28qbeGPrWAuDK yYLhgJRThyw12Izw2h8sOngU4Izc8IY6RfCazA7TA4rFMuQh9EEX/fCFSA== 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211801_252230_B0682EF7 X-CRM114-Status: GOOD ( 12.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791718 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DA196CD4F57 for ; Thu, 5 Sep 2024 04:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IJ0f2V5xQlnWNK4EvLWQUiJbt0aWje4MjkaawAE2fXI=; b=W7QRa96e6/G/fDQwYHZvKJ38l7 0HhYOMelaDHE8gFGafV3wuxH7qvANIg3ymqkGDEerahu6IhlzCCnreNhO1a9DeNLSjBvEKG7cPcGg c0F533n/OJ6kKTvgkMzqP/Ug5wWTOvRNe/o/NJcGE8XSlo3kGAu9ktBVfrvasKBHvPn71I4ih3I0S 80N/cH8BxdS60SnXL59MDTgsdM5pImhuzGLr9N5QbqFbo/xkQihqX4OSBnI/jR0hud7k8rqoKz9dl RdoSU6dTjTAT6mJ22L/fMpHVU2y+oTvIo6SijmeH1YY/uaGL9ZoqqDmC+blEuErCotOBD7fqty2Rf HU7IDrtw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm48J-00000006w5A-1KIz; Thu, 05 Sep 2024 04:30:11 +0000 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wY-00000006tRU-3dUg for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:18:04 +0000 Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-70f6118f1b5so284045a34.0 for ; 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=lists.infradead.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=WmuSmenxZC7jqWTx8F5nZhPOggEGRzQHMmzPd/PhcgSD3dibw6M3ib9KqRRfCj+tZJ BxE3DBUPGydzAtroTKT2EGu/Mux6Mm3QLIC6g79oy7OLZWB/yd106u8tkeu4PBsMn5sP qglwem6BwzOtW3gui1VN2+PG3KbcALnJ9161unEh5H8+GLCRwF0s5gxSxbp41M+fAZu2 9mGIuGnoWWujhwxKw/h+z42P2Qaffp4YrxK0bMfiYsQh8dId5pxnp321zw6bKSuULTwf kuyx4BLZTdYDHtnlGJgfbu6t201TNtD9zErjaw1drul2lD+BCX08oL8ElB/jiekUkcxx hrVw== 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=t3fo2BOYA4PZKuo5uEuvGnBiwS7nz+KSNyrj0PKZ1bVY94ushdPfuuiePqq1wBZBrD If48EkPqwvM7YJ6FG/Wfv0tQes07KcUigIWs8+w5vK7DQzQsKBUyT4L5A3TuqX+KLbi1 goHd+OO4gO/Jd8SISmCBSlQs7dDN3NucvXgi5dv+XUBR9NSRDyDE1zVIzcDr5DIO3B/f 9jeGdlJZx6CUFkjABOapbSnniLaPBnBzY/v7+yet5WUJ7rNavFWSIvTg5kaGiBrsNuYp EQtqLw9xdaxdoFJUYXgKss3ktRi7SHU+7dNyHw8iWayIrskZZnb3z9i3vao83MUaUcxU Gd0w== X-Forwarded-Encrypted: i=1; AJvYcCWEkInmF63jKHE+nbrdO+bPY71Ez6552pZfQ2aWOgxcjYHTfbowNV6Xw4lNkSWRRwhLBE6FPBdIIpsfEVswxpxy@lists.infradead.org X-Gm-Message-State: AOJu0YwOcHP1WbPSD9tQ5kZvcPiDQdoR/KzqlhTNS39PNxWdCRKDAUQ3 PjpQf+uwFZrSt4m3wwYCCsmDbU+R1uLwSpSfU4fLwJHR7laYAyWjSDJyLg== 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211802_938184_7AE55572 X-CRM114-Status: GOOD ( 25.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791728 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 27BEACD4F58 for ; Thu, 5 Sep 2024 04:31:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JXmUmnslyZHyZJLR+Zy+r2EKZKWq2y74P1oax/HM5cE=; b=dAd3cTwdYG+9xjKGJvsY+nOlc9 blMhexm+EyWMWiFodJk/rLhG76T9/2uSKQNTqvm+DvcpBEgSiD/iQEguQPpIcOMbUBL/d3dBHbTAK E/hkrRWDsMupm2ff1gm7ptnwegArExgTvLEBaoQ50RZsSMFBvvv2WQb9qE1fVTobfO5voU/uBT6+L GSFgLQwEi80NciZTUQPYC3rikzpO9VTIPu5zbTQueCMIkW6yp4FVYIrdUqF3XO9CPLCwQpmVcxo4E 6IR1NoDtjt7Q3onuh/E7yBtfAuCimTnHcHahZB8AerxLdUFNEcnP7GGEMMlMKTmpFaLqCM7XTFqN5 taVl9YWw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm49D-00000006wAv-10ma; Thu, 05 Sep 2024 04:31:07 +0000 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wZ-00000006tRu-3wcz for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:18:05 +0000 Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-70f6e65d605so210181a34.3 for ; Wed, 04 Sep 2024 21:18:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509883; x=1726114683; darn=lists.infradead.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=erXoKqyyMsuCP2QYE3GqRQ5c7e0zfUuXS+v/HoXl377m9jr7vGa/prCN2PJthx+4eb NHDaeRsjlqlDgzveoNCUHg0xiORxB7fRNVYmQb6l6/PJzGkS7O9Yd8mQJKDMb+szlyXj 9Ur3cBQs7nxuQF6PwJ9H4Tfj0kJK3nBZGinvFscMzgiv8qXW8zR9LizexGSGV2fIb/DW jyKkDongf1DNbRHngIp9xPY5rAxyEnWSS5nC/nyCR/Dub2nSSzV/vdZJDVd2NFkc/P2C u6QtsV9kfIWUtiiT1flMU9rO97k59cYk/BhMCpnvxbFx/pT4tuyMU/Zg0eYjHEfjHzr1 vIMA== 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=lGyrQH7nKWTaZNZbm3d3elLySzsjusNcwfqpjhk/97jpYrRyRYJXevWsKLD+Gfr8qK 7jbQ9C03hGlkfjfoLTmsEOqV3nBWtITTzhia/iphcRCHJA+3E5oLgEZrvdkgTi3z4aO8 3XVjdWRxjOdGRtXRBOTxp4npKi+ySgs7E89zy5huG0RgmZPJE8ck1NEoWyKcHw74aOW7 e+17pO4nKk6FT4+NdlWeqAcnPLbrsml+8VjWVhuWKkRMjtaSQ+KqEqsN86SQfFAb7nZp LvnJ32URpCtR0RlNTuHimnuPv7eoVAPDSr61RcjhIzo9KEZPKQvQkHfOfCj9n/YbA5Jq mNRQ== X-Forwarded-Encrypted: i=1; AJvYcCVU/ByxvVlLVGOzpwo0ht7oS8gZa+Io4AMLlplWXtNd8DzsnjcpiyVb84iPUiqvXZLpJsp00qvWQTIO3I1I04EA@lists.infradead.org X-Gm-Message-State: AOJu0YxMEO2ZfvhY94xJVPgLl2KXBBPOnBAk1RROFTIspOM0ExTG7g3R s+7q6zOfp6dK5ra4GuvoiJGpZIfLpY/ImaGGfjKRpKlCMhNYFGlh 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211804_010928_7AE8D403 X-CRM114-Status: GOOD ( 20.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791729 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B41ECCD4F50 for ; Thu, 5 Sep 2024 04:32:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=p3btFCntery0ta6nV0jjerZVdR60/Gk5jQnmpE6Mqz8=; b=GYWbe8sH9cHOYnN7/DqO+Lyc6q ZoY31jjJqZbLmJtv3/MiL+rW2qCC/dZ4iubC7FbJlZ0Xw3omAJcBTFlzbx5K5f67k9n6IkqSA1XhC syVhQpJyFP8ZvmqgDw4QzVbeUCg9F+Kg2wuJOSJfAufp91sPi1bYHLFxsh8HVbGjPi1CXiUlmSyC6 lMVTYHFhA3rTBjiZ9uVNs9Z/vG6SA2hsqx6KG401jjIm6B9JbxO/oxbUewDLODwQoh58lkOy6/Axr 3JoH0xr4HKwdFoQRqtmoVi8qTVKXPkzE/Ifnl/rxXhEfVJBwWw71w0xuI5jpC2qIrQDY1+45Ux5Hg Ha4r5HHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm4A8-00000006wJi-1XlL; Thu, 05 Sep 2024 04:32:04 +0000 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wb-00000006tSY-3FJm for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:18:07 +0000 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-70f645a30dcso287383a34.3 for ; 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=lists.infradead.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=hzWdCOF5361Dbwnu3EnOQPcqePbnKXQUQ5a9yZRvKZHcCecnM7gC/4+n3elkGNRrnI SstUVnRf75yqWJE+wHDjPPsWjjU5GcJgdsuTne7hiitf0MY3jT/47czCVQ7jxVbSIC2G Jhzof4HEi2QlQLh/JL8ydSEkkSDZCfP5nQ+LdB5ENcK8bO2riNjXPc6+LroE+ynHDwqQ 8yjJ6A8WPRXTyBvcYN3dpBDj7xnQf3E8FC+fQCPMcP0QutmyCl48pler327az8fZlc82 wuzMevnsgawIdwHQqK54fzFrlZl06swYTC1PSCqdENG3lx3MsuPGLz3UbtiAVI6fIFXJ uxiQ== 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=HcRSURhWFNd9inKOfjRC1dKYCU1pv9HY/gKZbNQTsZZaOO528SUOsqPJTvGDrXQSTQ uSMOPbo976O+TcCQxoha/+wbW3TRkFly/XSZfINjDN5XYgyNxacAb4inxL7YVaeV8YV7 Nis6IhSE1I+CblJmtf90qUlIeYK8TUfsLeTKd68ylXWviOYnI1+NiLXSNf91zu+Te8IP wW29NLpBP8mEUjdv+SmbbFDXSOkIsZGZYJXPo7EHWHPfA+KDyKGzRbnZUdNv/PZt/4Q2 9n67QxP2M7av4DwJEf7sNjzE9yjvqMQFTw14dyAng/S6xk8b0gchKf+C/gv5cYyPEQGU CzbA== X-Forwarded-Encrypted: i=1; AJvYcCU/wIordQyDBOWVLl2TjgDXdtxqN24OxGyyIQCiyL3Uf8cL9mISB310E1jaCnBsh4FlQ4zP3lTrJ7IfFlWj8Gvl@lists.infradead.org X-Gm-Message-State: AOJu0YzZ00YcZ0WS+yDmM5uJtcqOZ0UdDbm3BHk3pTz8c/NLnMLq332c fdeB4AXmjbwJYgp0ip/U7APG9eeesjhwtkJIvE4leoEpbGKQ4JWq 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211805_892764_D7DD071B X-CRM114-Status: GOOD ( 12.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791730 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A519ECD4F50 for ; Thu, 5 Sep 2024 04:33:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8RJDHa/X116xPB0VZS9gOnIwjZdjbYo4abWgUGhtfDc=; b=gIR6kBFNvupnksIZTpALoppPJB 9BsA3XC7xrFBgGr3oeqUXmBxsp4Iz0eC2sdKjohpS296XNnYtvN7bgFXsnFT0n+y047a2gM1u1Ss5 fjgvDhYJ+A9P6pcdOx6XfmsBjYmUhFsN9gQA4/RZ77SHWJozHbNfqIBXLkTNzN4t5pa86d18Iwnzl Y+Mh3b398rrrny37P560Do/OPnf+CdG91y6iL3EZlcxPB98xz2uv03rqHwYECnRzU2P1+B63QWpy0 LSXvYMPfSWg0j4y1cb4pKBv2+1nRGVXZx9yFQboYosqxV1RWtbp+NPZyJmKctasiViLZ3owdArvgl NSmouOTQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm4B2-00000006wQZ-2OW1; Thu, 05 Sep 2024 04:33:00 +0000 Received: from mail-oa1-x36.google.com ([2001:4860:4864:20::36]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wd-00000006tTL-12rT for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:18:09 +0000 Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-2780827dbafso233069fac.1 for ; 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=lists.infradead.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=cUcR+e6/nwBwC6ry3W7G9VkK1jWHqwUUTPKTdnUN/9gzBeG4fQ96sdBDqtQT7imb21 u+EWEHs2K0gxe5GOydnWR/492ygFA0U345rKFZB4XveUJLj+bFSbdxHl1GcJhMJDS63Z b8V0l7E/pntibvjHX/cgRNxGBMaONLtbspxNMS4k8hck0PCZvLKbNVj9NzG8O/inkm1B OvfrYin0HK+ZMKNvKk0OIljS4XMx5ImLYvMA9RmX2CItgR0uU1mLrM+FIjXiWhWjDb0g /5qOWi22LHRO6qK1pFscF7lfMBQz8KmH5OXGmW8hWEYcWPJULcl+GB0Drtkzke55qnKG ggrQ== 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=dcgQWSRGOYEwRidUH3s802PzqgE/huyeZcDSDvNAq9N0oNirZdVTBS98noyAIv19x0 30qarOrNUCCwFq5zXAibnV17rVogBMs1Cr2lTIKtfl1iTE1iIao/HbNLCAyVDBPLjNU3 RDv/M+Oo4Am09+Vw18/KroNR+GSmnmuDHlBELPfjyKMr4cgNlzvbhUi1Cb0aKRRSj5xL un953NrIKqaYpJV80gbQ2ZFeq7hAfWG1F+WPw0EPWFOS/3OT3kFutmEPyYZCKfzGL930 HrKTJ4zFneoqwgi6laO4QLkINbDgdJvAivRNCLrdaPtKtEwIkHIREMfsD2rsdaeWHzcC DY3g== X-Forwarded-Encrypted: i=1; AJvYcCUJ5Hos6N+SoorZW4whayQgaFgBbNRgSj9RIkykz4FllIt81NJKXogXTJ4GibH/ZdlXLSycZ24JI8uWZJp9Nc7H@lists.infradead.org X-Gm-Message-State: AOJu0Yy1s7bJZU5NjYKfoBilXn+I3l3Xi+pJjVjivgRkof6eRHocAAjC JMVbVY6oUtlVXnLBRrdZrQ9QDS5LdHS35QfxVS8Bi79WtodvmLHy 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211807_323143_754BE287 X-CRM114-Status: GOOD ( 11.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791731 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63CDECD4F20 for ; Thu, 5 Sep 2024 04:34:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zAvYQ5QLNfvwvbAxc5bD+RAm1KaOm8ejwTdtW3p547k=; b=4bjMedB+IYt+RZRI2Y3a+DLAaV metBR9o71qpC22K7PNd8bNR2BAGD/YgWb6OF0VBqraan7jbAKtbbJHxTnno/4WIn+vcDqhbsX6FN4 REr7QnChobl3L/XDlJ5Z8D9w4hrKvi6NN26KQ5xiewiFfULYkeXTFjp7ArwRkmA0JkKFs+DSW0j80 /Cf6JdWeylgqqFmP/wNS+SLTPnlejxGIyR1CHHC7MFzS7S6rzH8oVKImz01V6AQEr2w6xyMHiNDnm nI4AdhmBSwpJzyAO+aBm3Rg9C39kIuM7N1o0/PJlDkZQOxwbbo1JIVAKdsF9nYTcMeZbyVddoxGBl uVtfiS5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm4Bx-00000006waW-2F3G; Thu, 05 Sep 2024 04:33:57 +0000 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3we-00000006tUB-0dPT for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:18:09 +0000 Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-70f645a30dcso287400a34.3 for ; Wed, 04 Sep 2024 21:18:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509887; x=1726114687; darn=lists.infradead.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=gMqosvHlLlDsKA7WNiSuw2cJ9z4VezklHZsVgfAdBSt1fEo9vDgX9OiJzv8BIgRG6L Xfj6fc66eZMM3B891hHf8Th4wmCsJsQD7URvqqblEuBr1kXYl1H+yFqbRxAQgktzw83k 762psErDU31StwxmJvWeDYS7OFuMu+vXMvRDFyUPOstbfS8bQ8GFSTcuYOAA5d3CV5B0 hRqKl/ZuVnivTEPWH/yFtgFswLYjT8sekZG7FYzZ8AH3WLJV5dgs2VvCZMYoXr7SbfNk YbuCFw8q4nlaqs8ZkC7xfQIoS3tr3KEZFZvS36EIiCdXFqAfQ5d7bg6U2lHxxSx3oIBZ ESaQ== 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=SSQhp54A/UUnlIxgIs5yFLc8RGxrfr08irGEfLkEcFqcIyBwBA59EdHpKEhR25Gz93 6Q5VHgEm/nyAOp2NYtyKPe2nwjDoYuMq09IzZScaVO93D2Bcz/33Pg3hEO3i0Qr6GO8N lQFfRLY1d+hIistuJHRTTEMmdoIe7XD90uPg6ZjtG56rm/UZh3ssD5NoF5S5FioxZpYZ 6I5i6fs6eWrii7QjgiTXO8XuMILPu5ZGYGwLo7v43WEYKrmz9J24Tyi6TdUHdcCOxaED XkP3KoXQsVvZYYBO43bPdnhM3ghlzNAMQ6ucDOcQhduzlSPTgzplm7rGdgqHHcGYPvsb 75QA== X-Forwarded-Encrypted: i=1; AJvYcCU1WmyRJoYklPvgQyhjWM7eon27eWkqaPMjStC/d4lA1vLiK2PgQq2xzNCkZx1xM0CmBSCptE/Ml0MGnL7wZtq1@lists.infradead.org X-Gm-Message-State: AOJu0YyFzxs7yra44/nJZISnzI8AbgT/G8dAHgd+ZXRybd7d/ZR0NNZp wNgwvAGuj+4Imzr3U+4HQizQGXbEkY6Xu4tsaY++NbZ0OcIFOkFu 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211808_212910_9496EB10 X-CRM114-Status: GOOD ( 12.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791732 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 14CC2CD4F50 for ; Thu, 5 Sep 2024 04:35:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2hL/oJ8v77sFrESpjTE2muwhc7qNiYaOX9Ne/zSSlqk=; b=4caFeu/BiEq3O26zGhviJSjpuY J/KVGACkY4m4vp67U30ps6vs2ApI5fwWBHFD9peIVd4pcCW0yeHjIvq0LOeUbiHz9D2/xdGSelPMM /knjxMPmd3t7Kux0JS4xlnLBgkShXbOr9toqcDnjkXX83Y0C5togdwR+ROfIbXwQChUCZ2U8sRYsc FwG2rmJxt035MC+XRD4arwIqDR5E4X6FuujvTtUFVJoNaqLxmXQSPQk5GA1NE7uXy3LQ4sjNjYf81 /I3plf4EvM2xkGKDo+Ipy2yNU4Kv0r27LINJwhOYhosHaTSnhl+iZ5BgAWfqYLSmCnJB/5FVZQSPh 9HLu1omQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm4Cx-00000006wuz-187U; Thu, 05 Sep 2024 04:34:59 +0000 Received: from mail-oo1-xc34.google.com ([2607:f8b0:4864:20::c34]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wg-00000006tVA-0Zhr for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:18:11 +0000 Received: by mail-oo1-xc34.google.com with SMTP id 006d021491bc7-5d5b1e33fa8so211688eaf.3 for ; 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=lists.infradead.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=aoR/3YJ8Er/6iBZvXFdcGa1G+NqjChbl2iKmD+w7DMQ42hmA3pEeQU5wM9erhsOJk3 YkLOifkfP3ZNuIXZZs/zYss5+DjYrjug6s3ZuuVzitdq5ZTDgkQXR5wd2O1ywDqXBffP OGpr4OrijE7NzSt0nVvu/cbTcfSFBmMEVYqViK60GjjffC6ruwoKB+y9tXaNEGLBEoLC dReIEg3X9P9NxFLVXOS6ssZr7E9BANOmoJEjZ0aGgePxPyVEPQtXj7uO4of6us/UAh+E kSrAVvLWbtm6PMxDOTzWZXKJMivCfknldrmPSB78dzwH4Xa1Qj3+0ll244CGydK4Le0U pVTQ== 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=Oxwo7UhbzeIU5cIaNdPYtQmd0A2ecd5RGiAMZbznyKLHqM+TdFOeryPbeXVDj4i78S wsi+3b8sqFndp81Xd5D3Ncl+yFsQyyRz5OxlAGrr+rE5jJ97p/Z32uzVkTf1SSDpDJg8 vokWGgA5nfZ2lFroXw5gJI+t89kmnHsurHWqnsHxdDfzTHpN91ia/bNkTvap3pYXqgby YHYpDxp9sflm8S3vdn/gmrCNuv9LsGfEuFtHMuOJ0RIPrzxIAC3G0KltOdBJH3Bw1lWP 6PW4DTDhJVk3R7aMNPipWDVHdJivGyEVl2Fd1buFMjW4k99ZMq/rGFx4BTWTNwiiOPul 7zcw== X-Forwarded-Encrypted: i=1; AJvYcCWyosQ1+pAWAMimyZ/Ais3NFtEXplww2p9L0xQhrpmD5NgtPfqiD0GBTLq/E2MVXqliRDAaoXk5tGaIZYKfriW1@lists.infradead.org X-Gm-Message-State: AOJu0YyDYUxldwu2N2sOxkAKTuEsG0ZkpR3zFK0TJ1BjJaHJLBsRLQAh nAmifcVkx5GpE4exI/G5uWUiLLIwG8SL3WDhdOHOQDxh6p7UhCf0kP96nA== 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211810_240485_3F0A4B9E X-CRM114-Status: GOOD ( 14.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791733 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B9F1CD4F50 for ; Thu, 5 Sep 2024 04:36:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zdj97WNnHfmaSgwSXHcMMW5oApE6Xxi6ExD1cTeMbgs=; b=YXKFKysMigZYhrLmMlw637d9QG M2lmtWv/f9TbWnfDkKUspza9PwJhDHR4UGsmlGwbEHaecW14sfoj5D2briwywWIzpn9OylfBBAnED AAoN3ronyy/un4GV/XgFOkZCmfYSHGMKtItd0oRDAelbMx/cSrgZA96nuKnpfjrPxFer+0LWgOnbF 2z0+Km0wu/RzbhgeGp5Y94jmiv/jnBu4bXk2Si5Fb/+gwvHgK2MoPr3HCQjxHvKU9KwVRrUhQlt+t xmH3tbgRxsPlSsMacQqdXf41nZRKU7Z0gZiPI6t5F98y5tLt5y0OLeaucBLdnn83YdFHPODJcJIu8 9p+GbVeA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm4Ds-00000006xFR-3yKU; Thu, 05 Sep 2024 04:35:57 +0000 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wh-00000006tVt-1xOE for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:18:12 +0000 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-70f782d6ba8so192145a34.0 for ; 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=lists.infradead.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=SOShAhuP7rFuKK9DpAcG3ATClYtnsr8fbfYHMzKsoQtVo27aoAytG9Kfh7MP1pzZaI kQhvuoyeLyeJPzqgxikX3+rXz2DTyzmIwyI+bOu7FKUQYB0atjTe9s0y/m4NQt+2G4MH td9PBajyPdmF7stoV50P1AMSxzED4rkjxeFEO0uWtUt7DyXY3VC8Tu2Pt4Qb0CMWNY5c aVLK7+h7IIGgiWAqjDqwZuAU+qBU1lwxyfM1g2urh1Iz06URm/Wy4zndO3nWSw5a6yJ3 7YQlJ7eZOPDUy82HUqR+3pMvz/Zq4Rv3Pmc0erdizHiY36PGYsHfu0rSAB/KTo8f0Bwf JAbA== 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=e6uuTIwBALslTFbitqLMkq90rycP1r3XfhZrH6jhOAtavjRRxo1dzilaYjH9EPIct+ BmptjMJym22cmdBvv1Cke3Z8IzWqW9Uyc1LB8wOGPrT04MzG+kN45fQ1i8aoXwCMHWi9 AkkS0mzta4hj7fl74uBIeYgH/Io/WQ/zB/SoVUxTkNvPB3HJdIPx3vhNQU8RlECLvqKN hZfm6s6diEyKCwn/pDTQC0FUgXvV1CWouuX7NU0ljZkBu2rWELtIEkNJIpZzlgInvhlP wnpFKejY8OvS8jCMXWi0dG19q4KjRiMgYfGJFDPlOnER247F1JZLpPLfhk41KNvlbOy0 zxJw== X-Forwarded-Encrypted: i=1; AJvYcCXE26CAMJ1HGXCubFq8uH35OO+KuesBQLNpHSaayUquHDgI4shTGuV7YvSy9q6BytISBWi7eqfK9IF/lAj6tnnM@lists.infradead.org X-Gm-Message-State: AOJu0YxahJr8m1AkZp2Ea0x2sXA8cMfsNFVuCZraC3cviHaeqGjTFJAD m18HKdF9cHDCuPXpYgz+kzz4ZvSWNdjbSBkuVotM0x2aumTSG4d4 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211811_534175_D424CE22 X-CRM114-Status: GOOD ( 13.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791738 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AB3EECD4F20 for ; Thu, 5 Sep 2024 04:37:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=NPWoWt+316Jv4PRkQXpmOTDxa9BtNdvynfRmo3h2lZU=; b=44LHY/jF0IDqixUP9IB+1hs0zb fSSPXr+nSn9k/dnp8N6cns6yc7mhXt9gkHUyKCbZYwoNdsObLSVA04I2xD9WA9hl0T/1XHe1Vc1H+ ry1IC2v8memD9+jKOoXmDsbb/099u+u4ggmeO0MW6oJsOJYM8LZR8Oy9pijafzh1Cva/mbtohVO7V yAcZrpTQM7V9SBUNKf4FpJfu7tS7rfAu9zJr5CfjcIq5ZIVptfqyNEmpgBhj3IguX9n1eU1I7Z90S Iq1E7pLZnKRZQX9WLCq6TnscHiB2S7tvJzLw/fGukF34Hf3nEtJaw2EdyFhVGU6smHLcOJsoskxpi 24eRBC1w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm4Eo-00000006xUU-175g; Thu, 05 Sep 2024 04:36:54 +0000 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wj-00000006tWb-136L for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:18:14 +0000 Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3df02c407c4so180283b6e.1 for ; 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=lists.infradead.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=SeUQ1JW1atrCQuD3IqZvBp5ncZL0kuwkpUnzl5b2Lfr3NTz9H3zY2xL+lYhOd1HDWo kExLv4mtOPN60n3AUBRHkcydhaHBCJb6hRAztl9W96wDefT8AjLXenWICZmeiuZbfs4c F0PY7jzKFWRa4E/KmaEbEipPGQTspaLSQxrq2iZfQFz5YB2r5LtSEooalU0bIIXQF7Fi R+7/kCN7vrnAFhNcPjppvTC8MWuRRCDLpoWoPmk/iMdQ5BM2W4v0uowtmBD5pmfnyOpA AtYz1iXdXtDJkxwOAwbU7G5MhrOv9B8V4/b43MKRORRdog1NNGWM3iwJL46RvlfY0lei 5Acg== 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=XzDw4EIBLSMkNlEo4A7G50cyQgxw0rcNRWWn3Sd0otlmMaRUfsx1tQCE5s4cp3Fc27 aNIRrFAQXrjglII9gXB9X/WPYRJ3y2X18Bgv9U/HA8fSWrh9MbJER5GE5/Mc2EX6Qnk2 FJzWLIncxwKCrrsMhGdc03hZUHeCRluUeG1l3oDH5csqzm/d+47KlSFxM/U7ENMG3l2O AoTzGCesF1DjZRnvNNI4xSjRABzPJ8F08V/84+HhxxnqxD+rONDYAuxVW4zL33vrjrhM SH4XfiYSMHs+pAszmexrzwnQGuamGcol1kjo/fMxJGn4Cq/JbfO+pMUYCc0BW417XfTw +C3w== X-Forwarded-Encrypted: i=1; AJvYcCUVJOqyrKfU2DWLPXQiS4onl0Hf1f5yn1kOatgMx+subboHOcTKh87uo/WjCDI3LGh6EcCBJOKOmdPRVZFB8fcV@lists.infradead.org X-Gm-Message-State: AOJu0YyQOfP29sHsc4pcMEmR3oq0XCFUWbFq9DudCd4c5+0w/fEQENaE tOR8jpS1bLxgei+jF8xMMgiqGxt4F3JzcfQwM5T6AxtnAAzOpktd 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211813_317818_5F054FA9 X-CRM114-Status: GOOD ( 20.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791739 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 41807CD4F20 for ; Thu, 5 Sep 2024 04:38:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=j96TxrzClXBkhwjMJZl6JNr36upS20Gw21hZhz5UEQc=; b=NHQ0T5qiZsuR4Xv2utmGfEZyiO MgjeHygSl9HoMk9fpCbIe+1ee7seCD72Hop5mzEvIezVBd5KSRl19QAHa+ikeSUYw6TluUCs341Gn i6Ah8teGG3Tk6LqOQ5VrTI+Vg749kSHkTkGH8JMzd4h0zvthWAepCyw9SzVWKsP6nnPgh9Irr0ejI bWhEXBSx92vdYrBzgNy0VnszRW24+T+TN9GG78tNi6bLvzQ5YsP/9Fp7MS76t/qNbmJ3Ay/KjAjGl O2XUOVZnFQCZWVPlciwZX/zbqzj8SuXm81fzEAyqUzXE99g49RXyAHHiKpmBUDGjPqvpjjw06fT8K CE7TPwIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm4Fi-00000006xbX-0cRR; Thu, 05 Sep 2024 04:37:50 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wk-00000006tXD-2brR for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:18:16 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-714187df604so933199b3a.1 for ; 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=lists.infradead.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=hqKUN/fgtWPQttJ5x1vV47ElqKCPvBHchNBOxIj7EYUC2OE5K/aZFp0avaKvdbFWk1 D3I6kttDiUpKIB8TZDz0cvCz7N8EZpvdF0bBHL6cu2BV+vfqc10/vWdtNLUHcADFxfev BInvPSyGbE963aVZgvNJsVunw9ed4anEOCX/6FublFnm6mDcFDHmSo2X3Mlv0JjOUT81 N8tJp+q+Q9g33t+UmbR4vm9WEbJL8PZIqZ0/7mQ9jc7o1VVZ3R54rK9AfxulI7zwcP5C 4zVY4b4L3ROY1gIZFdLfIFmXFJdRlLfVYmN0pDr9QblNcxt3piIL4OhA790l9cfABBH0 01vA== 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=R7Vx7i+oRLq1gb1bHFhJMD1Z2lnkW/4u/4X73nh0lcPyHAHPf8CmW8nZLo9HhsN/9m Jv6pWFYSx9nAHjI4UdmauA8fbaKxL6BAO52IteUBc7jUYTF43w0extoqxqoBA9V1u1Km e/5g5liHgjwRHzfv38wY2BvuIjJVyuiG+Kx4qKUsvQm1/lAK9/9cEsZ7eY90pcbpQi/F H2TgEPHWhKjVdwlwJMvrGPsiakzDETO/29cHwUof8SuWjD+6d4MwQ+JFzU2vTw3lOgqU KkfidiRtImsU/2pX3vkdOYj0YMz8SxvkbhD6T+DGQ2JNRGmpczzogUj98/WFom7zFzvY l9Uw== X-Forwarded-Encrypted: i=1; AJvYcCUriu7AXJYSRrjqcVRjw03Ulq8LRKEIAOyS4+DQ7eIrKCBG8n1TAqpzBsWuTTI4Ve7gafHuybhwhTYe7Ns7Zgkg@lists.infradead.org X-Gm-Message-State: AOJu0YxGpcXRriNp8R/jQgUffFnVd2R5DzFlNSvuMxmhqn9CpG8KOCud t8WOojtFv1lby8nPIUZWKUb0hgtankHZqcT3Wwq3e6AZ32D3Okli5PPreQ== 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211814_763291_8FB411FB X-CRM114-Status: GOOD ( 16.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791740 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E9742CD4F50 for ; Thu, 5 Sep 2024 04:38:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nD0rUo0iZKECgz1mfgeWlPajiiX/VTTiXfcH67/TdcA=; b=jBlom1MXkvMSQd+AFpzCWQuFsG Y8YBJvz4tuxkwFLO9sMe2yH9fmH2ggXlo8QZEzlTq1ccf4IdUUNPGNkN4tNvMHX3bcgP6aG/f3I0q jGaFlcVDH66Dhj9s3r0ENrrLdmyP7O0sahP0F4sqW1ENefufo7sR8fGcAhQ0s0vOx4lytaehUbrXG SltetXQGdNt/jsU+aGJ2ggwhb4uH9RFYqkQHBvFcZAsuSgR2Jy9fpFFGhVoj/Oxu4zIQECyHoxWqB FTqh3Bhw5gAjv1LSuR+J9dfRjYhz54cwGRywmCdB6nBsAHGr3Orum3EAWgmHN8bNhw/m/tloW3/ke HDuXsh4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm4Gc-00000006xio-2JD5; Thu, 05 Sep 2024 04:38:46 +0000 Received: from mail-ot1-x335.google.com ([2607:f8b0:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wl-00000006tXZ-3qr4 for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:18:17 +0000 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-710ac7041c8so270061a34.1 for ; 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=lists.infradead.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=PABOWAsPGobefFkVl0iOyLph2S902KjlzOuly1zTbLDhcMMwiYdMGs5uJFgODSGJwy JMVXdRKQSyOUbIM7axa1rTyj7tvfPCVCJVNT/tmyc4mDrZ10mcw77RzyY7zsrwv41dKe BkysvjKgc8gtlb9ojhBdjLT0SvtKMKyjdKEX2Wh+nAlete/OTj+kdNuVb1KziBKV02p6 9R7oqahITX/aNS71IFtA5Exw8PTpHkh85jURvqnuIVgSBUcPrgSpoyJ7IXdGV4KBgvkf pP8MPS2fU3Aho6MphPBAs7emoLbl4qPF9b/uYA3J5/Xer+Avn015OZeVkFvsjU9UrZ3m +ncg== 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=YD6AEpOY3fhWaxVCPHg9JGTT18EfOXMwGf2FYnDAOYDGs54pEYNgazI3lnlIqX7+Dx 0kHrUbQz4z340yxMYmUVMVgaPRov+SoDR8ztBH8AMaLhoho370FPlKO8zi38kf4R8UHx 69XAhasJNK09wtHG1F8YlT43uKpjMuPoDvOqEJEk5hxJON+ivLnQipQvIN0pBlDX1a+m t2/5eI/a7b5L4tgI22F30KuLzDldMzyRnmtR84JE33ANnBgz9FTQog/G5cfSv9tOWiUx b250UYG9Robb+s8rTnDEmmFCoW1okxGWcctgkDT8wRmGwFje59VpmqCBiXSzJg8KWkUr dg+w== X-Forwarded-Encrypted: i=1; AJvYcCXgVBtIQv4LfCpcIaqfttJtgocoY25q5NrTEiVagEXnOS64oFYwZ8BXjr8jUjhkkjt3+VtxoPQkL/dTU3QlPf4k@lists.infradead.org X-Gm-Message-State: AOJu0YzNOlkcrw5zVjON78E5QntEAG6plpRjpy5xrDyW8aRvZ/LPEYZj vMK2Vrc/EOhs7X9C2GNlIdfVtOLDfDkgYPEegudW2XG6Hbyog3eO+VJUGw== 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211815_976591_26692386 X-CRM114-Status: GOOD ( 13.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791741 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 074E7CD4F50 for ; Thu, 5 Sep 2024 04:39:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=xz2erQSg3sDaQU8qTCUlHXjZi76BIHFsta/dILnpIUo=; b=GiXSGELQ50Eh2JxyWbOIHLC/8Z SzIwR1WEmuRK1CPOwScMoefvg1n2/LIdUe+Nc7pV/8NU1HLUVF2/qvH+S6OdqERMDoqlpS+9alfmT scneT4pMlpvzdnmxD0VPW+1ebO5mkU/BZwLoRziB8qNebr83Em7ra85spEryZEbn9KGiFFDb+iGl9 2onfN1kTSYCPzTMp0M4epdtMoBN0xDPvfcdpoGSeNkurYSBHYKDJAkj354ZqsHyJlm8SDw/jFtBhE Kr5Sh4I5G1uT03dJ/NbDZwgDFlWJA703GEDuwrndMTLDObAgeOlIbjFBQYB1eDYOx5MKe4Ea4MO2Q 58c3zKKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm4HX-00000006xpM-0EvD; Thu, 05 Sep 2024 04:39:43 +0000 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wm-00000006tXy-30qI for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:18:17 +0000 Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-709339c91f9so242733a34.0 for ; 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=lists.infradead.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=LC2H2DtSv/3vkSyc9RykLoYlWyXoH4B0Mp7SGU3kzURq7clrhomI+7+uv8IhewCmH+ PYeHBmUQvZZwH12ZqqGWUz7noE4h9Cn9uj7M0PHKCeoRqlf3+AuWRud2pm54Hul8PfOn m+kwHjqFVg35f230hr55zhQ9WzhJjJv80jxaVOxxozNYS5BU8kChrS8zu2IJSvbyD4B+ 1078LMWbkERKsXxEgrSMBWerdhh43DngFHTgQJ2IZesnVZYBjwFxGiUI/MoxNWGHbSjW l70kuS1eYNIuHE/5km3ljp586EijitQ2eTRnVAmFmpXQN+Ub77zLSQRa2L89QT802fsv 4jyg== 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=bqB9d24bQE+GkMrBSKt5i49Yo1bD3euFzZfkg7Vk53cY/xbD44ojNUHlevq623McNJ eb4j+RLxRHQ40+ydHdhYh4HfMGqXDsz3WSsSmcZW5djRd9/pyOYFVu6defNgRyhjSxiC qMAJ/BBF9aS0GRETraw3Zc5psWxsUduKTjshbdVAE0bTTDukTQhMLxXUNjxj8uchsR+e 6gKwtr/BL6uo39wIc2B/VTD9tfGcU9QcaT3LoKezK6zLzKYXpPfoZHQdyoFqjfYngW4v sVIfl3JyCvSNulYL1aI4zGdRmac8JVYAMknZPWjDYfoF4oPJ2gd2pMde9GahBGV/2vWN vcuQ== X-Forwarded-Encrypted: i=1; AJvYcCXPYVBAeKOI0yF6Puk2ldvtn8NpNL0D43Ugw04t4KDZ9v3VABHIfl7vjIJd1Wmu0FEbZIHhxkYf1OWkGwphrm40@lists.infradead.org X-Gm-Message-State: AOJu0Yysy8Qz1VEL5X+elsKOrxoUNOu0C1dVoaFtbRCcp3brDdn9AzP3 QKBzShKAShOCempDFQJa2OxVxQYy/Ddxl6kJEUeMLL4/IgeBCE6M 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211816_776258_38F49C2E X-CRM114-Status: GOOD ( 13.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791742 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A86EDCD4F50 for ; Thu, 5 Sep 2024 04:40:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=KAMMGFcdQQuvbLfMZ1RSK1JtSdD6Ii5X8caybj72d5Y=; b=ZzD07UeySyicbmMsoH+taw3AWZ Eb9wQ0wkqcZP8l9/vl6AZ78RmIytiXLEQRdNDg60XBSEBE6aaPDsgvxWEc/5ghARjtiFDVHMcMf7w r18T/7isIa01jIjQ/VWEbrDYWTxp45LlIXaInZh497JmSPW4HRb2qBKewhHWq0PcdLVMauk29QsmN 4kkW8JdoD4L/LkzH7mvnCga8+p3YqPhNkzw8+O6M3fsKvqjBEdjWlbfKe9hj2pEaagZqsbzAOdsAl cnzgs547JoV4/B8Hj3zYglRj8zme40aOnFfvrAMfzedc7ssjOzdfKz7dY1GjiLkM0rwXD5mEHF6aG YSSNPTTQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm4IR-00000006xxF-0sHW; Thu, 05 Sep 2024 04:40:39 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wo-00000006tYe-2HFK for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:18:19 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-7176212de5cso259884b3a.0 for ; Wed, 04 Sep 2024 21:18:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509897; x=1726114697; darn=lists.infradead.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=Z5/EBfHlOSBCzH4S1dTRUmlDRDTB8uBpszawvwQrwuIbnTwXPsHTUqZI0sLjrhP4VA mO2uXQeRmg4Wo0JEzcRRtwdF7C4JszJ8QQ7KfkcvybEJJXo6Q7Zkq/Uxk+zwQtH8hPvO l91VxX/sbdxOoMV7cyRUZA2FnFBp5wtLt3fCfpD7ntFBCFdVwMxl4gdGDtDBRAXldHxg 2nD05bSdS0kLrTRo4P7MqaBK3u0PHlosZtSbwosBSlmhZ05QItnCklhhAquY3JkP7043 thgoeUH40RhBIv6zReUnV5IjDPsGEdKRw2m/lwnUkUjcdGyi8sAhoLY3Mwa6pXVKJnkP GgMw== 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=HGikR1VXtwwkph/9sNmzzP6Iu9BUPp6F0f9/b8T4G+4GrzXpC2RADlX0OoZ9QsNioM Gw8hGIiKbEhqXAm2mTTd+k8CBnglgdsqhELuL0Z6gxBnlvE0UlIkvPHIQbyQaASPqkN1 jTTdoVEACpTuI0QVSZidOZDhM1BfZFYMCDM0mZSgl9W07b5YXBAJgjfqvG91f5hkkScP W+h0uJOFVmQvoF6WEDaGsQBSnN06bbCkltwpg/5j5bFx9ySP5iYbuhHkF999pG6QGZrU zOBqJeIvVOPGthuC4TLAS7sjZNmUft4MBKI5wXGBVqeq75rCjHo5AcK4CvzkfwxihaKN LEaQ== X-Forwarded-Encrypted: i=1; AJvYcCWOpL7OkQWApgcjosVngOAITjm1WLEiRDfHzlb4AjBfOB9NLbbqX1n9lu8+Tq06UOS6WQnVW4LMvgeAkM9sOkh9@lists.infradead.org X-Gm-Message-State: AOJu0YwEXCluIszV3H9yWU5DGm9UrnvvIYyx5yPmmrcHLjKFb2s7qapq vDnDeZTvKixZY0law79Tv7lXp7wo2tOnLHkRoz8OOsEI3AEzMa7c 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211818_607619_4BB89FE9 X-CRM114-Status: GOOD ( 18.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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: 13791743 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E4B43CD4F50 for ; Thu, 5 Sep 2024 04:41:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zDTJQsChimFHLTafhuTJQvaUHnDbeVQTacrVKRN5TeI=; b=RH7Ufi1hK+SX+CDhQhwZtqVKYl om1MFPghaJN2qa7GO8643C3JR88uiOlYwBH3AJs/FnlcQIdG7iI1kO5JO7Ahrtx5fgP7wjvkFSqR8 W0WQu46UUNdhiTT8wX/knQQCYToyAAxxLAwnM0HPicuWwY1NG5l3JP36LZpbo8A4N6kb/mYmnj0QM 1ix0Z0Pw8BN3DywoMRDLZKFA/EtnuZR3Wobu+WsSoO3dMuzX/ry94C0sZQZGn0O3qiNOKNdzxDO44 Zp/7M4rXm5Qot8xf1oGKg2U89SuBWH4H7Ln7YDkmr+zJyAtxPBDxnsEfeE1BmhNTSfKDtCuxWgl2U mqIldezQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm4JL-00000006y4U-2RXA; Thu, 05 Sep 2024 04:41:35 +0000 Received: from mail-oo1-xc31.google.com ([2607:f8b0:4864:20::c31]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wp-00000006tZ1-3vMg for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:18:21 +0000 Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-5e19b16568cso113008eaf.3 for ; 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=lists.infradead.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=Bgq0DJRSx6mrirSs2INll7BeL5tzxGHO4kaBf6Sda36ctCw4oWWZnzazXj7oGAibDc qf8Iph/SYFvKvk46+Ki5Kp587gp2V8DxAYnC3pUzLf8oUBWPX5UXKnE/4A2kYx0jhnYH +iF7afMWojAqDJtO/Kzx4losVb8b0DQiYekLsv8r0q+9cl39svBql56X8AqPtpywzbDH hRuC46ON+LkziD+6vhZsJnh5k0Mk2gKPMS9bHWlSNWYIhujGbmCXUKVyZWa9hyF6u9kG K0qRtuxTqT+CcJE8Vf2tzvDAb0s0lz4ZCyNMrFgUexIMlIXu3KNjxtXYYAv2y+q3LY4Y cBsg== 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=AePO17Aau2stvDGDwC4GbXnBdbrM9aFAHpRX2yIquSZLU9sORJk9KWSddidmcZI22b dGch+a3tzIydx5XIEGsL9j0yW2OlK0ZyCsXCPa/SATEyUN8trGYyAIy9yZXiRVeB/qLV DoSSz9DWwMMQu/147op14AzYJfV4aACbiQNw7UO1f38Agl7WgKjwCDq3KfCL7DIgGo+e oxGzNbD7dLFP1gQD+Prgf8qez8/tKnjK0f+dQIrt7NkCby1q/gnLpJFzmxOn/HrB2r+m Zoa4IRimWNfVUsPIEovMJ5NwgYzAmEWgp5lWiSZ6Q1Vex8LY4Lrzg/T3WKHDc8LDcm7A cTCQ== X-Forwarded-Encrypted: i=1; AJvYcCW+1TS+BmzReoYtzWrqT+nOQVhvvxZaCevw8u26TugIGjKQVQC2Jhmi6/lzZj24dmnKhPiLajPaWq/gdkcc6lTd@lists.infradead.org X-Gm-Message-State: AOJu0Yz0rwWn5vD+Mwhw9P0bGwJhfw48tbFRvkEgL0y7BUyI5mwChapU gGWcKhU397JaQ8el4nd6/UKeZ/Xn6MZRYQtmoAzA48wDD99rLf5gBl31DQ== 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_211819_999374_7139EE72 X-CRM114-Status: GOOD ( 13.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; } /**