From patchwork Thu Sep 5 04:17:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791707 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 15B3ACD4F56 for ; Thu, 5 Sep 2024 04:20:52 +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=YscGpXPa0igYUdPp8o8oV5VkpUTxqWDGqD7B4LMXPvo=; b=36PGnHKGeHQdykgozy9wQTUwO+ RLcFIz39QzGD67X02viH+gdHRLik4gtNt27MsP9bF/94K7PQfuai5FzlARZUZbHpPOKsQ737x3BRW o54YM6k9xNLpk0HAzudASYgOinzgoJLt8sxfGOPBvYXryu8ZYs3e91iC1qNXrerWyGccdFoOreNQw nY8CrXFKvQAnVLfWGut1X6vKSs+X+DDaLB67oRiBPvWwEg48ob8Y4D9YaBoUbu+HZvJOZwLlpLWOX YCX7TvsBLANlYfhrZ9AJLzCnnYnO5c3yArvcNM+BR5/nYFKK4dp2QRhtc7DlA5zGMHXVWHscqV1KD UUgjM19w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3z7-00000006uDq-1AJW; Thu, 05 Sep 2024 04:20:41 +0000 Received: from mail-yb1-xb32.google.com ([2607:f8b0:4864:20::b32]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wK-00000006tLQ-2TQF for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:17:49 +0000 Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-e1a7d43a226so419984276.3 for ; Wed, 04 Sep 2024 21:17:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509867; x=1726114667; 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=YscGpXPa0igYUdPp8o8oV5VkpUTxqWDGqD7B4LMXPvo=; b=Cfc/fxXprqzbbj++nYoMpWl5msCDIO2olIaiJpWssGY82i/zU+4o0XMaJKTj68X+ju EOrbRespnA5zt0CURkvl3o6FRQe28L00wcgr3Kyl022Wh3Fl3N8gO2BwsHBdWzEeTcz/ Y1HsNrmGyfBhBStQJ3sbM0YSLRbKacBnr4+7K7NHsPD8aQWIM3tS0nakxPGq4/z1nACh LYrygMqfTU4jmlTg1IBQ+68DwSxoLxSaOZn7rSvtGQYxzHz2Cu2hfrvmeaVs37aHIkNR RbLoKWoolNYSk9HsN1L++eYB1avrKWK743aNn21FO7AG5SgCwLUNF4B6SsV/bDru1qsB Mj5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509867; x=1726114667; 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=YscGpXPa0igYUdPp8o8oV5VkpUTxqWDGqD7B4LMXPvo=; b=TVPJlsYy5GDHe0rbjbLCGgUqQsTuXXRg0FbmfySOJI/eGS2zvpsuUVeWVn0i0hk5dq ye4UMdtRNe0tXsLgQQUBjiiRpd7LWQSrPEPYgmC0zgmbUbg3f4PURk2hqxWIVM/uGFMF V1Ridm7ylUdrckJ/BdW5JlPvqlcnFP04qRVQWj7EORCP8LT3PUyzFpcK2n5erCu7+OtI ikWIuTJrBS/nUixkh64YEwFZazMo9lO5Gkhs4U8b5k7l/0qO+E6vv1OfxhyCB+6tI3/Q rV0duoejThHxsO5GElgdxc15MJeKTRIKJYrgaXlmYn0/YAWwP0qMgopKajrYvdYreisd erUw== X-Forwarded-Encrypted: i=1; AJvYcCUBz9gaxP6a6vosA0g2R3uTqSi/ytqSOHgFiDcJjWjM4or4DtWUC8uGFM+LaQ8fzlFq2xP11jnJIVgcrUeYJJ6O@lists.infradead.org X-Gm-Message-State: AOJu0Yw8uaBVETVEkh992i+iytbfP9bNiu18PlVCwo2CqvaVMgxd8eWm WRW0fkHXMasxihDPBX3XlDVus2QUZnHxfs30m3oWpzod9gnfG9pP X-Google-Smtp-Source: AGHT+IG2n4QttKo2Kk6OwZ6xAkRc+KBcDbR2JtYsfVRI0Ayw5MYcw6SGH0iMQHCRmBjRsLLZm2riig== X-Received: by 2002:a05:6902:1106:b0:e13:d834:604f with SMTP id 3f1490d57ef6-e1a7a3cf59emr21411841276.50.1725509866951; Wed, 04 Sep 2024 21:17:46 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:17:45 -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 02/24] Input: libps2 - use guard notation when temporarily pausing serio ports Date: Wed, 4 Sep 2024 21:17:07 -0700 Message-ID: <20240905041732.2034348-3-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_211748_650557_5DC9C298 X-CRM114-Status: GOOD ( 12.92 ) 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 serio ports are resumed in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/libps2.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/input/serio/libps2.c b/drivers/input/serio/libps2.c index 6d78a1fe00c1..c22ea532276e 100644 --- a/drivers/input/serio/libps2.c +++ b/drivers/input/serio/libps2.c @@ -108,13 +108,11 @@ int ps2_sendbyte(struct ps2dev *ps2dev, u8 byte, unsigned int timeout) { int retval; - serio_pause_rx(ps2dev->serio); + guard(serio_pause_rx)(ps2dev->serio); retval = ps2_do_sendbyte(ps2dev, byte, timeout, 1); dev_dbg(&ps2dev->serio->dev, "%02x - %x\n", byte, ps2dev->nak); - serio_continue_rx(ps2dev->serio); - return retval; } EXPORT_SYMBOL(ps2_sendbyte); @@ -162,10 +160,10 @@ void ps2_drain(struct ps2dev *ps2dev, size_t maxbytes, unsigned int timeout) ps2_begin_command(ps2dev); - serio_pause_rx(ps2dev->serio); - ps2dev->flags = PS2_FLAG_CMD; - ps2dev->cmdcnt = maxbytes; - serio_continue_rx(ps2dev->serio); + scoped_guard(serio_pause_rx, ps2dev->serio) { + ps2dev->flags = PS2_FLAG_CMD; + ps2dev->cmdcnt = maxbytes; + } wait_event_timeout(ps2dev->wait, !(ps2dev->flags & PS2_FLAG_CMD), @@ -224,9 +222,9 @@ static int ps2_adjust_timeout(struct ps2dev *ps2dev, * use alternative probe to detect it. */ if (ps2dev->cmdbuf[1] == 0xaa) { - serio_pause_rx(ps2dev->serio); - ps2dev->flags = 0; - serio_continue_rx(ps2dev->serio); + scoped_guard(serio_pause_rx, ps2dev->serio) + ps2dev->flags = 0; + timeout = 0; } @@ -235,9 +233,9 @@ static int ps2_adjust_timeout(struct ps2dev *ps2dev, * won't be 2nd byte of ID response. */ if (!ps2_is_keyboard_id(ps2dev->cmdbuf[1])) { - serio_pause_rx(ps2dev->serio); - ps2dev->flags = ps2dev->cmdcnt = 0; - serio_continue_rx(ps2dev->serio); + scoped_guard(serio_pause_rx, ps2dev->serio) + ps2dev->flags = ps2dev->cmdcnt = 0; + timeout = 0; } break; @@ -283,6 +281,10 @@ int __ps2_command(struct ps2dev *ps2dev, u8 *param, unsigned int command) memcpy(send_param, param, send); + /* + * Not using guard notation because we need to break critical + * section below while waiting for the response. + */ serio_pause_rx(ps2dev->serio); ps2dev->cmdcnt = receive;