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)