From patchwork Sun Aug 25 05:16:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776676 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 E7D4CC5321E for ; Sun, 25 Aug 2024 05:19:18 +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=ShO+HgvM3GmU9GyOB1yPa+S5A01U1lb+gXxQbTtxVpc=; b=LaHniRIlMdBhEJYw6f74zJvmD+ AHvDjrGqQqediToZQLNdFLU7B5V6P7nC3OPSRTL9dLtZ1/Bxio4erc3GvipKKvLqGQ6ojhEzkkQ1F o9UvVYaRhd848m4m3ssSX6Sv71G7Nd4d+Tao/CO66kmexkfmdxe/VeTx1NvreLvx68tbe8bCHknDo DH95Kx+fzy7y4jhu9No+QhEkIMbjv8WbaB8kPR7GXhNwQWeLlJk+JRxa2xsf6/zMTWm64ZkJ+k1Oy CBkXdcbtSBOIcBDQe4yP3R+cIIVPPJm7gomGPQzpd3+5gi8MbDq/0cB3oOYJSNun4/gDBB5cYyY1j zMK8GPYA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5ef-00000003eVj-0lVW; Sun, 25 Aug 2024 05:19:09 +0000 Received: from mail-oa1-x34.google.com ([2001:4860:4864:20::34]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5cH-00000003db7-3aiU for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:16:44 +0000 Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-268eec6c7c1so2367252fac.3 for ; Sat, 24 Aug 2024 22:16:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563000; x=1725167800; 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=ShO+HgvM3GmU9GyOB1yPa+S5A01U1lb+gXxQbTtxVpc=; b=F0vBRkwSLTKGM21UC1owUE3/HNCAaXSY62wr/Z6i99lmReZ9gNYMaLXTwETOcoDo9c H7lHUgyGHhR1uDuyXdo8ZVZ7AaUjLoCezrsS17Sk/0s4bSWc5E4RrakF88/btC6Sb55H PFzPcJeQ3P4/BuA+0Wbf8icAfAbc6x9OnvxQP8TAqsJ/jVyJeCZp86qyq2WcXPLFvjdx mgOkL8KLs5pTLrxOKTK41qQ3r1AWmEz/j8P6r/ygV1Y2d6SHhHxS4sshVKbkDMU3hOfm BRMSAmhJevJWN9oNv9SUOTKRi1lWWhxXQdTY88hAjYByyBOt+9p/GPTsgrGtckr5N5Vq AeaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563000; x=1725167800; 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=ShO+HgvM3GmU9GyOB1yPa+S5A01U1lb+gXxQbTtxVpc=; b=ALFiO5ZougNySLxKNEBr/ywxYO+D5sXmf4C74XVbR6dqQ2TU3e6LpGtsjFjkA8a6XL u4yDk6n0hhEaxfCY47zWS4kn23H1av5WafS4nzrlrX0Tq/JiJW+dGQY7LVvVOTHmHOhV pVQJZN5qQk79aE7LXbDOL5kZaBui1qrg2sx6BVLB0O198xLq2pgfibhIsczz7+63IqsM JXtb1W8/Cwbi2szNDVrOX8xKG7Ypf9/w7lGoEwO5nJGh2lVzNgTOaO3oGzm3qA57+HP2 k1n4nt3lmdoG0c3bhpc7xqZCfRa4Gibp1/qPzqRxjHslNsIYvHEqEpJRMxxBOYeuhZ3h Yk9Q== X-Forwarded-Encrypted: i=1; AJvYcCWy5OJrMuWeDKbgBF37D44TPjw+DQcEMnyz/ru55SWaTeWKzaw4OmppWfAuJFfdetEnAIUNZbBAGJb0QpnW6wrB@lists.infradead.org X-Gm-Message-State: AOJu0Yz0m1iKGu4Rwd7KiVSu1skUxmH/7XagDpYvmYH5tYHx7ywxPSfl fz84vvB9Ff+w1nY905/O3ru9CyvdTSWhwIVJiCjzE8OME/8ycyNd X-Google-Smtp-Source: AGHT+IEZFPpCzZoomgKLJTyaudR7j9NCS6uaxVcYk6aQIQGxzRythkb2raMKaNsay8DSDOaUBbZJmA== X-Received: by 2002:a05:6870:1608:b0:270:440a:a40e with SMTP id 586e51a60fabf-273e67260d0mr8083459fac.46.1724563000175; Sat, 24 Aug 2024 22:16:40 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:39 -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 01/17] Input: adp5589-keys - use guard notation when acquiring mutex Date: Sat, 24 Aug 2024 22:16:05 -0700 Message-ID: <20240825051627.2848495-2-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_221641_920645_13CDC93F X-CRM114-Status: GOOD ( 12.04 ) 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/adp5589-keys.c | 39 +++++++++++++-------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/drivers/input/keyboard/adp5589-keys.c b/drivers/input/keyboard/adp5589-keys.c index 8996e00cd63a..735d96b056d4 100644 --- a/drivers/input/keyboard/adp5589-keys.c +++ b/drivers/input/keyboard/adp5589-keys.c @@ -404,7 +404,7 @@ static void adp5589_gpio_set_value(struct gpio_chip *chip, unsigned int bank = kpad->var->bank(kpad->gpiomap[off]); unsigned int bit = kpad->var->bit(kpad->gpiomap[off]); - mutex_lock(&kpad->gpio_lock); + guard(mutex)(&kpad->gpio_lock); if (val) kpad->dat_out[bank] |= bit; @@ -413,8 +413,6 @@ static void adp5589_gpio_set_value(struct gpio_chip *chip, adp5589_write(kpad->client, kpad->var->reg(ADP5589_GPO_DATA_OUT_A) + bank, kpad->dat_out[bank]); - - mutex_unlock(&kpad->gpio_lock); } static int adp5589_gpio_direction_input(struct gpio_chip *chip, unsigned off) @@ -422,18 +420,13 @@ static int adp5589_gpio_direction_input(struct gpio_chip *chip, unsigned off) struct adp5589_kpad *kpad = gpiochip_get_data(chip); unsigned int bank = kpad->var->bank(kpad->gpiomap[off]); unsigned int bit = kpad->var->bit(kpad->gpiomap[off]); - int ret; - mutex_lock(&kpad->gpio_lock); + guard(mutex)(&kpad->gpio_lock); kpad->dir[bank] &= ~bit; - ret = adp5589_write(kpad->client, - kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank, - kpad->dir[bank]); - - mutex_unlock(&kpad->gpio_lock); - - return ret; + return adp5589_write(kpad->client, + kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank, + kpad->dir[bank]); } static int adp5589_gpio_direction_output(struct gpio_chip *chip, @@ -442,9 +435,9 @@ static int adp5589_gpio_direction_output(struct gpio_chip *chip, struct adp5589_kpad *kpad = gpiochip_get_data(chip); unsigned int bank = kpad->var->bank(kpad->gpiomap[off]); unsigned int bit = kpad->var->bit(kpad->gpiomap[off]); - int ret; + int error; - mutex_lock(&kpad->gpio_lock); + guard(mutex)(&kpad->gpio_lock); kpad->dir[bank] |= bit; @@ -453,15 +446,19 @@ static int adp5589_gpio_direction_output(struct gpio_chip *chip, else kpad->dat_out[bank] &= ~bit; - ret = adp5589_write(kpad->client, kpad->var->reg(ADP5589_GPO_DATA_OUT_A) - + bank, kpad->dat_out[bank]); - ret |= adp5589_write(kpad->client, - kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank, - kpad->dir[bank]); + error = adp5589_write(kpad->client, + kpad->var->reg(ADP5589_GPO_DATA_OUT_A) + bank, + kpad->dat_out[bank]); + if (error) + return error; - mutex_unlock(&kpad->gpio_lock); + error = adp5589_write(kpad->client, + kpad->var->reg(ADP5589_GPIO_DIRECTION_A) + bank, + kpad->dir[bank]); + if (error) + return error; - return ret; + return 0; } static int adp5589_build_gpiomap(struct adp5589_kpad *kpad,