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