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, From patchwork Sun Aug 25 05:16:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776677 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 DC747C5321E for ; Sun, 25 Aug 2024 05:20:06 +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=v03nlMt8wt97ucP9MgPsI2XvI1FXNf/NrpeS/5IiYv0=; b=Z2PXUXu21MCdGD+YweD3LDb2QZ HCWn3OV54W3oFfCyYvgDumTHkD+EOr2FOfbc1RfNTj/TnAkDs8ZZYFFqtVBaS4/u4sPOwEaGQPq8B wO0KHkXvP3GhgBO5duKMAHolg8P15mv9BJC/H4i41Z0tnDtrP6WxBSkHhpaUbToIbjg93BBkKnYQp plTQZLdk1cFUotbCNqxljkua3JbhhmRLi5gMznbecCY5X3q8wWIEjsNUMztaYlOtFKALL8TSzUlOo kQUT7qJ10sFDJwou/vYFji+JM2Qnwc8lrms5tnbVhdq2OvFUWeyFEqH5dhHRDsPkRsme0nwSaR2lT zuVCi15w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5fP-00000003ek8-0kAb; Sun, 25 Aug 2024 05:19:55 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5cI-00000003dbw-2rfj for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:16:44 +0000 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-714263cb074so2302364b3a.1 for ; Sat, 24 Aug 2024 22:16:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563002; x=1725167802; 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=v03nlMt8wt97ucP9MgPsI2XvI1FXNf/NrpeS/5IiYv0=; b=BkgJCbIKK7yu0IHaYCY1YqVw7u06suOZV+fwsFT+KbJwWD6hwNrQnnB6q81EE7OP4F jf8MNAjWn2BEQY/KPf4UDNL0DX715EBzIVj8N9hP0kFkShq55F5kYwcEpKXLhLRhFyCD dBmt6O+eQiQeggtm6fgczanhK/V3pRE2G1eThycHZJYZIwrsyroX1JZjyz2K8lHFgDZ/ xoCf6Iaq78SbINT5dDlQnytNOcrWtVTkwGjO+9B1S50MHN8Q3mcFyig0iO0DAi4vNZzo 3jPYSM9YlMdzthDZHFhGKwUHdRng6LNW5lgkD+pwuVtlJnG/sc49qC4CeCzWCyA73tEF vRcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563002; x=1725167802; 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=v03nlMt8wt97ucP9MgPsI2XvI1FXNf/NrpeS/5IiYv0=; b=dg8h6tLMRKoBkVQ5LaTYfmLzai76eNPED2gCXs0ASqz76x4Vgh6mNqRxjgQwEQOsOa TpXeQI7OxE86NfGy+lxZogrKQRLgGzqCBFV6U7/xWG0JIc0St01Uy5zNNnKP4Rgnb5yZ psX47TXk/l5ptTnWPSyImFd4h1it3ihk98OLCm3y6RKQN59L8J3d7jd4AWsX98l6ixXF cBBmdf07VNAAHDUoHPnFDv6WNYSbO1xLOmQQ2KBoVWm6h8n3LyvUyziDMNpbGpNmvudE xRxJj+OpD1dahNE7OgKCbCM7y58jBewDBkWngc5cN/c7eVmg6sTh8NzVw2jaj7ZmrxcB bIdQ== X-Forwarded-Encrypted: i=1; AJvYcCV2D1JyixtJidvTXSbXg+5JEv3C+GjdansP7OmnB2ALlcX/4KC8BjVtUl8xQTKld1e+DkxjLQpIzoTIGRoUafJR@lists.infradead.org X-Gm-Message-State: AOJu0YxGqpBdrCshGJxeQsJsS0cUICeBDLRywsyzaZUXGVguejZFelI1 cGOe35cbQIK19HvlrJ8eLkj0WvSvG8J7cf6SvyYZ4x9cOIbP+1IY X-Google-Smtp-Source: AGHT+IF7QoHmrLV6kSFTTdk+PD8n2j4jO61+JgdZXKp0HB/dxjAB/YizqF4tzxEjr27TgbIwya03LQ== X-Received: by 2002:a05:6a00:1990:b0:710:7efe:a870 with SMTP id d2e1a72fcca58-71445dfe700mr6501782b3a.19.1724563001466; Sat, 24 Aug 2024 22:16:41 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:41 -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 02/17] Input: applespi - use guard notation when acquiring spinlock Date: Sat, 24 Aug 2024 22:16:06 -0700 Message-ID: <20240825051627.2848495-3-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_221642_747658_48742B34 X-CRM114-Status: GOOD ( 14.02 ) 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 locks are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/applespi.c | 72 ++++++++----------------------- 1 file changed, 18 insertions(+), 54 deletions(-) diff --git a/drivers/input/keyboard/applespi.c b/drivers/input/keyboard/applespi.c index cf25177b4830..501ce8154786 100644 --- a/drivers/input/keyboard/applespi.c +++ b/drivers/input/keyboard/applespi.c @@ -717,9 +717,7 @@ static int applespi_send_cmd_msg(struct applespi_data *applespi); static void applespi_msg_complete(struct applespi_data *applespi, bool is_write_msg, bool is_read_compl) { - unsigned long flags; - - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); + guard(spinlock_irqsave)(&applespi->cmd_msg_lock); if (is_read_compl) applespi->read_active = false; @@ -733,8 +731,6 @@ static void applespi_msg_complete(struct applespi_data *applespi, applespi->cmd_msg_queued = 0; applespi_send_cmd_msg(applespi); } - - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); } static void applespi_async_write_complete(void *context) @@ -888,33 +884,22 @@ static int applespi_send_cmd_msg(struct applespi_data *applespi) static void applespi_init(struct applespi_data *applespi, bool is_resume) { - unsigned long flags; - - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); + guard(spinlock_irqsave)(&applespi->cmd_msg_lock); if (is_resume) applespi->want_mt_init_cmd = true; else applespi->want_tp_info_cmd = true; applespi_send_cmd_msg(applespi); - - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); } static int applespi_set_capsl_led(struct applespi_data *applespi, bool capslock_on) { - unsigned long flags; - int sts; - - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); + guard(spinlock_irqsave)(&applespi->cmd_msg_lock); applespi->want_cl_led_on = capslock_on; - sts = applespi_send_cmd_msg(applespi); - - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); - - return sts; + return applespi_send_cmd_msg(applespi); } static void applespi_set_bl_level(struct led_classdev *led_cdev, @@ -922,9 +907,8 @@ static void applespi_set_bl_level(struct led_classdev *led_cdev, { struct applespi_data *applespi = container_of(led_cdev, struct applespi_data, backlight_info); - unsigned long flags; - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); + guard(spinlock_irqsave)(&applespi->cmd_msg_lock); if (value == 0) { applespi->want_bl_level = value; @@ -940,8 +924,6 @@ static void applespi_set_bl_level(struct led_classdev *led_cdev, } applespi_send_cmd_msg(applespi); - - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); } static int applespi_event(struct input_dev *dev, unsigned int type, @@ -1428,9 +1410,7 @@ static void applespi_got_data(struct applespi_data *applespi) /* process packet header */ if (!applespi_verify_crc(applespi, applespi->rx_buffer, APPLESPI_PACKET_SIZE)) { - unsigned long flags; - - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); + guard(spinlock_irqsave)(&applespi->cmd_msg_lock); if (applespi->drain) { applespi->read_active = false; @@ -1439,8 +1419,6 @@ static void applespi_got_data(struct applespi_data *applespi) wake_up_all(&applespi->drain_complete); } - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); - return; } @@ -1573,11 +1551,10 @@ static u32 applespi_notify(acpi_handle gpe_device, u32 gpe, void *context) { struct applespi_data *applespi = context; int sts; - unsigned long flags; trace_applespi_irq_received(ET_RD_IRQ, PT_READ); - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); + guard(spinlock_irqsave)(&applespi->cmd_msg_lock); if (!applespi->suspended) { sts = applespi_async(applespi, &applespi->rd_m, @@ -1590,8 +1567,6 @@ static u32 applespi_notify(acpi_handle gpe_device, u32 gpe, void *context) applespi->read_active = true; } - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); - return ACPI_INTERRUPT_HANDLED; } @@ -1819,29 +1794,21 @@ static int applespi_probe(struct spi_device *spi) static void applespi_drain_writes(struct applespi_data *applespi) { - unsigned long flags; - - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); + guard(spinlock_irqsave)(&applespi->cmd_msg_lock); applespi->drain = true; wait_event_lock_irq(applespi->drain_complete, !applespi->write_active, applespi->cmd_msg_lock); - - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); } static void applespi_drain_reads(struct applespi_data *applespi) { - unsigned long flags; - - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); + guard(spinlock_irqsave)(&applespi->cmd_msg_lock); wait_event_lock_irq(applespi->drain_complete, !applespi->read_active, applespi->cmd_msg_lock); applespi->suspended = true; - - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); } static void applespi_remove(struct spi_device *spi) @@ -1908,21 +1875,18 @@ static int applespi_resume(struct device *dev) struct spi_device *spi = to_spi_device(dev); struct applespi_data *applespi = spi_get_drvdata(spi); acpi_status acpi_sts; - unsigned long flags; /* ensure our flags and state reflect a newly resumed device */ - spin_lock_irqsave(&applespi->cmd_msg_lock, flags); - - applespi->drain = false; - applespi->have_cl_led_on = false; - applespi->have_bl_level = 0; - applespi->cmd_msg_queued = 0; - applespi->read_active = false; - applespi->write_active = false; - - applespi->suspended = false; + scoped_guard(spinlock_irqsave, &applespi->cmd_msg_lock) { + applespi->drain = false; + applespi->have_cl_led_on = false; + applespi->have_bl_level = 0; + applespi->cmd_msg_queued = 0; + applespi->read_active = false; + applespi->write_active = false; - spin_unlock_irqrestore(&applespi->cmd_msg_lock, flags); + applespi->suspended = false; + } /* switch on the SPI interface */ applespi_enable_spi(applespi); From patchwork Sun Aug 25 05:16:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776678 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 25DF3C5321E for ; Sun, 25 Aug 2024 05:20:50 +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=G5PKJ4DF5X1qlJhF7gsux7p32n0IqTVXA5WgHVkgHUQ=; b=Nuu2qCN+uxen+T8MJloJPimNj1 Jr16hHvqxzTyGoBsCV5PfcfAcKuzsu/Br5TamAE4I3MaMOMdZ4TbzoH+tmSJRl+fKGgciMn1HOTOH xQQquSJo1swuSQbGlID6xl6ZsrlIhq1HInkkYA9zn31Ea7ljjm9uHwvmSnwN/jxFGoanNOVeus/I0 uswKYQ/cyO6hTPbnhcXG9PZRnox4y+4OIYXOJSzKTdIahO6ENsDQXPN5EHf6+aMRgXxzBC6U+HnP3 luej7f/Sxtrk2WUY+lJmVLjx8wGOkJXKedPs0wYvTA1DVSn4pXlFGriaE1P0ky+VQdNwMbg7hL66/ Qi2GN40w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5g9-00000003f1W-0qOt; Sun, 25 Aug 2024 05:20:41 +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 1si5cJ-00000003dcS-2eVr for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:16:45 +0000 Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-27012aa4a74so2181346fac.0 for ; Sat, 24 Aug 2024 22:16:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563003; x=1725167803; 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=G5PKJ4DF5X1qlJhF7gsux7p32n0IqTVXA5WgHVkgHUQ=; b=Dtl370YX7SvjwCgdhM+6PefFzqmTEMINxvGi5zLkDestOKMvJYB5BCe+5KanSKp+KU HWNRAgHr5UVqsetx5u4XF8hi8dUrzcjmBGUP0nYWuIXrnjogUVZANQBYlVHABcStKte4 4Bob73laxvTdGgO16L3IBIT8kFjGj7b4pq8TYoHIJTcj89ck7dqyFDG+Izv8MD2+JbhT 5YopT00qLH0VMozVKBqRDoCMEBaE7iUsblKRqqj2G0HhAQFdsmr1NjpGb2zl67/RCEXX hmKSL3bXgof/XJHN5lSDByvyyoMbnjVZbwWcqL1vjgzJcvV1y6lSFBLDGxn5EL0dCELT U+tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563003; x=1725167803; 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=G5PKJ4DF5X1qlJhF7gsux7p32n0IqTVXA5WgHVkgHUQ=; b=aiCi+OlsVBmxh0lWn6Z/XB8LnVdEpDM8AegAayQWGkWEkoO97DYDJeOjVmqS3799L3 nyDt27Tt7o2sHqxXrkDeqgQ51+GJnUPXmDw4DzU4OTzztYwVF+6du1ZhFeY6t1ypGSjW /Q9C0FkBUosdPtfmCTBBw6amSOr8XSYTZeq1PI5dfEvRHIYZSlrxupgvqyd58ODYwH7Y 6ZmEc4/J6ik8h+SjLhkEaQRC5/O/DIUvyHIp6k4vuJor/tLpwqoQcF7mOfQtLQOYli6h YNUNuXYlLa98vf8J/x5dOB/2/tOpBtbZiSG6iW3H2IEkFhsElgK19Hdrkar9mSwEc2Ir 3p7g== X-Forwarded-Encrypted: i=1; AJvYcCWKpvvHGP1if/Wm4F3b2JbS5uD3PLSS64wsBp65xfBWOD/H5rOHmHCrAwjItIOLu0YBUH4VdIPWtUDUWlIYp7L9@lists.infradead.org X-Gm-Message-State: AOJu0YxqdvbK9Cg7b3YvG5oUc9/xHzvQY7997joQof6QiWZ92p7bStGb GvtOyliSCouXjw86zq2GkvE8er5Wpa8AnsitXCK29BTMm3pMUG3O X-Google-Smtp-Source: AGHT+IG8p40c6YWUkGfP1Ref/yI6506RwxbxXGHkuvgXNPmHrDm0NWWnw5t8czN5o3U7acylmdbbqg== X-Received: by 2002:a05:6870:e310:b0:261:113c:1507 with SMTP id 586e51a60fabf-273e6472931mr7072687fac.20.1724563002770; Sat, 24 Aug 2024 22:16:42 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:42 -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 03/17] Input: atkbd - use guard notation when acquiring mutex Date: Sat, 24 Aug 2024 22:16:07 -0700 Message-ID: <20240825051627.2848495-4-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_221643_741573_AA89571E X-CRM114-Status: GOOD ( 14.76 ) 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 Reviewed-by: Hans de Goede --- drivers/input/keyboard/atkbd.c | 37 ++++++++++++++-------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c index f4f2078cf501..5855d4fc6e6a 100644 --- a/drivers/input/keyboard/atkbd.c +++ b/drivers/input/keyboard/atkbd.c @@ -639,7 +639,7 @@ static void atkbd_event_work(struct work_struct *work) { struct atkbd *atkbd = container_of(work, struct atkbd, event_work.work); - mutex_lock(&atkbd->mutex); + guard(mutex)(&atkbd->mutex); if (!atkbd->enabled) { /* @@ -657,8 +657,6 @@ static void atkbd_event_work(struct work_struct *work) if (test_and_clear_bit(ATKBD_REP_EVENT_BIT, &atkbd->event_mask)) atkbd_set_repeat_rate(atkbd); } - - mutex_unlock(&atkbd->mutex); } /* @@ -1361,7 +1359,7 @@ static int atkbd_reconnect(struct serio *serio) { struct atkbd *atkbd = atkbd_from_serio(serio); struct serio_driver *drv = serio->drv; - int retval = -1; + int error; if (!atkbd || !drv) { dev_dbg(&serio->dev, @@ -1369,16 +1367,17 @@ static int atkbd_reconnect(struct serio *serio) return -1; } - mutex_lock(&atkbd->mutex); + guard(mutex)(&atkbd->mutex); atkbd_disable(atkbd); if (atkbd->write) { - if (atkbd_probe(atkbd)) - goto out; + error = atkbd_probe(atkbd); + if (error) + return error; if (atkbd->set != atkbd_select_set(atkbd, atkbd->set, atkbd->extra)) - goto out; + return -EIO; /* * Restore LED state and repeat rate. While input core @@ -1404,11 +1403,7 @@ static int atkbd_reconnect(struct serio *serio) if (atkbd->write) atkbd_activate(atkbd); - retval = 0; - - out: - mutex_unlock(&atkbd->mutex); - return retval; + return 0; } static const struct serio_device_id atkbd_serio_ids[] = { @@ -1465,17 +1460,15 @@ static ssize_t atkbd_attr_set_helper(struct device *dev, const char *buf, size_t struct atkbd *atkbd = atkbd_from_serio(serio); int retval; - retval = mutex_lock_interruptible(&atkbd->mutex); - if (retval) - return retval; + scoped_guard(mutex_intr, &atkbd->mutex) { + atkbd_disable(atkbd); + retval = handler(atkbd, buf, count); + atkbd_enable(atkbd); - atkbd_disable(atkbd); - retval = handler(atkbd, buf, count); - atkbd_enable(atkbd); - - mutex_unlock(&atkbd->mutex); + return retval; + } - return retval; + return -EINTR; } static ssize_t atkbd_show_extra(struct atkbd *atkbd, char *buf) From patchwork Sun Aug 25 05:16:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776679 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 5877CC5321E for ; Sun, 25 Aug 2024 05:21:38 +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=H7WxrWJ62hQ2vKyvroZvAzkaBumF7Y0KoLKrYpStuCE=; b=yNaXtzLceRLRd81Nvm7oCmvEiD 9vrKo86JorHhUi25Y/2ObNlq3M4iQMbKlWvNtBxn88jzWo0fQs8NO4McF2hwqA+fgaIJTuHcvzLZF n9rTrMllpvlX52n6vKS9wN2OoFsPsxaeCaelWuzhQZYSenh8SF/QR6KDp4xafGxoRjIzzw48trS8h VLgdjU8NhkVmvMvVbyKfpm6FbqHCtA+EMCDx5QYL8fPryuHXmSUz/Dx9n2Ei+EYIOa65sXQqDZ6wC mXr5G8jKzrQNLZ7hP+WRfrMm6/VsnzDF2hSzOtw7Wfq2Wpa8P7pdvuDNIYgHiNM+2dvhs6oOPs/mp rUDGanvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5gt-00000003fFM-15A6; Sun, 25 Aug 2024 05:21:27 +0000 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5cL-00000003dds-2OVL for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:16:47 +0000 Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-7094468d392so2671526a34.0 for ; Sat, 24 Aug 2024 22:16:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563004; x=1725167804; 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=H7WxrWJ62hQ2vKyvroZvAzkaBumF7Y0KoLKrYpStuCE=; b=fVuE86pF+pvkuwHa5/R7TXoC2OjMMvxQZIYDhHipVI/fF/M8qqLx5/XGnwTJtoCti1 ayl3fKjaxZKBiqT1BQSPTyJ/dJGAKuR4lWeOurhIeAzchl5iS3rBaTBcTbAev9vTZrS+ MJCWk/Dk0xA2Y1HtnN4+m+3KzV0Xc84PvKGYbQuE2/OfQYK9HA7BlQQoC9c3Co0GXgXj lobe+FUKHSGMXFUftZJawXOnLquUq0jwdMSn2dDihDwt88SQX6mnIE4/251ByceiHxJh 6svf4XKKQzF+mfvvBnnE15sRf/EThFeu9eZMPkcTHK4eexPdtuAghbbY2pwMcWJXmOsA 82Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563004; x=1725167804; 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=H7WxrWJ62hQ2vKyvroZvAzkaBumF7Y0KoLKrYpStuCE=; b=xL3apDt+k7gOizWyOkeJ8QZHGF0W8ppj4abxnj7JvOzfCYbrPCloIqjebZrhi6DEMQ fLGLC0SQQ3FWJGCarGLGpcZ84/gCRS5n8/j7QKPYeHpVKrbvE7F5md0ctyMDz4df83F9 9yhpDBUlMm4P3FaiUhIUMF73/8AyEkbaIAadIpH67BTN0CWjSsgcGyRQs9UJPF30VXWt QCGzAKR/tjrMkK/pr0cM8bFezz4kyMzrw9H2Y/moCXvjTmGc3YosobeAnpWrNggB9Ynf N0GgzoMWBdPu0aikDy4KRcJUQNXB+ysep2XxZW34sfKj2R7CFl+p1NVkoeHS1dcXq+W3 fUzA== X-Forwarded-Encrypted: i=1; AJvYcCVoukVClxub6bGOmHO8fmRZl+OK1o0N6esK5RtIN8MIfjeVPYR+kZBDRWrxQAwyeJdUZkCxQnsWH0J88DcIXXbR@lists.infradead.org X-Gm-Message-State: AOJu0YzutZfQZ63ykeN55gACsG1ohdJWapAF8itTomYyTp6temI8IFsg OK0He88j8XqrGMbeUbossJwEKxeV0toBj+Qv8lkPIPqvW3mYiUZj X-Google-Smtp-Source: AGHT+IH+QpbfxDnkPKJFQfMCjn2cIc8LsR3+E1IY+zf3Sg3+FogfeIFria8bka1eODj7ExYmhpbLgw== X-Received: by 2002:a05:6830:2808:b0:703:6ab8:1fe3 with SMTP id 46e09a7af769-70e0eb31f1amr8578138a34.15.1724563004054; Sat, 24 Aug 2024 22:16:44 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:43 -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 04/17] Input: ep93xx_keypad - use guard notation when acquiring mutex Date: Sat, 24 Aug 2024 22:16:08 -0700 Message-ID: <20240825051627.2848495-5-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_221645_637151_93F35B5C X-CRM114-Status: GOOD ( 11.69 ) 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/ep93xx_keypad.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/input/keyboard/ep93xx_keypad.c b/drivers/input/keyboard/ep93xx_keypad.c index 6b811d6bf625..a8df957ef261 100644 --- a/drivers/input/keyboard/ep93xx_keypad.c +++ b/drivers/input/keyboard/ep93xx_keypad.c @@ -184,15 +184,13 @@ static int ep93xx_keypad_suspend(struct device *dev) struct ep93xx_keypad *keypad = platform_get_drvdata(pdev); struct input_dev *input_dev = keypad->input_dev; - mutex_lock(&input_dev->mutex); + guard(mutex)(&input_dev->mutex); if (keypad->enabled) { clk_disable(keypad->clk); keypad->enabled = false; } - mutex_unlock(&input_dev->mutex); - return 0; } @@ -202,7 +200,7 @@ static int ep93xx_keypad_resume(struct device *dev) struct ep93xx_keypad *keypad = platform_get_drvdata(pdev); struct input_dev *input_dev = keypad->input_dev; - mutex_lock(&input_dev->mutex); + guard(mutex)(&input_dev->mutex); if (input_device_enabled(input_dev)) { if (!keypad->enabled) { @@ -212,8 +210,6 @@ static int ep93xx_keypad_resume(struct device *dev) } } - mutex_unlock(&input_dev->mutex); - return 0; } From patchwork Sun Aug 25 05:16:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776680 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 B8797C5321E for ; Sun, 25 Aug 2024 05:22:21 +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=+IClYBjpK7iTXWqXO0hqSivHGfHTegcYSer/+UixwhE=; b=0Ifi61tbXEMRSpUJA0V2QKOFxQ QDgu3AgTT5Bz+NStvTyADZh+HFuxDfcU8+p6IwLEaGUQTML8VH8TddRoo7LGJhr+LqOUS2p0Ht17i 3tnS74ATwXff0M5dGFBK8abVi7bLvAgTXtBq/cmT9zF08L9fQN2d1l4oVtT1EBF8AtSp/1gyq5Bm7 HaqggB1aulG8XvhjJnh6i7QmhTHEctBWtgusENMJOLGsAADQF/+EP2OOIOHpeY+RnmI6o4Rasxlb+ dEw3tDZDScsqch3jzPkejqrZSSGN243pjW4aqh2GNqo/Tm65IreQKZFjCkVxWl3uPzfaWNMVY7H5X ys0svNHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5hc-00000003fNc-0HNk; Sun, 25 Aug 2024 05:22:12 +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 1si5cM-00000003dei-3Bvn for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:16:48 +0000 Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-2689f749702so2273473fac.3 for ; Sat, 24 Aug 2024 22:16:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563005; x=1725167805; 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=+IClYBjpK7iTXWqXO0hqSivHGfHTegcYSer/+UixwhE=; b=EJ7BUAw1SK8vmPY2G4rdirrj/8tGyfV49jRz/85JLEHoq1hueAg22qpjh3x2TDVrk9 GXu2nK5NdnU82ahdzmlRUe0/7cnwHcycyuWiODtW1Qfh7jaspDcUPe8Kau1VkKs3vCyT SeccGAFcESd6QAl11duswyVgnjY0TeRiYnQZfIrs0ai+kQNHBm6saYf72h3Mti7zFPPs n3zLMJ75Mx6Go2ic5qyw4NYSalODOVhmLp2PcUeVyGI4dPdHiryuYZ0j9ymOBRxcph4H +mOLlaCQUDrq8OM6QEbBLnP4j8xAC95GEejcC4E661/lO7YF4ZkTkLa3izbdU4ft7gmr ACRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563005; x=1725167805; 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=+IClYBjpK7iTXWqXO0hqSivHGfHTegcYSer/+UixwhE=; b=MNBtBrhQXevGCC9a6F3sBO0A7jl9aLCfifJ2j585PpGd5FHgFJkJnF9GZEeJlEdAyz hN4QZaY/0Zep6x9LYy5pLDvD9bUmNjBmDVc7SgYXR2RsgZK7ali/XoekswaUZwdCkbBW mGCg3s/et5uz8OpBzT+CA6wfTv2ZPChZLavT+WATQZgrCa48gEljk5VzKlPheWpFURVZ FBva1SEGkMwfhfBw0iyq9sPS0n56DKEsQ5LpK6WPiMGGNYtO2V3QBiIt18iMXQKQsGSS nHir/mTVxhCVhFsbHw8Tt0PpzCR/Su33FQVifTUicezLoO8e5/B2SVQVLQFykkzwUTdy RnAg== X-Forwarded-Encrypted: i=1; AJvYcCVqjjf9E/n32euO6zZjuMaNGdauldf9a6tRxrGEgjzv4IB2BQFsnGckZfzmiA76DaRd/bvZvo8HKS7qDtwASyq5@lists.infradead.org X-Gm-Message-State: AOJu0YxW4F6GT493ZVSjvFdI1o6rK62R+heL90E3P22Kb3g9wM9TWY7K 8KFNjhO2ieEk8mE1IPpdXn7dX3m1xducyYu58CitaT3KP9RZtDCY X-Google-Smtp-Source: AGHT+IEotK5Z46zRG2q3RwlYVnZUsrGo/WBEX9X+Oub64iSKDadCyz4xjkfGuQRwO8QaHq4D1a66ZA== X-Received: by 2002:a05:6870:a91a:b0:270:46be:9534 with SMTP id 586e51a60fabf-273e64f5c77mr7810387fac.24.1724563005413; Sat, 24 Aug 2024 22:16:45 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:45 -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 05/17] Input: gpio-keys - switch to using cleanup functions Date: Sat, 24 Aug 2024 22:16:09 -0700 Message-ID: <20240825051627.2848495-6-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_221646_820844_B43891B2 X-CRM114-Status: GOOD ( 18.18 ) 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 Start using __free() and guard() primitives to simplify the code and error handling. This makes the code more compact and error handling more robust by ensuring that locks are released in all code paths when control leaves critical section and all allocated memory is freed. Signed-off-by: Dmitry Torokhov Reviewed-by: Hans de Goede --- drivers/input/keyboard/gpio_keys.c | 44 ++++++++++++------------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 9fb0bdcfbf9e..380fe8dab3b0 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -245,23 +245,20 @@ static ssize_t gpio_keys_attr_store_helper(struct gpio_keys_drvdata *ddata, { int n_events = get_n_events_by_type(type); const unsigned long *bitmap = get_bm_events_by_type(ddata->input, type); - unsigned long *bits; ssize_t error; int i; - bits = bitmap_alloc(n_events, GFP_KERNEL); + unsigned long *bits __free(bitmap) = bitmap_alloc(n_events, GFP_KERNEL); if (!bits) return -ENOMEM; error = bitmap_parselist(buf, bits, n_events); if (error) - goto out; + return error; /* First validate */ - if (!bitmap_subset(bits, bitmap, n_events)) { - error = -EINVAL; - goto out; - } + if (!bitmap_subset(bits, bitmap, n_events)) + return -EINVAL; for (i = 0; i < ddata->pdata->nbuttons; i++) { struct gpio_button_data *bdata = &ddata->data[i]; @@ -271,12 +268,11 @@ static ssize_t gpio_keys_attr_store_helper(struct gpio_keys_drvdata *ddata, if (test_bit(*bdata->code, bits) && !bdata->button->can_disable) { - error = -EINVAL; - goto out; + return -EINVAL; } } - mutex_lock(&ddata->disable_lock); + guard(mutex)(&ddata->disable_lock); for (i = 0; i < ddata->pdata->nbuttons; i++) { struct gpio_button_data *bdata = &ddata->data[i]; @@ -290,11 +286,7 @@ static ssize_t gpio_keys_attr_store_helper(struct gpio_keys_drvdata *ddata, gpio_keys_enable_button(bdata); } - mutex_unlock(&ddata->disable_lock); - -out: - bitmap_free(bits); - return error; + return 0; } #define ATTR_SHOW_FN(name, type, only_disabled) \ @@ -470,11 +462,10 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id) { struct gpio_button_data *bdata = dev_id; struct input_dev *input = bdata->input; - unsigned long flags; BUG_ON(irq != bdata->irq); - spin_lock_irqsave(&bdata->lock, flags); + guard(spinlock_irqsave)(&bdata->lock); if (!bdata->key_pressed) { if (bdata->button->wakeup) @@ -497,7 +488,6 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id) ms_to_ktime(bdata->release_delay), HRTIMER_MODE_REL_HARD); out: - spin_unlock_irqrestore(&bdata->lock, flags); return IRQ_HANDLED; } @@ -1062,10 +1052,10 @@ static int gpio_keys_suspend(struct device *dev) if (error) return error; } else { - mutex_lock(&input->mutex); + guard(mutex)(&input->mutex); + if (input_device_enabled(input)) gpio_keys_close(input); - mutex_unlock(&input->mutex); } return 0; @@ -1075,20 +1065,20 @@ static int gpio_keys_resume(struct device *dev) { struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev); struct input_dev *input = ddata->input; - int error = 0; + int error; if (device_may_wakeup(dev)) { gpio_keys_disable_wakeup(ddata); } else { - mutex_lock(&input->mutex); - if (input_device_enabled(input)) + guard(mutex)(&input->mutex); + + if (input_device_enabled(input)) { error = gpio_keys_open(input); - mutex_unlock(&input->mutex); + if (error) + return error; + } } - if (error) - return error; - gpio_keys_report_state(ddata); return 0; } From patchwork Sun Aug 25 05:16:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776682 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 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 = { From patchwork Sun Aug 25 05:16:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776683 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 5B743C5320E for ; Sun, 25 Aug 2024 05:23:51 +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=1eSvY1Wrp9wBfC4UTCsKK6UuziOLVmjJl+zbNYuZ+vM=; b=GoFcKPxrZ/LdYaUdkf6fonxV7B 7mld0XX4jSLVdpgDmWkeU2u5wVULuLJCL0MopRMez/Lij8njJ8q48QYzzM4odGBIp4nNx2Ol2djd5 jRZ2pypVHkehxQyCW0dD0wcfDGUr1r139s3rmZznCJN1SRpYNCgcrMe8xEDLMbShHckd9VVZDqCE1 mTpj/MZYx/bFnBYcQOR1lhuA4x1Fd4YEwcKo9gQUXCBZipiPng8uqieJ86MPQTnV4LE9KsxdiNG86 aivKjA78d3yBCEwpfsPIwl65xAOq4H8KDcKQtTbed0VSpL5jvzvciKQRnYb3wzifLrzck+fryxsZV moYPXdGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5j4-00000003fea-0EgL; Sun, 25 Aug 2024 05:23:42 +0000 Received: from mail-ot1-x335.google.com ([2607:f8b0:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5cP-00000003dft-1Ebh for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:16:50 +0000 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-70940c9657dso2546573a34.1 for ; Sat, 24 Aug 2024 22:16:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563008; x=1725167808; 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=1eSvY1Wrp9wBfC4UTCsKK6UuziOLVmjJl+zbNYuZ+vM=; b=QNepyJBsb+CpgBF629sZBePGj2y+ngvB9A5dQwxrkPgqdaLDHlFcTKLkpNjQA0hrVu MyVyAaSnUbI7EAVjFabs+7JcrNonhRA8e0r/BMSu7m+hdLmHiJIU6N71dXV0WNK/Gh61 UpL7UD1xfvbvPAP3YVM9HIiU0d3apaArhVMGibgxORiuzkJXbnDnWffxESAoXNx6cuQR 3f5G9qW8JoObAKQig6/3Z899WnSzNFFZwNpNFT6RO+PVagvzl6M8kcAbpv3K93NvOkip bTmORaFnE2cZcIjxF+CP0926PSwMptnxlqPyBwcUcfoA+g0RVYbsnuC9+3UNyYq6I2jo gjJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563008; x=1725167808; 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=1eSvY1Wrp9wBfC4UTCsKK6UuziOLVmjJl+zbNYuZ+vM=; b=Hgs04/cTWNzkg/Ljvu30nFQPJcQrD+8RcxsFnHTBPiogAi8k7DcfgaTEKLVTNSS+hc A6MF/+QVBJmPvxgR0TTiHipdz1oEMtA+3UekkVbH/Yg0QWlX+YzDTZqoxCIP1T5/R0k3 19xBEykBXov2VZxwTiPeA2sxyCsep0b2wzFf9+oRZvK10mCEeBzWKWpI9SxHExRvEBqJ ZSNTMo9xpfJfp+T0V6dgqcpgYuFzulByDDT0YkqWDd8T55UT9+zMpz2wH6qjgk51AhRw kc5HkZEI9dhSDnCvfuRpBbYvb/uwwQ960eHvMEeT/MegwvEr3DCjunrLLYoRt4LnOIp5 FtHA== X-Forwarded-Encrypted: i=1; AJvYcCWKV3y5+ZMlO/pdkF0RniBFI4DFeQYY7y2ocvt9V+0bpWCFuoKrXad966BK6qnfCK1/ZfN96HBpwLtdW0rBFWbO@lists.infradead.org X-Gm-Message-State: AOJu0Yw76ZiFIGanJPDZ5ZWFTr2cqn6YEHlQ6pW4dYl90ZzXxAgVUx2b GH0T1YNLsCi6JesHpeX6nuETkj2VS6q+EOdIZZNT5ijrffYRhj3e X-Google-Smtp-Source: AGHT+IFPvL2EwU0HTmfQ3cZEpHTEWkZdGY6KDfx96n7lf7JVGqj+9oNVagIFdpcxgTMQQpdCDsaEdQ== X-Received: by 2002:a05:6808:302a:b0:3d9:2aa5:4077 with SMTP id 5614622812f47-3de2a8735e4mr7831127b6e.5.1724563007948; Sat, 24 Aug 2024 22:16:47 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:47 -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 07/17] Input: ipaq-micro-keys - use guard notation when acquiring mutex and spinlock Date: Sat, 24 Aug 2024 22:16:11 -0700 Message-ID: <20240825051627.2848495-8-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_221649_358325_C23398A1 X-CRM114-Status: GOOD ( 11.77 ) 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 locks are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/ipaq-micro-keys.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/input/keyboard/ipaq-micro-keys.c b/drivers/input/keyboard/ipaq-micro-keys.c index 1d71dd79ffd2..58631bf7ce55 100644 --- a/drivers/input/keyboard/ipaq-micro-keys.c +++ b/drivers/input/keyboard/ipaq-micro-keys.c @@ -54,18 +54,18 @@ static void micro_key_receive(void *data, int len, unsigned char *msg) static void micro_key_start(struct ipaq_micro_keys *keys) { - spin_lock(&keys->micro->lock); + guard(spinlock)(&keys->micro->lock); + keys->micro->key = micro_key_receive; keys->micro->key_data = keys; - spin_unlock(&keys->micro->lock); } static void micro_key_stop(struct ipaq_micro_keys *keys) { - spin_lock(&keys->micro->lock); + guard(spinlock)(&keys->micro->lock); + keys->micro->key = NULL; keys->micro->key_data = NULL; - spin_unlock(&keys->micro->lock); } static int micro_key_open(struct input_dev *input) @@ -141,13 +141,11 @@ static int micro_key_resume(struct device *dev) struct ipaq_micro_keys *keys = dev_get_drvdata(dev); struct input_dev *input = keys->input; - mutex_lock(&input->mutex); + guard(mutex)(&input->mutex); if (input_device_enabled(input)) micro_key_start(keys); - mutex_unlock(&input->mutex); - return 0; } From patchwork Sun Aug 25 05:16:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776691 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 F3290C5320E for ; Sun, 25 Aug 2024 05:28:46 +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=+36NNSRmVK5FdylQPpVTYi2UVBcAisEyHgKp3fnH560=; b=uL/SOHQ9Aumd/25t61ePe7NQK7 haPoSIGOFBVtEAzr7ftcv1XXXGK9FBvQip3at83lyYQpsQXwilo6nW0HNJqalebBZjl/TICpvoXy8 +WT8ShU21+LbAS6Fb6tJr+jtn4djpPO8WVON3slTXnnJz8udo4IlnG8Mx+0clzCfOkoSFHH7OMuFj mWZui4MsNxay+6gsUrWz7Q7h+Pe1LuwdCJfnH96CRv/8njAK7PlTiL6ZhACOVyxB/xpBAhk3H3tFd GNatOFDneLdF1OMzLUmsZ/YFWzb1BM4PWVtBjr/GjHIzZzAk+cF4RBGLs7mZQc8l1GOMvoQcZZ6lM aGaST2mA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5no-00000003gZU-36NX; Sun, 25 Aug 2024 05:28:36 +0000 Received: from mail-oa1-x29.google.com ([2001:4860:4864:20::29]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5cQ-00000003dgO-2MdV for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:16:51 +0000 Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-2703967b10cso2397282fac.0 for ; Sat, 24 Aug 2024 22:16:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563009; x=1725167809; 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=+36NNSRmVK5FdylQPpVTYi2UVBcAisEyHgKp3fnH560=; b=V1Kuf8UfWo/S+uenWcxb1upvKzKEjQv6Nl6VWQSJOlRjJ0Kc1DGrEOdyaFK5p4NcSI IcS0uH0iEiw8VcX0fIbEJh6c5hx4r4W0PIZ0jRRr59NC8KaoMGJHPMbA6fylpySSIDXW JdaCsB846ENeD0lwRAiKGQomT/2ET3zzEKbeouPS4gV/wt8vbDhzGv/NMWUIGHP2J9xl mZSTeADuR5UBc9pUgBJYRMMtd6bLPGy8Z9k2dXBU+ZrX/HhYy9xxP5ALd2rjlRiHnLpM CBUY+tB2HW+RSBCrqcJkEkGNbo9Im29Kly90rKOD8HOUqXtxDwi1syTskzyEEzoXrCQy kpiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563009; x=1725167809; 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=+36NNSRmVK5FdylQPpVTYi2UVBcAisEyHgKp3fnH560=; b=PWwYQVrWqHF2SkcB7tftl97x28kK93PhfGgzZT4bJ7oKmoypSfaA0cZs2tEZ0rbu4q vLmsN6U/Zd7/prNv361jEWdfUSrDbyRyQnD3Gl8iTihfhh8pAsU7o3A58WvtjESsH3RS wA53Z/MHdEsksWZ5RFY+82rdCd+R0ixByyK9E/cGv6/ofG8p5joadRLZ2CddxyOUSrx1 P5faI5ta/P1F0fNnwqN4btr18vk5PkPYm99NfctyIeErl656/c8DN6xmy7JS6c9rE0Zl OjUOYrjnDaCcFrkiRDshBpDDt0w0stYkyr9WsPnSfHEN5zq4jf9tlMEngaIfCtU//D/F 5clg== X-Forwarded-Encrypted: i=1; AJvYcCW4cZeIbAtVvnl/EskvsgXNa3+Wgj3XqeciAjEP0tnzdB8uGmU1Xq0v/OWeJbWDVxgq0bkuUBsP6U01ZqDRmEbu@lists.infradead.org X-Gm-Message-State: AOJu0YyapQnJ5URvH5Cv7eHMl06bMInjJ9E+Fcxd6htEcwz26EVKrwzF wThTbovr7jZ2+ywue3fE/8fLLU/I9giWlNYA/h6JdWsb9b++FglB X-Google-Smtp-Source: AGHT+IH50jfqsAxngsJyrNPRIognUKjg0ENHDCRW+P0AHBitO/WlT6UscLBhxwYmGb+kHjshcMLPag== X-Received: by 2002:a05:6870:2010:b0:270:1fc6:18 with SMTP id 586e51a60fabf-273e64458d2mr7894304fac.3.1724563009229; Sat, 24 Aug 2024 22:16:49 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:48 -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 08/17] Input: iqs62x-keys - use cleanup facility for fwnodes Date: Sat, 24 Aug 2024 22:16:12 -0700 Message-ID: <20240825051627.2848495-9-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_221650_629631_A68595ED X-CRM114-Status: GOOD ( 13.90 ) 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 Use __free(fwnode_handle) cleanup facility to ensure that references to acquired fwnodes are dropped at appropriate times automatically. Signed-off-by: Dmitry Torokhov Reviewed-by: Jeff LaBundy --- drivers/input/keyboard/iqs62x-keys.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/input/keyboard/iqs62x-keys.c b/drivers/input/keyboard/iqs62x-keys.c index 688d61244b5f..1315b0f0862f 100644 --- a/drivers/input/keyboard/iqs62x-keys.c +++ b/drivers/input/keyboard/iqs62x-keys.c @@ -45,7 +45,6 @@ struct iqs62x_keys_private { static int iqs62x_keys_parse_prop(struct platform_device *pdev, struct iqs62x_keys_private *iqs62x_keys) { - struct fwnode_handle *child; unsigned int val; int ret, i; @@ -68,7 +67,8 @@ static int iqs62x_keys_parse_prop(struct platform_device *pdev, } for (i = 0; i < ARRAY_SIZE(iqs62x_keys->switches); i++) { - child = device_get_named_child_node(&pdev->dev, + struct fwnode_handle *child __free(fwnode_handle) = + device_get_named_child_node(&pdev->dev, iqs62x_switch_names[i]); if (!child) continue; @@ -77,7 +77,6 @@ static int iqs62x_keys_parse_prop(struct platform_device *pdev, if (ret) { dev_err(&pdev->dev, "Failed to read switch code: %d\n", ret); - fwnode_handle_put(child); return ret; } iqs62x_keys->switches[i].code = val; @@ -91,8 +90,6 @@ static int iqs62x_keys_parse_prop(struct platform_device *pdev, iqs62x_keys->switches[i].flag = (i == IQS62X_SW_HALL_N ? IQS62X_EVENT_HALL_N_T : IQS62X_EVENT_HALL_S_T); - - fwnode_handle_put(child); } return 0; From patchwork Sun Aug 25 05:16:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776692 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 05878C5320E for ; Sun, 25 Aug 2024 05:29:34 +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=Y1sIje/HnXzt33wD+dka8sJAuwV3C7GUd6Fvewfxm9o=; b=ttk9y1TOuZXarO3fQViJR+W/8S oB2smX/kThFVOBI7bMhk3as3m6moWoLmtfngpsoR0j2gNtq6LlP9ZqMZT+TxGg1y/JPTWzbM0asXb Nb5KHzbxWMiomgZsy80pr+GEEzpu9HVeOU1NiFk2YtFx1cW2bO0ErY6Dv1FMpjd/O5/vr0Ag51yHA frNqJ8et0D5Ytk6oeLiijkGt0AuP3pOA02vcpiURoVNsIWQVlJDe3E62VdrQTLJMCi/6Kcl+p+sIy DDHRlk1Os0ZRJo/OFiuBY1fslKp8cBXUs1LB1erFm438lLXmIzdSnTeZrdKH1DMR9SeWYHAGVbdeI qkdXqx1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5oY-00000003gkv-3QUc; Sun, 25 Aug 2024 05:29:22 +0000 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5cS-00000003dgz-0qv6 for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:16:53 +0000 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-7bcf8077742so2272615a12.0 for ; Sat, 24 Aug 2024 22:16:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563011; x=1725167811; 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=Y1sIje/HnXzt33wD+dka8sJAuwV3C7GUd6Fvewfxm9o=; b=TxPpvsLza1Ls87GzzvHzTnKx+3GXqsggS1zUo9d3v+hFVW5GIt8E2KkSw2GjeEb87n lRMa72ur4CT6aEnHK0zF4r1OfGVNpBKrxdP3beqkl4wKK6V5SVxGRkvhQ7b3bGfEOoEa EDkWhS3zAHfjKZNC0LIY4cuu4tTy/jRtE9LaIF0cFEWkva4OiDS13wofDzqUyHAuyjgR FKp3LwkB68aKbSq5Ouy8rNHLpuPLeQv+2iXKZyF477Icvt1cZ84p1Woh+MET0CI9Hztp U+Lcj+8sg2MTdAyDW7aGNDls1Sf0Q4nGNfaskeY4C95k8pe0sBk6q6AUeyZmLjQZu/rM pP/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563011; x=1725167811; 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=Y1sIje/HnXzt33wD+dka8sJAuwV3C7GUd6Fvewfxm9o=; b=vRxWelvpJT0pS7bYb5w4nbBhwaxM/HorleGbE9xTDLQqBhZk++cs8dBR8Imt/ojrtt PRouf9vCH7mq8x1zJzHaxg42t7+EUsMgnPA20aatggZX5EgujymdXDyrYLYpVUGreKWt DIqOgiLd/WaJKMxIUXE6xdbzLIDwIMCjde9aozMeQSzrf/jSTdDtPqyo+Zk5l5n2gsZS iXiKryB3IiNelAGTdUBBYqOH9SPT9T/ZDIojnY2XFHWOqlLNQs6UVeG1Db5xtyPi1v/l gfRcNGNeE8aFJtPJTLi4/IbWJ9nahxOG0rGQnLPcf09VzI3Go0SMZ0erukzKK1JerqB8 Pyvw== X-Forwarded-Encrypted: i=1; AJvYcCUOVfJpR2i3Xb/zftkXPhE9+NPi27P/XGoAj7RCPgVBQy+mqfnqn604g428s/uoMXPLo7SL/iCKGNHOBh3/Hah7@lists.infradead.org X-Gm-Message-State: AOJu0YzlV+MZE3wxw7TJZW7/S8VyH+dSciqgc1YzM5yOqDeQoibCoxN/ aoLKIQbPQK8JMuMQ0qeGeaeC9iNzPpHKvwWX3kAq+Suv2oXVfm6r X-Google-Smtp-Source: AGHT+IH6nl7Gp6typ8jXOMj8WE/a55ZrJJqfoIbSsLMBPPh/0P9kxt4yqzLE6RUgOHHWRfDQqSZM3Q== X-Received: by 2002:a05:6a21:3a87:b0:1be:c4bb:6f31 with SMTP id adf61e73a8af0-1cc89d4d900mr8040665637.18.1724563010571; Sat, 24 Aug 2024 22:16:50 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:50 -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 09/17] Input: lm8323 - use guard notation when acquiring mutexes Date: Sat, 24 Aug 2024 22:16:13 -0700 Message-ID: <20240825051627.2848495-10-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_221652_269438_0AA5DE34 X-CRM114-Status: GOOD ( 16.12 ) 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/lm8323.c | 49 +++++++++++++++------------------ 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/drivers/input/keyboard/lm8323.c b/drivers/input/keyboard/lm8323.c index cf67ba13477a..e26bf2956344 100644 --- a/drivers/input/keyboard/lm8323.c +++ b/drivers/input/keyboard/lm8323.c @@ -350,11 +350,11 @@ static int lm8323_configure(struct lm8323_chip *lm) static void pwm_done(struct lm8323_pwm *pwm) { - mutex_lock(&pwm->lock); + guard(mutex)(&pwm->lock); + pwm->running = false; if (pwm->desired_brightness != pwm->brightness) schedule_work(&pwm->work); - mutex_unlock(&pwm->lock); } /* @@ -367,7 +367,7 @@ static irqreturn_t lm8323_irq(int irq, void *_lm) u8 ints; int i; - mutex_lock(&lm->lock); + guard(mutex)(&lm->lock); while ((lm8323_read(lm, LM8323_CMD_READ_INT, &ints, 1) == 1) && ints) { if (likely(ints & INT_KEYPAD)) @@ -394,8 +394,6 @@ static irqreturn_t lm8323_irq(int irq, void *_lm) } } - mutex_unlock(&lm->lock); - return IRQ_HANDLED; } @@ -445,7 +443,7 @@ static void lm8323_pwm_work(struct work_struct *work) u16 pwm_cmds[3]; int num_cmds = 0; - mutex_lock(&pwm->lock); + guard(mutex)(&pwm->lock); /* * Do nothing if we're already at the requested level, @@ -454,7 +452,7 @@ static void lm8323_pwm_work(struct work_struct *work) * finishes. */ if (pwm->running || pwm->desired_brightness == pwm->brightness) - goto out; + return; kill = (pwm->desired_brightness == 0); up = (pwm->desired_brightness > pwm->brightness); @@ -489,9 +487,6 @@ static void lm8323_pwm_work(struct work_struct *work) lm8323_write_pwm(pwm, kill, num_cmds, pwm_cmds); pwm->brightness = pwm->desired_brightness; - - out: - mutex_unlock(&pwm->lock); } static void lm8323_pwm_set_brightness(struct led_classdev *led_cdev, @@ -500,9 +495,9 @@ static void lm8323_pwm_set_brightness(struct led_classdev *led_cdev, struct lm8323_pwm *pwm = cdev_to_pwm(led_cdev); struct lm8323_chip *lm = pwm->chip; - mutex_lock(&pwm->lock); - pwm->desired_brightness = brightness; - mutex_unlock(&pwm->lock); + scoped_guard(mutex, &pwm->lock) { + pwm->desired_brightness = brightness; + } if (in_interrupt()) { schedule_work(&pwm->work); @@ -510,12 +505,12 @@ static void lm8323_pwm_set_brightness(struct led_classdev *led_cdev, /* * Schedule PWM work as usual unless we are going into suspend */ - mutex_lock(&lm->lock); - if (likely(!lm->pm_suspend)) - schedule_work(&pwm->work); - else - lm8323_pwm_work(&pwm->work); - mutex_unlock(&lm->lock); + scoped_guard(mutex, &lm->lock) { + if (likely(!lm->pm_suspend)) + schedule_work(&pwm->work); + else + lm8323_pwm_work(&pwm->work); + } } } @@ -608,9 +603,9 @@ static ssize_t lm8323_set_disable(struct device *dev, if (ret) return ret; - mutex_lock(&lm->lock); + guard(mutex)(&lm->lock); + lm->kp_enabled = !i; - mutex_unlock(&lm->lock); return count; } @@ -758,9 +753,9 @@ static int lm8323_suspend(struct device *dev) irq_set_irq_wake(client->irq, 0); disable_irq(client->irq); - mutex_lock(&lm->lock); - lm->pm_suspend = true; - mutex_unlock(&lm->lock); + scoped_guard(mutex, &lm->lock) { + lm->pm_suspend = true; + } for (i = 0; i < 3; i++) if (lm->pwm[i].enabled) @@ -775,9 +770,9 @@ static int lm8323_resume(struct device *dev) struct lm8323_chip *lm = i2c_get_clientdata(client); int i; - mutex_lock(&lm->lock); - lm->pm_suspend = false; - mutex_unlock(&lm->lock); + scoped_guard(mutex, &lm->lock) { + lm->pm_suspend = false; + } for (i = 0; i < 3; i++) if (lm->pwm[i].enabled) 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, From patchwork Sun Aug 25 05:16:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776694 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 A302DC5320E for ; Sun, 25 Aug 2024 05:31:05 +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=j9zYR0W/Xjhx97slmPTim4xkiDUhOUV5BM1jCImN77U=; b=yy5OfHmcTy4fLclF5xy6dsthYk WJ5JJn9dv/wzswdz8Th/WBOjlnX9WNtb680K+idfXKBKc011WhbNQaroSXh5hFxUJ6Ewb1ztS8z/8 QEhMlmyA/8F2nffrCDj2JG69qwPvJrkE7CvApsR6z4VcExh2nC4EBXmq93UuGaj5UsQx9A/cgcUfz ffysrExWv/wRs+yw/FZz9xXv3M/aidB3xl5DDn3722I+WBXizA6L5DSZzd7ol8dB1dFK9YAn0xci8 XJHp9ru2x2FKgORh1IdckUV+i5n5kqHfy5kfMb6erdcZnA1QY6YkrCNHV4h4rFM3hx19ID/bDV5qM OdgeZNGw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5q2-00000003hHR-0Cz2; Sun, 25 Aug 2024 05:30:54 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5cU-00000003dis-1xID for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:16:56 +0000 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-7143165f23fso2467551b3a.1 for ; Sat, 24 Aug 2024 22:16:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563013; x=1725167813; 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=j9zYR0W/Xjhx97slmPTim4xkiDUhOUV5BM1jCImN77U=; b=PlYfcL5YLj/uQWPPpAzuF29113bV3alSluwR7wxFdgzQURz4V/l44AC7PUMxIXmtOp 1sgGKzkJlGBXyOYZV9Pjlk1dDDigIcfN2l///JswfV7hsx2l1TloqQBDJ9Es5QvxaUGg anSTTuyfnMwl3qx2dHE8s0aZkR7CdXRpXsRA+6xJoJD9dJOkZVAKFCeZtnW98wDnmVGN G3h7sXiJXAUa37Gq1G6RIfqwtEY77yiSOnRPjHFg8NtscX4SwJmRrGYHGs3lrLBZmRXn QSQK4WJF5pLrMRKCsJAJWQA/DaGwOg1aVwrcHojJKjhXB/4HaV3VpbK43FbFxgdmnNvx qLxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563013; x=1725167813; 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=j9zYR0W/Xjhx97slmPTim4xkiDUhOUV5BM1jCImN77U=; b=ql/QzfAUhG5JERnxfZpRd02VCzVHHb17rCCXXFCe1VhCJYWEMmBM/ZWZQSBUbqeTxa +dC2qyj5IRY+oFspYbgi+A40yD5D/nS+wpuByYEoCPLVbPbrXkoCH4JxSf7cvj+UkePB E0DHppmpjp+MFdehskidv4YSUTFtAqqYFYKBTr0PTWhypmShR838ynIgIkLRKWW5dS/S STflWF9/JUkDZdxsZUcX1GZineLFMfJVpsRLrr96S38jyEJSxZ/NFNWWuE0lsbJ5uRC4 Si/reel0lCFJ6Qd1krIVpusgL6A4EbYp+JNnT5R804XovSuNQH6k5R+wSqE79oEh8bfm l5/g== X-Forwarded-Encrypted: i=1; AJvYcCU8BKhhR82QI59w7WX3ZUGvU9thJFhx2/2FHq1kZWgzd2u+1kA7NN+jbE8wLSkyAFiQq2eiQu8CTtwiNL615mNw@lists.infradead.org X-Gm-Message-State: AOJu0YwUb0fZu+AKd1sG2eLY5EPShRPXad7P0cGm1rDDw7nfmvloxjrH Fgs3dHYJe71IbQD6f3FJUFvK1XcgpLcoQHrdDhj/PlqD6OJIozBx X-Google-Smtp-Source: AGHT+IHcuT4NA41j3BiOlgdyA7A3m2CkwtxDOGLO51Pqdelg8y5qs9HsGoezNmvzuRmb2+38RG5t8A== X-Received: by 2002:a05:6a00:18a1:b0:70e:8e3a:10ee with SMTP id d2e1a72fcca58-7144587e2dbmr7640487b3a.21.1724563013105; Sat, 24 Aug 2024 22:16:53 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:52 -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 11/17] Input: matrix_keypad - use guard notation when acquiring spinlock Date: Sat, 24 Aug 2024 22:16:15 -0700 Message-ID: <20240825051627.2848495-12-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_221654_571336_511E2A2B X-CRM114-Status: GOOD ( 12.23 ) 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 locks are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/matrix_keypad.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index 7a56f3d3aacd..bd763d704306 100644 --- a/drivers/input/keyboard/matrix_keypad.c +++ b/drivers/input/keyboard/matrix_keypad.c @@ -158,18 +158,17 @@ static void matrix_keypad_scan(struct work_struct *work) activate_all_cols(pdata, true); /* Enable IRQs again */ - spin_lock_irq(&keypad->lock); - keypad->scan_pending = false; - enable_row_irqs(keypad); - spin_unlock_irq(&keypad->lock); + scoped_guard(spinlock_irq, &keypad->lock) { + keypad->scan_pending = false; + enable_row_irqs(keypad); + } } static irqreturn_t matrix_keypad_interrupt(int irq, void *id) { struct matrix_keypad *keypad = id; - unsigned long flags; - spin_lock_irqsave(&keypad->lock, flags); + guard(spinlock_irqsave)(&keypad->lock); /* * See if another IRQ beaten us to it and scheduled the @@ -185,7 +184,6 @@ static irqreturn_t matrix_keypad_interrupt(int irq, void *id) msecs_to_jiffies(keypad->pdata->debounce_ms)); out: - spin_unlock_irqrestore(&keypad->lock, flags); return IRQ_HANDLED; } @@ -209,9 +207,9 @@ static void matrix_keypad_stop(struct input_dev *dev) { struct matrix_keypad *keypad = input_get_drvdata(dev); - spin_lock_irq(&keypad->lock); - keypad->stopped = true; - spin_unlock_irq(&keypad->lock); + scoped_guard(spinlock_irq, &keypad->lock) { + keypad->stopped = true; + } flush_delayed_work(&keypad->work); /* From patchwork Sun Aug 25 05:16:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776695 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 A607CC5320E for ; Sun, 25 Aug 2024 05:31:47 +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=TgrHzPeIHjCQToVGMM9JpdcPooP9HE7kqNjFtcQ3CT4=; b=gZenEHOLB3m0XfIt7gkDymlzZv P2qpCXBXTrEg6Q/tQ3YVwpffM2Ghi+BiO4I4+JZOLqj8d87yOPI0A/ZLo7PUVKujiVrRRJXJ3Zj0X cHOlvZ1jaGAHpbxSewnn7EKZdoKuoTBaseCvDwtG870uAbAjTaBP1aF5fME5uA8JrzVPlvKGCZxKj 8WlrqsMJd/wkWX9pmV01EYI8OAhWidIgul7Ar6pq5WksSMSKJOlEnWIcrFJ7EAiBjnnuBhDg+P39v CHgHN7Hxywl+wmDgb11HE5/K0aes7fqjc5tCXJR1u5L4Toj9zV+lZHjfPiBklChWzqzlVTYA+li7r AdcWJv+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5ql-00000003hTJ-18pY; Sun, 25 Aug 2024 05:31:39 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5cV-00000003djg-30ba for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:16:57 +0000 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-71433096e89so2772775b3a.3 for ; Sat, 24 Aug 2024 22:16:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563014; x=1725167814; 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=TgrHzPeIHjCQToVGMM9JpdcPooP9HE7kqNjFtcQ3CT4=; b=gy/ocSp8P4cl+i9WIdi3TQj7HgOP0N1BqM+RdorF1ms2WqokB/X48o/lsfykhbd3rp Dl24cnOkH4XcyG6Ofincr0O3fH89plVOyb8pJFEUmSWULQOvMfN9NvCuGR2Qe1+5bVpV Eon//hmnGWAlrPfATDcM1dui3JoEM1WLrTlKctUKexi1EXs3lqg+k1qgIig6LDnbIcD6 uXrctZO4DJm/Z+JuEC/uvTWay3Tg5G/UZIsjAPP8V41/9A4Irtg25HHDUn5g89gnIrhD ItpF3ImXqv5jVeLngNNK7atMjxdRrCp8KBmT146TS8gxGMlRwObzzYBlB0feT9U25q2C ThJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563014; x=1725167814; 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=TgrHzPeIHjCQToVGMM9JpdcPooP9HE7kqNjFtcQ3CT4=; b=ML4N+zW5OIfIB567rTZUdReY9PMhZejC316/ZtX6pmOKRi306mEUGU1ajCUw7Zgw5f wGbckEDWS76SSfWdC2hIx+DdcUPUHSPzp6uWNshAF2/eOpJsu+JrPIu2XDDakVNnhKEr o/2vUWEzrBkFKRvX6JE9vNa6GdJbJ5ht6bCLb/rWV7yVD9TeUayFRJo5A7GtzSELs2Uk +nRq+LKVmHgiOV2WFBplYU6CFNPfphpueMuvTgDSADuZ79pkjUzpEC6FnhlfhgKagS/s ZYNvIDOAW8n+bZJBdUPUZfdzjmeUd7xglTRzuW5JZuUt8lsghZ/NXAb5ybZRGj7cRlWl N2rQ== X-Forwarded-Encrypted: i=1; AJvYcCU9twbJF8LJ8q++J7sY8WgEZSkor2zbU3nZcDOEAKQAUlZeRE/nWYOjOV6qqsmlkmWd8vclFRmVSeAUrRChEKG1@lists.infradead.org X-Gm-Message-State: AOJu0YxksnN9Dngtqv8MTqz19oYPvdkIBY2g5UKvQYEVT3c0NXHHFsHx TRSUlX9qE3MydWdmT42Tfoe4IdldPINnvZe786+bR2i9CGmzBsfF2cHbdw== X-Google-Smtp-Source: AGHT+IG9GzB5hV+R3jUFqV7C8FiDWaB5skbl01e83Rq6Yxznn6igCC+xVD3kT7dOcBsXXHvExd8ddg== X-Received: by 2002:aa7:8895:0:b0:70d:1fbe:b96f with SMTP id d2e1a72fcca58-71445893b63mr6876250b3a.21.1724563014434; Sat, 24 Aug 2024 22:16:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:54 -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 12/17] Input: omap4-keypad - use guard notation when acquiring mutex Date: Sat, 24 Aug 2024 22:16:16 -0700 Message-ID: <20240825051627.2848495-13-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_221655_778747_8AEF64C0 X-CRM114-Status: GOOD ( 10.71 ) 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/omap4-keypad.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c index 040b340995d8..935c2b27b81c 100644 --- a/drivers/input/keyboard/omap4-keypad.c +++ b/drivers/input/keyboard/omap4-keypad.c @@ -144,7 +144,7 @@ static void omap4_keypad_scan_keys(struct omap4_keypad *keypad_data, u64 keys) { u64 changed; - mutex_lock(&keypad_data->lock); + guard(mutex)(&keypad_data->lock); changed = keys ^ keypad_data->keys; @@ -158,8 +158,6 @@ static void omap4_keypad_scan_keys(struct omap4_keypad *keypad_data, u64 keys) omap4_keypad_report_keys(keypad_data, changed & keys, true); keypad_data->keys = keys; - - mutex_unlock(&keypad_data->lock); } /* Interrupt handlers */ From patchwork Sun Aug 25 05:16:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776696 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 67F4CC5321E for ; Sun, 25 Aug 2024 05:32:35 +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=pqe1CPNPyPwWJltZY/tNpoPncj2b2bW7ofGMYanWSqo=; b=17lamNu8nv/jAawe44Yez/T+ad 6wSx2mCDce/YmxbLUDCekpSmWpszENXxjnZUVp/cv8bLs2m6DeX7B4/fsEyECrQps4jmMfLEthFuA c1b12BST1w8PCuJDT4mQwyVopTC7o0hOU1rnwrALA0JluFRVnUlcI46+jUrl3tJIddLEcwOl3f/2D SRbrdLdp1x3h8azPGzZKAL1LQvITTwigKvrFcCO4RPl8omtJ/zvv8qO4B8VLw38awV6kGNw4xHM9R hPfocjMyOSJ58wdC+BC6IuNbJHwB8CV/NHTsqy0MxsO6vjTZkcHaPV5rTRLiPxK0XrW7790vQ069T H6sKu+rQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5rU-00000003hbE-1GGQ; Sun, 25 Aug 2024 05:32:24 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5cW-00000003dkA-418H for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:16:58 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-7142a93ea9cso2326784b3a.3 for ; Sat, 24 Aug 2024 22:16:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563016; x=1725167816; 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=pqe1CPNPyPwWJltZY/tNpoPncj2b2bW7ofGMYanWSqo=; b=XiSrXBydlDFyDHkk03goxLIgfkLtmvjKg2Dk5AatrTnsN9WEp8HCLdS9/Cjz30YOsV OBmpg3rQ3qwvuWK/6HHNSvSqHrAS0d5rGvATuD6eYpfLbowyTb+cpWT2QuzqulvL7i0s b6T9y9mcCKTZj0UaEY6FxVJnimsSiAlH46Sp5evxUCwQ7ugdbzIk+O9efm0k7q/WM4aP 4EYTWtr8Qe5awfNolAQ/MCv64K9bVgDyNdUe5u7xDpWAPb/By9hqZ03z4oefB00eIKCN 1jmBLQPgef9RWHMKkWpS/as/hLTgWh0lBmxgGajbgirBaWgnIXLxjMqMj98bizw5tC9W tc2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563016; x=1725167816; 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=pqe1CPNPyPwWJltZY/tNpoPncj2b2bW7ofGMYanWSqo=; b=fUE9ii/TC3K6Z92G0k07+fAwE1rAKua92jgf1Qp+i0OCzet+kNz2/Q/A39ojHFcyf3 wwYSwHkFIebLY3ktFhZ2j5gqz2EPzAt+xxYRR1qkEtQMQG1Xyxbxn7WhOof9LX92igCL w5KGqqtkMAk8V3f7QH1gti75sSNxo/XMTsCAAk0QGsIopi1efUMyB726wTPMOHHHHgUh +oI12wnYQ5H74EATKnHbH9L9F5rJnu/qPmEhPvG/ps/h3TdrfLmdGRmydvtA+1+X3uYN 5nkbILyrkacjQOOKtCF3UA+puydVoDq1QEDC0GruqkNk1u60eLVuZeIlu5kSfknzpOYl F/RQ== X-Forwarded-Encrypted: i=1; AJvYcCXZyRNEHren5PsoGkJjUeUq11HEteOX/+L2Gh+fyvlBH18zxuQfUxOTrzbBaxmskwbhCdBuIJ9BX4ZEhfRfLXFr@lists.infradead.org X-Gm-Message-State: AOJu0Yz3fvRanWuHCom3N1ZuTVCzDWt/2rYKHwIuYpavtUf24rcw6Ay4 1ZPwr+kcDNyZZoke7o9ICb0yTocOBtUNtK1K1xNDcpsloA0bsP42 X-Google-Smtp-Source: AGHT+IE9hfgPOc8K99rlo2yxdGDK0Km4IWYmEWtHARTyEvzXLFTX1fk3uYEqzkP6IiseW8pPeV5XNQ== X-Received: by 2002:a05:6a00:228e:b0:714:2cea:1473 with SMTP id d2e1a72fcca58-71445883e36mr6910331b3a.23.1724563015700; Sat, 24 Aug 2024 22:16:55 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:55 -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 13/17] Input: pmic8xxx-keypad - use guard notation when acquiring mutex Date: Sat, 24 Aug 2024 22:16:17 -0700 Message-ID: <20240825051627.2848495-14-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_221657_340427_62BF92DE X-CRM114-Status: GOOD ( 11.49 ) 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/pmic8xxx-keypad.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/input/keyboard/pmic8xxx-keypad.c b/drivers/input/keyboard/pmic8xxx-keypad.c index 26a005f9ace3..35d1aa2a22a5 100644 --- a/drivers/input/keyboard/pmic8xxx-keypad.c +++ b/drivers/input/keyboard/pmic8xxx-keypad.c @@ -630,12 +630,10 @@ static int pmic8xxx_kp_suspend(struct device *dev) if (device_may_wakeup(dev)) { enable_irq_wake(kp->key_sense_irq); } else { - mutex_lock(&input_dev->mutex); + guard(mutex)(&input_dev->mutex); if (input_device_enabled(input_dev)) pmic8xxx_kp_disable(kp); - - mutex_unlock(&input_dev->mutex); } return 0; @@ -650,12 +648,10 @@ static int pmic8xxx_kp_resume(struct device *dev) if (device_may_wakeup(dev)) { disable_irq_wake(kp->key_sense_irq); } else { - mutex_lock(&input_dev->mutex); + guard(mutex)(&input_dev->mutex); if (input_device_enabled(input_dev)) pmic8xxx_kp_enable(kp); - - mutex_unlock(&input_dev->mutex); } return 0; From patchwork Sun Aug 25 05:16:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776684 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 17E17C5320E for ; Sun, 25 Aug 2024 05:25:44 +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=6On2/1bDkxm+R+4fGzTtvwf3YjBZiAkFwRYzWZ0YLaw=; b=cdkRKNpuoh2uJsyVJaFUK4sl9u dkz9fXiQLpOWmEO6ViDVZNbzDxQRx3ER/mlNZ8vDBbeGUD4PYt8TCR04mC4tE1I7eBbnW6/RmOXJq +CWLbKoHpBbr9iQ/yhuIvVaBoOoPvkIPr0KtK7l7PGZqljOPDwrMU/bX/U++fVTWHPBp87H4cH6B2 wqhLwV2NgQrpQfBcZVeBfeiN6cqLw9qv1Mv1ntorfWz7HAjOCWqMg4lZ0UgMKxVhBpnZn/JBMpEvw ry8wcP91hQXvmRyfA2MIIXTv6jHn95RizmRowu5xLj95BU4a/0HSkCaB922IVx7cmEeTJBxxvOPkB XDbw7Kdw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5ks-00000003fuY-3ItK; Sun, 25 Aug 2024 05:25:35 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5cY-00000003dl3-0v4a for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:17:00 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-2021c03c13aso24234085ad.1 for ; Sat, 24 Aug 2024 22:16:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563017; x=1725167817; 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=6On2/1bDkxm+R+4fGzTtvwf3YjBZiAkFwRYzWZ0YLaw=; b=mIwFpXDdIvztZhVaaMcWdIgSGEKQ0oYvefzU2jEm1xiSuWU5Awnf5vWTM67JpqAvPm qVebbslLtBnzPJS7KFHRxqw2lAa4rFebcWnyh201TBthF6f4UpNNyk1dwbiPTGJIsVjd sApZXHcvdQnRIarQNd0E4J4GVFK2PJWUxp0SIBPQZdMaEilM/jy4upfnfBjVKfYNb3sN l6MlxvxOmFiRP4CIrdyuPvzoegfCNvyFF3z16mdLR5RLQNIoUjtr3PzgttcD6TzM2AO0 g47oD511Yfa8w6MtZmkJ8FDfDfs5F2tz9Ue0oYQI66JE0jZwXuwnEuM6+hBh2Ev8iwaq A2gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563017; x=1725167817; 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=6On2/1bDkxm+R+4fGzTtvwf3YjBZiAkFwRYzWZ0YLaw=; b=ue5CWkvns5RJ09nSnv1bZzQ65fJf6bLusCy7WPLFrh0/ohytqn6pXbM4o5ucru0hpG VAZkgST3PhGh99BLQ11dsFAFCOWaPgbQ5W8fz1bEqxVswUWD7B3GSUnHH41N6RL4HMPM XmJDRw7sUwLmY0SY1ZuYSEYlFXdSlLWjBK5K7zTbTkR3MYXyKdkUGLPHHYPPFjtgI6rv AXNtWYivo7qit909+LhISgGkwz0+veKslTKJfCeTqTVssdfVQnc+Y4yZzJbycREIygjB pEB5Cd+6t6dDlIF96LOt4aJo7lYlepuoBFi/Nv+ZtXiAu35lOp7FNk62tKqyAYjf4Y8E W9Zg== X-Forwarded-Encrypted: i=1; AJvYcCUhWpo7hlIUGdF8pi8jebKktg5i7+pXP39hCEQfGHwAy4x+20U/KAfQBcV4K14ZqBtY9ijlMUs5NocSqUWlMXFK@lists.infradead.org X-Gm-Message-State: AOJu0Yw/xwHENaKF8WIIIijORXBpB5uN8MngfYhF7LRKCAZitaTe59V7 QGhMcGuF6qJ1a3Iv/Q8acHXwpbvAca77vQqXXbDpz7Wul0+u3Njp X-Google-Smtp-Source: AGHT+IGTPS2b+A1C17aqp6MUwEwi5FNiFSaX+X5FwBh4QbkvAkE9nJITwi8u1xgUd3TXRjDwffCIyQ== X-Received: by 2002:a17:902:f9c8:b0:1fa:1be4:1e48 with SMTP id d9443c01a7336-2037ee28d69mr115710795ad.11.1724563016984; Sat, 24 Aug 2024 22:16:56 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:56 -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 14/17] Input: pxa27x_keypad - use guard notation when acquiring mutex Date: Sat, 24 Aug 2024 22:16:18 -0700 Message-ID: <20240825051627.2848495-15-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_221658_292044_FD0574A9 X-CRM114-Status: GOOD ( 15.55 ) 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/pxa27x_keypad.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/input/keyboard/pxa27x_keypad.c b/drivers/input/keyboard/pxa27x_keypad.c index 3724363d140e..38ec619aa359 100644 --- a/drivers/input/keyboard/pxa27x_keypad.c +++ b/drivers/input/keyboard/pxa27x_keypad.c @@ -682,7 +682,7 @@ static int pxa27x_keypad_resume(struct device *dev) struct platform_device *pdev = to_platform_device(dev); struct pxa27x_keypad *keypad = platform_get_drvdata(pdev); struct input_dev *input_dev = keypad->input_dev; - int ret = 0; + int error; /* * If the keypad is used as wake up source, the clock is not turned @@ -691,19 +691,19 @@ static int pxa27x_keypad_resume(struct device *dev) if (device_may_wakeup(&pdev->dev)) { disable_irq_wake(keypad->irq); } else { - mutex_lock(&input_dev->mutex); + guard(mutex)(&input_dev->mutex); if (input_device_enabled(input_dev)) { /* Enable unit clock */ - ret = clk_prepare_enable(keypad->clk); - if (!ret) - pxa27x_keypad_config(keypad); - } + error = clk_prepare_enable(keypad->clk); + if (error) + return error; - mutex_unlock(&input_dev->mutex); + pxa27x_keypad_config(keypad); + } } - return ret; + return 0; } static DEFINE_SIMPLE_DEV_PM_OPS(pxa27x_keypad_pm_ops, From patchwork Sun Aug 25 05:16: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: 13776685 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 A2F90C5321E for ; Sun, 25 Aug 2024 05:26:30 +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=TIA6h/0y/Yz1gsinooJtctLwNKMffY0VfmYdSxulMqA=; b=YwkAvxlysCu9kn+xHcMcLIjOUO onfVs6urA/UI0FBEZOO3WzGV6guHyquLHH/gcS+ZYW05lo5oaaUDJeLYZye0MSvry31MEJOTsny8U 4d81mNHvQH9fgOyc1U2BzqPVDRQm34FV/F7spefL5S22NbM39r5u2IZszxNn0F3qf8BQv0ZAsQtgD 62v09xwN6gTl4fmfisWoSljl4eVHaIRefsoLbnoSnZAG+3jddP4agz23qNMn2xVM+j5dOA19zF/sy 6zA2EiGtHzO2eGazhJMPR7BVMkFjxyGsePdy6l6uK0Kk7HHPbgTLRMF4mvyCG7ter8UeHlNztihMK MmCH/Q/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5lc-00000003g4A-11fq; Sun, 25 Aug 2024 05:26:20 +0000 Received: from mail-oa1-x35.google.com ([2001:4860:4864:20::35]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5cZ-00000003dlp-3kkI for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:17:01 +0000 Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-2701824beeeso2600007fac.1 for ; Sat, 24 Aug 2024 22:16:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563018; x=1725167818; 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=TIA6h/0y/Yz1gsinooJtctLwNKMffY0VfmYdSxulMqA=; b=REmkbRuBz9o/yf/aNepcFR9p0/xNZZJXkQEuDVBW3yt9sWkoydT7DzxLokjjq7ofEe nDPUX0nZMJ3LGHtShaR/DnLrwiZ4xkhMjrStbymt2pvI9EONMoWa1Jmsom47LTlN8otM gL//5xW38+fFGk/hXEULCho/EJaYL17JgA6B5xaVvqkBJp0lnhVy5M8fNqQb6omwHHVF LPzlM7qYpy9y7QjCrVrn08DkUt/pT80ZRc/6PQSsORA8cYMaOHQEH6POQca+uSEUT98U mpipupNFTQCIFPvosbx+sX+tZpM6vhacKI8p/4U1vqNZLBVJ1BYRRNXkcoyG58Sni9d+ QchA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563018; x=1725167818; 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=TIA6h/0y/Yz1gsinooJtctLwNKMffY0VfmYdSxulMqA=; b=Y3yvx5zMCLpHTelhG//hNQk9ZRGYNVTzA0oflpry91a49+z+DSfv83pR68qGhvHSUN bZK3EuuyYNSn8QEbPOD1cvBzKEe5HwoNeRAiOSDf0v4IdK8mYZShMDgm/2OBQ5NddUk9 EwaYZx6Vj1C/rjqUU9j0SYnav/GweowTZYjHk4VFJTbTidOWlIKqhnMf9VvOnagd1Y2F uzKdG74nhngpqFca+DVXZ+T+YaKFxPLKoPv/7x2rXI1Y0jfJKGCqBU2cOPGZM5EnalPA cjNL14/1CIzI1KxRq3y7fLp/Ap0/Oel2wAIiCpG22m/BL2DudBjqLs0dEqacojonSWZN LUmA== X-Forwarded-Encrypted: i=1; AJvYcCUTOYjrXREcdYCDlbsZhhEQldjB1FhF67PkHqLPPp7fV4kZJr8r0SD/kaXOv35ROKy0wIZooLaXGpwo0IaUAhXp@lists.infradead.org X-Gm-Message-State: AOJu0YwBO3u0yXbhtAtAQCfsroTKNu55QweSCvS92HfqajxquqDc9Okk cXrakqag2EMR5eUbQe9Z5Immm+vN0hHh9mHhUfpNWoKGVv7qNi/Y X-Google-Smtp-Source: AGHT+IGpby1l5kr49d3Ag7IqPDJ5s1jsbrR0tYx5ZtWy5I5Dnd9r2dAg+L7acAO7bMwntLfgmcpiOw== X-Received: by 2002:a05:6870:548a:b0:26f:e09f:6090 with SMTP id 586e51a60fabf-273e6620ee7mr7487035fac.37.1724563018382; Sat, 24 Aug 2024 22:16:58 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:16:57 -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 15/17] Input: spear-keyboard - use guard notation when acquiring mutex Date: Sat, 24 Aug 2024 22:16:19 -0700 Message-ID: <20240825051627.2848495-16-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_221659_958002_A16490C3 X-CRM114-Status: GOOD ( 12.61 ) 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/spear-keyboard.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/input/keyboard/spear-keyboard.c b/drivers/input/keyboard/spear-keyboard.c index 1df4feb8ba01..2d3f656e59dc 100644 --- a/drivers/input/keyboard/spear-keyboard.c +++ b/drivers/input/keyboard/spear-keyboard.c @@ -274,7 +274,7 @@ static int spear_kbd_suspend(struct device *dev) struct input_dev *input_dev = kbd->input; unsigned int rate = 0, mode_ctl_reg, val; - mutex_lock(&input_dev->mutex); + guard(mutex)(&input_dev->mutex); /* explicitly enable clock as we may program device */ clk_enable(kbd->clk); @@ -315,8 +315,6 @@ static int spear_kbd_suspend(struct device *dev) /* restore previous clk state */ clk_disable(kbd->clk); - mutex_unlock(&input_dev->mutex); - return 0; } @@ -326,7 +324,7 @@ static int spear_kbd_resume(struct device *dev) struct spear_kbd *kbd = platform_get_drvdata(pdev); struct input_dev *input_dev = kbd->input; - mutex_lock(&input_dev->mutex); + guard(mutex)(&input_dev->mutex); if (device_may_wakeup(&pdev->dev)) { if (kbd->irq_wake_enabled) { @@ -342,8 +340,6 @@ static int spear_kbd_resume(struct device *dev) if (input_device_enabled(input_dev)) writel_relaxed(kbd->mode_ctl_reg, kbd->io_base + MODE_CTL_REG); - mutex_unlock(&input_dev->mutex); - return 0; } 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, From patchwork Sun Aug 25 05:16:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13776690 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 667CCC5321E for ; Sun, 25 Aug 2024 05:28:04 +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=iL+2InRXO647WU3Yi34+ctBbVoiJtTYGlGR4qSXeVCA=; b=C/HFMwoaW47I+BrbLdGQbCz/KB dgvzm1EQmL1XksXqhrSX1qh8zzK7qqfvrTxFgl27pIm37LkYIKxd2+h4Nwc3gz+u4WJ+sUdd0l9Jp /zxXz4Ro3qeYw37HiQXE3gN7dgoTKKfdbb5IC9POpIlCR0YNSXkvVmzPaHahNv+F9yyfgvc/CAJv1 7f5dxH0rN0u9OPkqRPwgBU09E3j8ml5ynmstTOjHso839ce+L1hbrsKGDFS2QLbnuFvxrtZt2o/zC 2M2exkC0kACKVMb15o8mFeMbU+fv2c/HXOg6vl1dLfeXZ98EWK3YCbTAqrSeHsvjAKu1dWRYLW79G Gew3NMOQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5n4-00000003gRm-3umW; Sun, 25 Aug 2024 05:27:50 +0000 Received: from mail-oo1-xc2d.google.com ([2607:f8b0:4864:20::c2d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1si5cc-00000003dnF-13BL for linux-arm-kernel@lists.infradead.org; Sun, 25 Aug 2024 05:17:03 +0000 Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-5daa93677e1so2541513eaf.3 for ; Sat, 24 Aug 2024 22:17:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563021; x=1725167821; 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=iL+2InRXO647WU3Yi34+ctBbVoiJtTYGlGR4qSXeVCA=; b=OMKV2PhO4TuAo5boXIkrVcMDMH6cY9C2cs23DqaNKROy2uKysKk080reAQoOvOAwF9 LpdnGCqhi/bdCKLcYd2Z67+fJKrgZeobdnDzUeG9UGYpXAUZ/c14jOZFdEvBchpvyI2E uXKP4Js4Y8acytbPHvzW/XFN6SH8E6VqRyb4YGn3rKNjZ/J1r7uvm9phU6oJhFrzGyrR HvVRV/pdYaT7M4zs7CQYZh+j/7ltoG4f2U+cWPVDyRkJPVkBvQUDlGF/Zu8RSTgv1/qM rKLeG1bMeF1UvSwIzJRAbNu97Zptvp9KawDZBrydWyZ+wFoEULGsmYMk8iHfyEvgDtC2 ptFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724563021; x=1725167821; 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=iL+2InRXO647WU3Yi34+ctBbVoiJtTYGlGR4qSXeVCA=; b=YPAExWpoIvlGysd+dk7geVcm1HSYTWN2OrctnXbc35gjhwJRG9x9tP/8S7C+BhovtO dQ4bzMtK8hyAB/xZWnxgRkXiE+GGVtTSeBxv8UsqJNWVhM0v1/Q74ctUpwVVIs8LJzeY sojHPeziJTJh4jm3VZHSngAdtPbenIX5OAM+6+eenOv9v30bfj4Fcsinqs1aR+u0LtsW /FR+NhcFe/6yzEB7f1edp7Nv0OqCixWhZF9IoYa/XUDBC/75bnr+BIrxRpGq7J3ffEaJ OPg9gpxp51JJesWQTbdi/KkPcN4mE6pPoMSXQkVZ3PTsLLQD+9fNIZ0E3esNj5gRIKUG 6bJA== X-Forwarded-Encrypted: i=1; AJvYcCUNEM0302c1Kw7p1o4EpKiEOC7zOBbciWgTmGZeKKR+S3AEUnTNhgwpiSgjvyyzc5pNupPNV2JJOjnudUzO2lTG@lists.infradead.org X-Gm-Message-State: AOJu0Yw4B2Cl4cUtXcgkLwTGYvNnhsKVewrudy7dpMX8So4Ab43FPsob b1UD2GS53NQHJU/I/1sgeu5qjPNlRq5HyJKs1ar6eXkZslFooo90 X-Google-Smtp-Source: AGHT+IHIrpT9TrF1Y6WIh6M0wyTrLhvKWZg8Ae6gbV2uHoKlDK9dxT5dBqBF7dMmWUdbcIyQW1ik1w== X-Received: by 2002:a05:6808:199a:b0:3d9:3f51:f351 with SMTP id 5614622812f47-3de2a853444mr7501714b6e.11.1724563020952; Sat, 24 Aug 2024 22:17:00 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Aug 2024 22:17:00 -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 17/17] Input: tegra-kbc - use guard notation when acquiring mutex and spinlock Date: Sat, 24 Aug 2024 22:16:21 -0700 Message-ID: <20240825051627.2848495-18-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_221702_313037_8BBF3941 X-CRM114-Status: GOOD ( 15.79 ) 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 locks are released in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov Acked-by: Thierry Reding --- drivers/input/keyboard/tegra-kbc.c | 45 +++++++++++++----------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/drivers/input/keyboard/tegra-kbc.c b/drivers/input/keyboard/tegra-kbc.c index a1765ed8c825..204ba189807e 100644 --- a/drivers/input/keyboard/tegra-kbc.c +++ b/drivers/input/keyboard/tegra-kbc.c @@ -241,11 +241,10 @@ static void tegra_kbc_set_fifo_interrupt(struct tegra_kbc *kbc, bool enable) static void tegra_kbc_keypress_timer(struct timer_list *t) { struct tegra_kbc *kbc = from_timer(kbc, t, timer); - unsigned long flags; u32 val; unsigned int i; - spin_lock_irqsave(&kbc->lock, flags); + guard(spinlock_irqsave)(&kbc->lock); val = (readl(kbc->mmio + KBC_INT_0) >> 4) & 0xf; if (val) { @@ -270,17 +269,14 @@ static void tegra_kbc_keypress_timer(struct timer_list *t) /* All keys are released so enable the keypress interrupt */ tegra_kbc_set_fifo_interrupt(kbc, true); } - - spin_unlock_irqrestore(&kbc->lock, flags); } static irqreturn_t tegra_kbc_isr(int irq, void *args) { struct tegra_kbc *kbc = args; - unsigned long flags; u32 val; - spin_lock_irqsave(&kbc->lock, flags); + guard(spinlock_irqsave)(&kbc->lock); /* * Quickly bail out & reenable interrupts if the fifo threshold @@ -301,8 +297,6 @@ static irqreturn_t tegra_kbc_isr(int irq, void *args) kbc->keypress_caused_wake = true; } - spin_unlock_irqrestore(&kbc->lock, flags); - return IRQ_HANDLED; } @@ -413,14 +407,13 @@ static int tegra_kbc_start(struct tegra_kbc *kbc) static void tegra_kbc_stop(struct tegra_kbc *kbc) { - unsigned long flags; u32 val; - spin_lock_irqsave(&kbc->lock, flags); - val = readl(kbc->mmio + KBC_CONTROL_0); - val &= ~1; - writel(val, kbc->mmio + KBC_CONTROL_0); - spin_unlock_irqrestore(&kbc->lock, flags); + scoped_guard(spinlock_irqsave, &kbc->lock) { + val = readl(kbc->mmio + KBC_CONTROL_0); + val &= ~1; + writel(val, kbc->mmio + KBC_CONTROL_0); + } disable_irq(kbc->irq); del_timer_sync(&kbc->timer); @@ -724,7 +717,8 @@ static int tegra_kbc_suspend(struct device *dev) struct platform_device *pdev = to_platform_device(dev); struct tegra_kbc *kbc = platform_get_drvdata(pdev); - mutex_lock(&kbc->idev->mutex); + guard(mutex)(&kbc->idev->mutex); + if (device_may_wakeup(&pdev->dev)) { disable_irq(kbc->irq); del_timer_sync(&kbc->timer); @@ -747,11 +741,9 @@ static int tegra_kbc_suspend(struct device *dev) tegra_kbc_set_keypress_interrupt(kbc, true); enable_irq(kbc->irq); enable_irq_wake(kbc->irq); - } else { - if (input_device_enabled(kbc->idev)) - tegra_kbc_stop(kbc); + } else if (input_device_enabled(kbc->idev)) { + tegra_kbc_stop(kbc); } - mutex_unlock(&kbc->idev->mutex); return 0; } @@ -760,9 +752,10 @@ static int tegra_kbc_resume(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct tegra_kbc *kbc = platform_get_drvdata(pdev); - int err = 0; + int err; + + guard(mutex)(&kbc->idev->mutex); - mutex_lock(&kbc->idev->mutex); if (device_may_wakeup(&pdev->dev)) { disable_irq_wake(kbc->irq); tegra_kbc_setup_wakekeys(kbc, false); @@ -787,13 +780,13 @@ static int tegra_kbc_resume(struct device *dev) input_report_key(kbc->idev, kbc->wakeup_key, 0); input_sync(kbc->idev); } - } else { - if (input_device_enabled(kbc->idev)) - err = tegra_kbc_start(kbc); + } else if (input_device_enabled(kbc->idev)) { + err = tegra_kbc_start(kbc); + if (err) + return err; } - mutex_unlock(&kbc->idev->mutex); - return err; + return 0; } static DEFINE_SIMPLE_DEV_PM_OPS(tegra_kbc_pm_ops,