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; } /**