From mboxrd@z Thu Jan 1 00:00:00 1970 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 669FFC5320E for ; Sun, 25 Aug 2024 05:23:09 +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=MF5E3W/jIicHOW4h7MeNLzhN752Za5ehXWfMuqIr3TQ=; b=k08JdPDo/028Pafudxx0JDxYQn nGeCxhHRKMhz6CQew1o7vXHhfchPosbOkPeY98ZFTlZrIHVsGs6SDplMO11dekbtTKyywpPHOEAs6 IvLnEqElUt5o5JdsgblHk4OeYcaHXXeTxAaIXbvjc/sYdfNxqSfE4gNFg3ST8sM+zcxsTLz/Wm3hS rl9qJrlcKAImiVAERFGb7JuIzF6XrVQ6kWCN+EC1VvQoJo+vGtoqEeCJyktA+TMl+UrrcQHEwsYH4 r6GYVtE2kE/+nEDx7RnyRlRmwwF3rLHhkrN48bJo+gZRBuzPZh8zzPxP8wV4EQkn2Jn5jw+UGfQOD 7iqBh/Rg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5iL-00000003fVa-1cmb; Sun, 25 Aug 2024 05:22:57 +0000 Received: from mail-il1-x136.google.com ([2607:f8b0:4864:20::136]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5cN-00000003df6-3UCD for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:16:49 +0000 Received: by mail-il1-x136.google.com with SMTP id e9e14a558f8ab-39d34be8b6dso13314115ab.0 for ; Sat, 24 Aug 2024 22:16:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563007; x=1725167807; 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=MF5E3W/jIicHOW4h7MeNLzhN752Za5ehXWfMuqIr3TQ=; b=k1OhKvbLKzkk7E3rF20leBDR3fHOF6YBYbjSSKXaDptEPhQv4DsBj3ULjYnYEqethm DBIW1+1mawo4KMHLxFhEzICxZIMJeZWgc4Mx8MmSNZTZPSqzmicbHSorj8OuYdddU4dw UkzOaB8r5JZAC6WKWhK6MC/4cSiQ2h/YA1QLZdpGIAt7YHbktNkE7RncGmJgPWzuTgJZ FS5FLzymK9I4paNmg7QNOamOtFWQfEnS1S9oT50yJNSJcnVVq/BkBJdoKicJVW7HgPgN EDy7dSSw8dpWjqK7AXlV395XC9l0Hf+GfMb5v27MQ30ASL+50hmNt0AZi3NM0oEIdg+s wBlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563007; x=1725167807; 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=MF5E3W/jIicHOW4h7MeNLzhN752Za5ehXWfMuqIr3TQ=; b=VQ/5W7Xx2ugfrrrsr08xPlKZOS+h5pJEDJVzumX+LD/Lkkjzr+6VnZGTOis8vZnmPZ HyGDfc/ApAnYLWlKACKK1Cc0KWMuXJ6Pd0cWbfjQvcIWZR69hUARPtNTl1mztdA3t7IW wiWMgLcJm4TzPv18qsXla9Uy0gWznfSSTGsOJFeSIvi9WItS0dhX/xs9keOCIp1N3FLj JnfV+5CeXfVri8GSCvX8nV009tkEMgYmgCRY1SNyzHFqNh5mPs2U8Gzu/IHBSqAF7B1K NekGud68Vw1bImwK1YDMFhI4iEDpd0uVI7pFNCtm8VfCf8C+R1n3KCpinOkq0qWC6dGf ZQFw== X-Forwarded-Encrypted: i=1; AJvYcCW/ybotspu+pVz0Wpd1OUXWzU4X5iVRd/rhulexGHd6vL4X1m93f1pKAqrk1vdN8m0GJ/Wcbb3xVkIsZsuowVKq@lists.infradead.org X-Gm-Message-State: AOJu0Yxo4xosknBcu0uZt8cl4mj9aS4MyXqbWe0+wawJUqadCyAS7+6W +ywUf/HrfjDEI3+35GB+TPSzYZ53OY6/B9OPkP7L/DL/VJEIcGjN X-Google-Smtp-Source: AGHT+IHXAs6GceADDzLZ7I3Pij++Fm3NQFnIWhk4AJZxUkQIX9t9GW0NO9mJDGotB52VqJS/4yMQyA== X-Received: by 2002:a05:6e02:5a3:b0:39d:300f:e8ff with SMTP id e9e14a558f8ab-39e3c975b22mr65481975ab.6.1724563006637; Sat, 24 Aug 2024 22:16:46 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:46 -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 06/17] Input: imx_keypad - use guard notation when acquiring mutex Date: Sat, 24 Aug 2024 22:16:10 -0700 Message-ID: <20240825051627.2848495-7-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 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240824_221647_891256_9AAE0C5F X-CRM114-Status: GOOD ( 15.66 ) 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/imx_keypad.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/input/keyboard/imx_keypad.c b/drivers/input/keyboard/imx_keypad.c index e15a93619e82..b92268ddfd84 100644 --- a/drivers/input/keyboard/imx_keypad.c +++ b/drivers/input/keyboard/imx_keypad.c @@ -521,13 +521,11 @@ static int __maybe_unused imx_kbd_noirq_suspend(struct device *dev) struct input_dev *input_dev = kbd->input_dev; unsigned short reg_val = readw(kbd->mmio_base + KPSR); - /* imx kbd can wake up system even clock is disabled */ - mutex_lock(&input_dev->mutex); - - if (input_device_enabled(input_dev)) - clk_disable_unprepare(kbd->clk); - - mutex_unlock(&input_dev->mutex); + scoped_guard(mutex, &input_dev->mutex) { + /* imx kbd can wake up system even clock is disabled */ + if (input_device_enabled(input_dev)) + clk_disable_unprepare(kbd->clk); + } if (device_may_wakeup(&pdev->dev)) { if (reg_val & KBD_STAT_KPKD) @@ -547,23 +545,20 @@ static int __maybe_unused imx_kbd_noirq_resume(struct device *dev) struct platform_device *pdev = to_platform_device(dev); struct imx_keypad *kbd = platform_get_drvdata(pdev); struct input_dev *input_dev = kbd->input_dev; - int ret = 0; + int error; if (device_may_wakeup(&pdev->dev)) disable_irq_wake(kbd->irq); - mutex_lock(&input_dev->mutex); + guard(mutex)(&input_dev->mutex); if (input_device_enabled(input_dev)) { - ret = clk_prepare_enable(kbd->clk); - if (ret) - goto err_clk; + error = clk_prepare_enable(kbd->clk); + if (error) + return error; } -err_clk: - mutex_unlock(&input_dev->mutex); - - return ret; + return 0; } static const struct dev_pm_ops imx_kbd_pm_ops = { -- 2.46.0.295.g3b9ea8a38a-goog