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