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,