From patchwork Sun Aug 25 05:16:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776693 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 72F1FC5321E for ; Sun, 25 Aug 2024 05:30:17 +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=cyPqTHyh07puR7bU3JACy63C0BspLgz3ChuDMwPsOL4=; b=tj+6io/NiFQXsc92wV6t1dBxWt kgD30Sz2q9Yiq7CqCLsmIfHSeS7LmsiCYiN8Xn+LUpQ/SX3y5N3yQELjQbTi2SzL6LqF+SKiSqflJ gwqrME5M0TvjJmOLA0JblrdWOqqGxLMtcbJzdKJIyySh7YDszr4HBNn/Dr7AQVO/bJ48jDtSD5bU1 gGa9jj3/M5n0dMmP8g/qfSmDHBOheM8Rzfc/Yr6GWS66f8WIzGEzY7BEe3U0PLDn2u/dqr3nP6gfo azoktBvF4RJ8jjvXp2lfY6QcvixvXgzQ5utnRjpcvWA3MEcT+ZXWIKGQEpMpI8P/f24wyP20SGs6R F5VF/9xA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5pH-00000003h3a-2nce; Sun, 25 Aug 2024 05:30:07 +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 1si5cT-00000003dhs-0MCU for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:16:54 +0000 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-7093705c708so3522721a34.1 for ; Sat, 24 Aug 2024 22:16:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563012; x=1725167812; 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=cyPqTHyh07puR7bU3JACy63C0BspLgz3ChuDMwPsOL4=; b=T35iml61GknshUEOT6PlIlvULg+orBcIUVOYzrLTD7QOB7gjR+gONlEaLdq/nzpXp2 yKol3XvrhZblKqF8iv0QvN2UrWM56CiNkkkC8tP8JBXwEKaWEbFg4Z49XT3W4Kch6SpJ ls+/tmOgmLqaFrOH2PYcx5w1xxa6tVWz9OsV9Mq41NraLyyycV9Ac8zhXUZ3+cAP8HVo FFs2T2GfH5e7zhuLuPL7fYq0MZxU6GXfPFF9mjju+3XQFd+ivGTV9fBVL1T1bGy+Eh7R eV50taH159Z0BcOduoQ9ij/bnk6zrRg77OsNy7gCNA7oDHQsGgGVYEo8kA5zMDPN8SM4 KQ1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563012; x=1725167812; 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=cyPqTHyh07puR7bU3JACy63C0BspLgz3ChuDMwPsOL4=; b=vENOe9zLr0ztSRKUV6YQ+hDnSjA80xEVgkHKFZjR8O8DbthZDkH7pFHKFhwWLnL4gz 8VzwNcVG4xfEWSymDBJ9uJ4Gc/1qQX1dh6/YF1MbFRTIqnJaqrQpVgC7ylbn8RaHj/QK OCpzenM+2IouDj7uVD9PQpwGUhNJjewqsx9Fp38GwrhxWbfebIQ9NB+3Csx1YRSDYaFf pkaA0u134DP48cp111CwYFOK0nPOml0E2iSJJyhDnxPD226nEq0WUZzCd5XI5Iez6m1W zglmTwoH1lBAWq6W02Ra+h+bUfcQIOpx8l8ZxuNDmq+eI16gNY5M3b3JdtCB2v/Ls6cK +DTg== X-Forwarded-Encrypted: i=1; AJvYcCUGci4iPWe46CNbvSplko+hQiZzMUB4hBIRb03A5iVPlsakDoT/W1GBe3vcRSchq6fiFw8p0V1AeI4HRndQuINI@lists.infradead.org X-Gm-Message-State: AOJu0Yzo2g/fjXTU3j7RWvv3LjYLv9o9jnwFN66FRuWceR04+MaKB0vz plKJ6GvmlTwQvEkvAA7T6QgMnKy/1G23w57dwQ2V62N1fWqN/9EV X-Google-Smtp-Source: AGHT+IElTjsj7Q4fdjXuCiV15fwaclHOkI2Ai1DHHC2EwetOtIQNk0UHrxm09mtsUN+F1sUh9V3o8w== X-Received: by 2002:a05:6830:658c:b0:708:b32f:ade5 with SMTP id 46e09a7af769-70e0ec90cacmr8581080a34.32.1724563011839; Sat, 24 Aug 2024 22:16:51 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:66dc:ce07:b7cc:51ea]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7cd9ad55a94sm5622442a12.57.2024.08.24.22.16.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:51 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Shawn Guo , Sascha Hauer , Fabio Estevam , Laxman Dewangan , Thierry Reding , Hans de Goede , Tony Lindgren , Jeff LaBundy , linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org Subject: [PATCH 10/17] Input: lpc32xx-keys - use guard notation when acquiring mutex Date: Sat, 24 Aug 2024 22:16:14 -0700 Message-ID: <20240825051627.2848495-11-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog In-Reply-To: <20240825051627.2848495-1-dmitry.torokhov@gmail.com> References: <20240825051627.2848495-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-20240824_221653_150566_3431EFF6 X-CRM114-Status: GOOD ( 13.34 ) 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 This 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/keyboard/lpc32xx-keys.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/input/keyboard/lpc32xx-keys.c b/drivers/input/keyboard/lpc32xx-keys.c index 423035be86fb..2392e7ec3b19 100644 --- a/drivers/input/keyboard/lpc32xx-keys.c +++ b/drivers/input/keyboard/lpc32xx-keys.c @@ -262,7 +262,7 @@ static int lpc32xx_kscan_suspend(struct device *dev) struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev); struct input_dev *input = kscandat->input; - mutex_lock(&input->mutex); + guard(mutex)(&input->mutex); if (input_device_enabled(input)) { /* Clear IRQ and disable clock */ @@ -270,7 +270,6 @@ static int lpc32xx_kscan_suspend(struct device *dev) clk_disable_unprepare(kscandat->clk); } - mutex_unlock(&input->mutex); return 0; } @@ -279,19 +278,20 @@ static int lpc32xx_kscan_resume(struct device *dev) struct platform_device *pdev = to_platform_device(dev); struct lpc32xx_kscan_drv *kscandat = platform_get_drvdata(pdev); struct input_dev *input = kscandat->input; - int retval = 0; + int error; - mutex_lock(&input->mutex); + guard(mutex)(&input->mutex); if (input_device_enabled(input)) { /* Enable clock and clear IRQ */ - retval = clk_prepare_enable(kscandat->clk); - if (retval == 0) - writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base)); + error = clk_prepare_enable(kscandat->clk); + if (error) + return error; + + writel(1, LPC32XX_KS_IRQ(kscandat->kscan_base)); } - mutex_unlock(&input->mutex); - return retval; + return 0; } static DEFINE_SIMPLE_DEV_PM_OPS(lpc32xx_kscan_pm_ops, lpc32xx_kscan_suspend,