From patchwork Sun Aug 25 05:16:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776686 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 1027EC5320E for ; Sun, 25 Aug 2024 05:27: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=1NGHCiulzh9gyI30mSR8DfFWb1nfUXRaAntbygPzyeI=; b=1CitRJlokAYemiLSGZ3kznse9S Y4KbVc8ovwQ2xsCGU+WnLP8iIH8dvJxI/vIpzDrQvguk1Tfx0O6NjQEAOnfsKNw8ZUeynJNbuql6i B0z1i9RzdO8JMXgDcPHkeVToZf0rxAkrw56P66ifMGYDevoE7DLAyQPN2/6KE0U0jNLgA03ADtLR3 HZEEvD/dg0Oij4XY+2RolOa++gd63FmKm6d3ja/LUcOfr/Z8d7cE2FTsGMWrNmR3gWJzcdzy2mVmm jf79wrJdOtAdkqzXWa91oqQNkdqtcmDa5gXJMtkW65ET60ZG4+dPWM4YhUa6zrV5Bt/yivtTAsA5u eaz7gIcQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5mL-00000003gDZ-0GSn; Sun, 25 Aug 2024 05:27:05 +0000 Received: from mail-oa1-x2c.google.com ([2001:4860:4864:20::2c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5ca-00000003dmb-22Cc for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:17:02 +0000 Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-2703967b10cso2397342fac.0 for ; Sat, 24 Aug 2024 22:17:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563020; x=1725167820; 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=1NGHCiulzh9gyI30mSR8DfFWb1nfUXRaAntbygPzyeI=; b=MeBy6gm0Zy1iJycfA5+gqxX47eGKXcbC3r1EpqDYG58KjNMLRl/wPr4mMeHsibhDQH WorbOVE2pFCEd908uLiFPGVfTS+DIxpu2cZeluhSZlGOLIX77AJjk4pVUfTPOiV+GbH0 QPL8EaXhsNsPfuL/DIIymsbSDgrniFB0GjLVMYbwHwiy7wIlwKeOw1VSM1mhbJZGXl6C Rm/g68yVfFfoxeflMLgnu+nQFogZA7/+CxN0NsRv5xusULs71SIJ4Lm3WFeS7NbQKsnF ViKZPWLBaKSytNvLMTf4Y9yS0IPvxs65v/08LritfOh56nPKeWBi0zAWfkrvXUY4Sntz Kpcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563020; x=1725167820; 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=1NGHCiulzh9gyI30mSR8DfFWb1nfUXRaAntbygPzyeI=; b=XE+tXGG8dNTnuSXyFgaR+ipvSdYc66UO/LxEz3qoNy1smo/YPssgsNnvFUnIBOhmg5 tCo8YHOKySk8xi3OXdYfeCYoqv4cr0m73zXCcOUT/bgUAJoEId3Yz4Lg6Gi23/xQw/tb rdRirWDa4lJ1tFAKMXJpWFQpQ+9T7NV1c6FfmiRVZ6mISvpkggC15lBu+vwvJ4tIbfpT fVg9jbWAQG9VmIUEsuAhLTz3TfZBH4BUraNPP9up8CfRRdgLl2JxX++atg6ahMY2TvnR 4fnXYAVSV1OO1/mkpT+4rtwODyHUnGYFwbgPqR/BGSSNlwhy175zOeEnRwgJZawtW7Pz B4yg== X-Forwarded-Encrypted: i=1; AJvYcCU4ShnIATIcbKSdAFTGr+fnHrkj77xoIH/Dtt7MIMV4ybBeq743ORKnqdnUiNQtcQ1PqHO8Zds6RdRXMijw23Kc@lists.infradead.org X-Gm-Message-State: AOJu0YxxWrZg92W/8F6hf1w156glFbP7JrH+Q5mMUa6xEyzdibIp3W20 xVtRtQpuW9VrC6Vj7yR4U4oCKIrBUqnNoSL725v7lyGEaxTmwRHo X-Google-Smtp-Source: AGHT+IEQYgbglgd8I3qc/P81ZQRecoGdRxN5BkyvLrd2/7rQzAPvHkH9Capk9njsg6VV/xAvADHbUA== X-Received: by 2002:a05:6871:2284:b0:270:b0a:cc0d with SMTP id 586e51a60fabf-273e64321f9mr7289887fac.10.1724563019693; Sat, 24 Aug 2024 22:16:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:59 -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 16/17] Input: st-keyscan - use guard notation when acquiring mutex Date: Sat, 24 Aug 2024 22:16:20 -0700 Message-ID: <20240825051627.2848495-17-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_221700_573760_81C119DA X-CRM114-Status: GOOD ( 13.39 ) 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/st-keyscan.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/input/keyboard/st-keyscan.c b/drivers/input/keyboard/st-keyscan.c index 0d27324af809..e53ef4c670e4 100644 --- a/drivers/input/keyboard/st-keyscan.c +++ b/drivers/input/keyboard/st-keyscan.c @@ -216,14 +216,13 @@ static int keyscan_suspend(struct device *dev) struct st_keyscan *keypad = platform_get_drvdata(pdev); struct input_dev *input = keypad->input_dev; - mutex_lock(&input->mutex); + guard(mutex)(&input->mutex); if (device_may_wakeup(dev)) enable_irq_wake(keypad->irq); else if (input_device_enabled(input)) keyscan_stop(keypad); - mutex_unlock(&input->mutex); return 0; } @@ -232,17 +231,19 @@ static int keyscan_resume(struct device *dev) struct platform_device *pdev = to_platform_device(dev); struct st_keyscan *keypad = platform_get_drvdata(pdev); struct input_dev *input = keypad->input_dev; - int retval = 0; + int error; - mutex_lock(&input->mutex); + guard(mutex)(&input->mutex); - if (device_may_wakeup(dev)) + if (device_may_wakeup(dev)) { disable_irq_wake(keypad->irq); - else if (input_device_enabled(input)) - retval = keyscan_start(keypad); + } else if (input_device_enabled(input)) { + error = keyscan_start(keypad); + if (error) + return error; + } - mutex_unlock(&input->mutex); - return retval; + return 0; } static DEFINE_SIMPLE_DEV_PM_OPS(keyscan_dev_pm_ops,