From patchwork Thu Sep 5 04:17:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13791729 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 B41ECCD4F50 for ; Thu, 5 Sep 2024 04:32:14 +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=p3btFCntery0ta6nV0jjerZVdR60/Gk5jQnmpE6Mqz8=; b=GYWbe8sH9cHOYnN7/DqO+Lyc6q ZoY31jjJqZbLmJtv3/MiL+rW2qCC/dZ4iubC7FbJlZ0Xw3omAJcBTFlzbx5K5f67k9n6IkqSA1XhC syVhQpJyFP8ZvmqgDw4QzVbeUCg9F+Kg2wuJOSJfAufp91sPi1bYHLFxsh8HVbGjPi1CXiUlmSyC6 lMVTYHFhA3rTBjiZ9uVNs9Z/vG6SA2hsqx6KG401jjIm6B9JbxO/oxbUewDLODwQoh58lkOy6/Axr 3JoH0xr4HKwdFoQRqtmoVi8qTVKXPkzE/Ifnl/rxXhEfVJBwWw71w0xuI5jpC2qIrQDY1+45Ux5Hg Ha4r5HHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm4A8-00000006wJi-1XlL; Thu, 05 Sep 2024 04:32:04 +0000 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sm3wb-00000006tSY-3FJm for linux-arm-kernel@lists.infradead.org; Thu, 05 Sep 2024 04:18:07 +0000 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-70f645a30dcso287383a34.3 for ; Wed, 04 Sep 2024 21:18:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725509884; x=1726114684; 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=p3btFCntery0ta6nV0jjerZVdR60/Gk5jQnmpE6Mqz8=; b=hzWdCOF5361Dbwnu3EnOQPcqePbnKXQUQ5a9yZRvKZHcCecnM7gC/4+n3elkGNRrnI SstUVnRf75yqWJE+wHDjPPsWjjU5GcJgdsuTne7hiitf0MY3jT/47czCVQ7jxVbSIC2G Jhzof4HEi2QlQLh/JL8ydSEkkSDZCfP5nQ+LdB5ENcK8bO2riNjXPc6+LroE+ynHDwqQ 8yjJ6A8WPRXTyBvcYN3dpBDj7xnQf3E8FC+fQCPMcP0QutmyCl48pler327az8fZlc82 wuzMevnsgawIdwHQqK54fzFrlZl06swYTC1PSCqdENG3lx3MsuPGLz3UbtiAVI6fIFXJ uxiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725509884; x=1726114684; 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=p3btFCntery0ta6nV0jjerZVdR60/Gk5jQnmpE6Mqz8=; b=HcRSURhWFNd9inKOfjRC1dKYCU1pv9HY/gKZbNQTsZZaOO528SUOsqPJTvGDrXQSTQ uSMOPbo976O+TcCQxoha/+wbW3TRkFly/XSZfINjDN5XYgyNxacAb4inxL7YVaeV8YV7 Nis6IhSE1I+CblJmtf90qUlIeYK8TUfsLeTKd68ylXWviOYnI1+NiLXSNf91zu+Te8IP wW29NLpBP8mEUjdv+SmbbFDXSOkIsZGZYJXPo7EHWHPfA+KDyKGzRbnZUdNv/PZt/4Q2 9n67QxP2M7av4DwJEf7sNjzE9yjvqMQFTw14dyAng/S6xk8b0gchKf+C/gv5cYyPEQGU CzbA== X-Forwarded-Encrypted: i=1; AJvYcCU/wIordQyDBOWVLl2TjgDXdtxqN24OxGyyIQCiyL3Uf8cL9mISB310E1jaCnBsh4FlQ4zP3lTrJ7IfFlWj8Gvl@lists.infradead.org X-Gm-Message-State: AOJu0YzZ00YcZ0WS+yDmM5uJtcqOZ0UdDbm3BHk3pTz8c/NLnMLq332c fdeB4AXmjbwJYgp0ip/U7APG9eeesjhwtkJIvE4leoEpbGKQ4JWq X-Google-Smtp-Source: AGHT+IFL+aSox2tT+ROcWimEdBXmALGnwGMrd8DuDbiXAmTxOicOS1tEjKJAt+iSvmj/V84cB+BBpg== X-Received: by 2002:a05:6830:349b:b0:709:4793:8757 with SMTP id 46e09a7af769-710af68fc2fmr8717442a34.2.1725509884434; Wed, 04 Sep 2024 21:18:04 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:18:04 -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 14/24] Input: ps2-gpio - use guard notation when acquiring mutex Date: Wed, 4 Sep 2024 21:17:19 -0700 Message-ID: <20240905041732.2034348-15-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_211805_892764_D7DD071B 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 mutexes are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/serio/ps2-gpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/input/serio/ps2-gpio.c b/drivers/input/serio/ps2-gpio.c index 0c8b390b8b4f..c9c382989e55 100644 --- a/drivers/input/serio/ps2-gpio.c +++ b/drivers/input/serio/ps2-gpio.c @@ -133,12 +133,12 @@ static int ps2_gpio_write(struct serio *serio, unsigned char val) int ret = 0; if (in_task()) { - mutex_lock(&drvdata->tx.mutex); + guard(mutex)(&drvdata->tx.mutex); + __ps2_gpio_write(serio, val); if (!wait_for_completion_timeout(&drvdata->tx.complete, msecs_to_jiffies(10000))) ret = SERIO_TIMEOUT; - mutex_unlock(&drvdata->tx.mutex); } else { __ps2_gpio_write(serio, val); }