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: 13776640 Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B52F28382; Sun, 25 Aug 2024 05:16:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563002; cv=none; b=sQeKMGv9YMCHL0EKXIgmZPLHnxeWkq5qBOuYT2eWCzx8h9TpFp42Ia9QVW/9CtrCuQwvO7/EfUVnve1Ffu/L8fpmwDQRYUK/OBqBJc9nEhxs556RrodOb1An8DW7kRX7YhA+Vws3n5zd2i0iYsuyr+PctlNfZj8kMQJ26KRkUI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563002; c=relaxed/simple; bh=OSk3cuE+1s6/axlkl5Wvob1pSWEblZgOBnVXoaDU3Z8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ksYqVqzOIiOE2dnJpUO+Ob17Xa8pof+blFG7zUZfh2QW3ZReLojXeN1eVQIKNmp0VICNHxL65s9fOga7JJloHxdTzyQkcAn4Ok+WS0zlGMTgXrzmylSmLQIt5LuMnwf5xNM+8PpFSFen8PA5aVZuuhoj9sjva3fTeGB8XjFOAjA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ih9e9nhF; arc=none smtp.client-ip=209.85.160.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ih9e9nhF" Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-2703967b10cso2397246fac.0; 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=vger.kernel.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=Ih9e9nhFoNghFKgVDd3KOC24ec4FdrkVvj0hLEcrHoUnN01joGDF+/mEDRDhoxJsFV jGRWMQI/c1yLvNKSYKcInZlTXx9CmTlJO93BAN1xY4bK8b364J9Y7bQT/7fDm7wz+q1z 9d0oBEfpEI3ah5wVuFfkZB2No32xt7sXQuunGMBoAx6Wts2owOuVSuqJ26mJy6CqPfTI 24kbvUunl5olH9TJDxUcaYEY/suXBAO63uYHXJmVQLn5dY+qbYvG5Q/t8CrU+DuCoi1h AuXVBYVm7vvplwmAVY5mOkxHsCM1PgAxyK/Lg+MfYNCAcOx1W66fAQEstk+DIoIrpnat b51w== 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=R+ss+e/8S9p4IWtoyaaN50+YPJMphGT9ph0YpdaJPulRwWIV91RYc4fxUm2b8o7LHD 1v7PkNa/Z3eOabrAtSwqXFrFL5lMiyn7AsK97ta90v/mMo3u0kTrokEgI0qCEYPCqYum lXnP0VnUp3BSYZHQj5AAzzfIKLuvsF6rBeIzPnaks2H42AzN7aT2M56+q/VlvVKxPURP h0KdErL1RMBHH6aq1Oy/DppZyRyu0i7vYVmMJWpp2xFdu8JuSOjEe/Hx9/CQmbS+Ohfl s/m/kIWeXGY6AagWrSzARGT5nlTtpdQPP+gKeHDE4op9FnVTp1XgMllZwr+Fhyfvvzhb ENXg== X-Forwarded-Encrypted: i=1; AJvYcCWw1Ic2ponYQ9HAjok99Hre32echD08B/UvrrpIsxn4x/uTsRHIlDSiVsBQ/de42F1gLDvsXYTIn1dHUmo=@vger.kernel.org, AJvYcCXIh/nMh8M8wf7EVF877WTNCqQOKyUjfLRGq0NToYJ0t4M/Mbcc5Uizm9w4yJfGwErkFNgsMSu3a8uQIWQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyY6horRlQFyF88Z/2AlEmdEa9rjbjcM0qsdLdci8JtmQt7JTyN sWU5NoYSVV9fL4i6rDNUPUcdLPzshbNNrYOea2yTGCmDOZVvb3Prt4TBZw== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13776641 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 748943987D; Sun, 25 Aug 2024 05:16:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563004; cv=none; b=hes4HCnBboAnbUTJkcR+eo+HupIA62HC8TCond2dgYuzyhQZia+sJ5Rp2zzR1WXW7Gl9+vhCc6jSg6D1WSpTSZen5+DgsHklr40+pqZj099vW/Nz0862d8warMVrLW3ezNBWsmjxW0Wz7LzOZ/ME6xXj0mQnaTf5CQZcaOT6GDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563004; c=relaxed/simple; bh=MsMHIhrTk1gjFRMb90/7beC7gZ6Zim5csgEiyFhf9s4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zi8AaMzLCWsNcVSz3XBhdx/j8CEQX/f/XDGr8lrluDB2BtTi1k5+rQxa0R2+173AGf/kAyeX3ytcBUCTxgj9OAqiSNXRZPR4rpqx6sqBjDVxx1BPLu2eJo8z4satqxAcLN3N7nouQwK2K2uDXAmC0pLozChCmGzmb5T6pFFGHIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Zat+6PSX; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zat+6PSX" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-7141d7b270dso2511502b3a.2; 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=vger.kernel.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=Zat+6PSXFyM9m3wsyVYFvA0ghD3Cw8Gz5JcWthPVq8lL/wLawsnBmHIGDS7+IWY4gU M6n2CEWoS+plzEIy0VSSFlEsw43tuaFZ3xw3JIHn5HpgHh4+bERgavYFBRGfOgS8tCsg BnTwqKIsXfIYPEQvYJJoyaooqDjmpklJbAwTSUUezuEXgxgApbAtN5PQ5YhSKk3Y2Z9q L9+MwVYMuJY9XUqtIyeq0BP4bE3kLLIqUfOBm8YD9PlNxKuEqk5iyBVpGrH/S+4DO5sh 41faqrv/tF/uDlkTjwH0U7juUf+NBPaDrsOhQLsL4M/B1sN1Cq/pJqkGXbCdcB09P3wk h8Dg== 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=sl03y5KIWnOtaaQeS5aMSCvlBRGRJHfD2YoLgKFWOdTIoAA9o3gxLDJgt7uiCsa3kv T9ywtyfiaHA1m7BxfhdY4fz49vQnADkIZd7IIH0XVoRJSeGFfYq+mej/+YXXrz1bkxGl wvmbM5hbO0w2SF66HGVdDIivHu6Lp4i4tb37RFXnCT9qyyEGGXA9v0GMZWjg8JaHo4am Uu2z57iJU4VQxl51kO7SP9xS/Pr/mfel5PgnZQ5kSH3F7PgHMJHDXYRTAkE/MPL043xV stAFWuHhR+vJwFdyeaaCsT/j88CpZfmEF15SlP9a0oOG2NBtbLlzQwtfjgmm4GxEg8ax N/nw== X-Forwarded-Encrypted: i=1; AJvYcCV0drbk26N0tJj6TUxYt3dWsGy4p3f12j1vaw0/QNFsHrSgKiUp6NyPzP8DTMsPtxKt8F9BqIB0/CR7WeE=@vger.kernel.org, AJvYcCW+hPH/KuGAw6pA15Pshxb4Z9TD/paXAUNzDXti1ZUwFG7QyvXfY7YKRqM/uTva4FHkb+Gev7XA2w9RUAU=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/GJGodSiYF3tG7qmwQtRBpagOZuLEGnwqS7ruP1eTnA59to2Q D1t2pK/mkj56QG6o5TvWNTSIc1SXIZV3njvyhuzVu4P/9ddJJeo+TNrksw== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13776642 Received: from mail-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 015D83EA9A; Sun, 25 Aug 2024 05:16:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563005; cv=none; b=dlu6ShlI6AIzN5avq5N/mtt9jfoQHxhvqeVRshHze5f71eEXVXqJ22/YIj2VDgTR/xyw48nMDMxtwggi5fn/5KeAbnyZuhc/So3nTB6JHJJXrDLyPl0+M+71j68TlV7CtaypTszDmmFBGohtOEhMNluxBfE2QMJikXNtf0A0lUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563005; c=relaxed/simple; bh=4KWBfDBADpELKklAMQgXyKS3im5Vr3TIuW41bJymLjM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jXYylF7BF3r51aX7MG2PZGsQEOoq1fKsb1gkt9OQMU23C3ZGDrDt7g5r2NtcmQXZkdte+hBh745Ssfvy9cROdX8C+o7uY8wnPOhxvWJ+OvH3wXzTJ1zGA52wlka5g38AGN2gL/3md2ox6F8cMOTlaPgZUprOnbbD4zc3UZN7e6M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YWEUDYQA; arc=none smtp.client-ip=209.85.160.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YWEUDYQA" Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-2702ed1054fso2521854fac.3; 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=vger.kernel.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=YWEUDYQAIFBC68Vtixqvfl1Q5v+vsGXAWNT7EFmPxoP2OYTkNKncr1I3R4bCx4Boj2 a0S1BT04MyLvAtcVJqvmKraSBpJHEFba/4v4zQwwozPljGIuaZfB2wTLDmyvVmqlqjja GKsUTv77y7xh5vYOPHP+6BFV7K65+5Lj4Kv/QCQBOUtuhCJfRccDd7j7Dv2izha5FtCo iBk/u9g984S6jiAVvt90SZcuxr+l2PR+sksOPBKrLHaeYuaWbGgYChcZ0QBMTh8ocJMc Py0WjGa3VDoEfTChqnqkPU36REclznxl7vhTQHlIWOaW4FugYz5jlL7Du+4HPctUdlTv WqBg== 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=YEhUADXaeIFg6iHUw/lqsEP0W4nRF5D3wNNfuTGAl1TAqB8ectogqJjkNkFhAzb+ta uq6v64vyJprlILsnrDpnVWb/x4M9HjaJ04OU/4IjHoYIjLTAZElC83KjLKrCjvzXbHWu cSd+jDdEJGY0y8OD+1dKSDEWjGcGrPH8kh/EsJCoTarFc3s+9LzMPBrikTPUDyHlKeFp DuEnNEMOJjI6BBxvxb5Q2CdBeC4X2P2AiWfhSIpNxu8srRnMJ05pnqxmhApvP0bKuhoT P+1v9oEvPGUKKMp4EgOMZzT+uZmxRpUvvIkoIcyymRAV2xv9AJ4mpXyE+0yG5Uqct8cv FUwQ== X-Forwarded-Encrypted: i=1; AJvYcCUQm/Voo65F/iDNEq4UsCmgHMCwsQerMKlQ49HssrW0tjJ6W9EgEVtLX9AuKfrFlR4K5OejpUdKhpCE1So=@vger.kernel.org, AJvYcCV1C2hncA4yiImZJ73HOgwgam16hiwwwN8bvxnpfSrIYqnjj3oCvVHvlMvLw4D8hiWXDLRJjoHip16+0Lk=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1nU31mK2zGC+tu8DIzHCqIn1D5kMvOZzMdywCT6P8VZjSaNSg dpfoR6Whzhu7N2Jil/ojJ9CVEEK0hY1838kDgbLvkt2nhxy5P/DQWRHjLw== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13776643 Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54FF43308A; Sun, 25 Aug 2024 05:16:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563006; cv=none; b=WvLfAm+RaBYiwt+0D5xZ3kdSCH+/ZW/qbw0npdVVwJTKfffBMvcSoKZo8itStS+vcNYFaUPf2V4jRH/KqWbZzYwRZl1fQAkiiFWIQwxZmlIJtalnUtNjr3bcEN14Iia5+q89KKf+Lv4XT78ayWGEOq43BDlXTAfid2YqB1IBRc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563006; c=relaxed/simple; bh=QuTUzvL0NRGEdr7cl4+DB5x/Lu/7uSJ/TteYcsbBaMU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kvvdeo2AVs9GK+ivVkRq7BxJ2La6zkKDuxwiLNklhkSYrZamXLwEIbLdORibH1X+QuphN6bNORptdwkpvETVkpbYyvwf0Ucg8JF2GnVdVvDPUkwD7PkcCdmcyPKCBl9wfe2aLaSUgMbjGR1cUmqAI3fJUzrB8fqdx/yfsGdVhIQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OVxVBhKP; arc=none smtp.client-ip=209.85.210.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OVxVBhKP" Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-7094468d392so2671528a34.0; 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=vger.kernel.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=OVxVBhKPRAndiMzYXArVerrajLNcMF7V3omucrU01/qyuAnpp0YmUZxzCZGhgxqF5B iAGdH/DblbVtQ9l+CoaPom/Uy+z8i9R4zNxgMvCtGrLpy10N3lZjukIMKziKrh5ZVCMU sVrHEtNkK+d3XJonQxTduONTgPAjnvY4mtYKYN0Vb+H/gVTKUWwWhZFfl31ZK/NLNPxI kNs1JpdXCtt89JNVGb6JqwBfRdiiqd+b5WOYsXBibI3sNay6LpH5/fQgM/U8ZhLST9ry uQcn5aZ+trDen8gqfh31LlAKMMZxQDADEDEsuhH8zswBpCe6chfBwmy/uzgVQhosAsh/ 30IA== 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=wXmgpdl4Oo91bNes+veoIoItPzifzvKuO9P8Xcxg+o04BOxlPSshPbb9uOiJC7Bz4Y d8QehhroCzam32BgkwnLUXWCS3hUAWjT+TFR8XDnNjeCkM+UVHvo3OR3AojGZL4faq3L nt7LaOF+9ZE0Kq6DXI6WDAo1Qo9yIn2knr0VZe1K1ssqZHMwl2di8vY3M4mhuM1Z8s5n nCuGsJoisMBqN/ynl5/xLa/SSylmnPAvNMfDPhOox2qCsCfEk57omLp0ZVijErcmDrTU 6szzmFaaXd4un6EGc6UoDx5VsUpuNxShPXxJUBzm81P89xxJvAUpvSOEbxr97wpV2yIi 8W5g== X-Forwarded-Encrypted: i=1; AJvYcCUK97tNBObbrZrwoocTVF7MjdNAnk8Adc0mf+x6Hyu0hXOhnW9zrEXIGsD3LBeblY4fVzi0+urAU51+4DQ=@vger.kernel.org, AJvYcCW0to6r36GUIyhRM4YcLpLLFZ/zINrf23TU+9JMiTIUGVSynxJLZEbiJUnfdIDJG5eBzpRYncRgLeFMavw=@vger.kernel.org X-Gm-Message-State: AOJu0Yy90rygv7YrI13jrv4Zd65ssU0kQxqSKQEnqFRNEocC5wUgNWRh 6KuOI4x3GZ5phlePn9gIn0XSM6YaXgFllBm0EugWHDuo9XB4+cv7iMx+5g== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13776644 Received: from mail-oa1-f47.google.com (mail-oa1-f47.google.com [209.85.160.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CC2757CBB; Sun, 25 Aug 2024 05:16:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563008; cv=none; b=hdHDq7EF1xPAw/FzfWMUyUvuOwd+40dBHQg6d9+KBkRVAut3KSNdJf7TRadPW7o/Nixu9j3hvbEKAkm+xoVEPqQbZlXMKmBMjs8gSPf0aHIu6nDYkv0j5oBukq4MxYAXjnGK/DCjGM+m1JAxTKJe8HTrJ2kppC+L40a5Ttu/hhM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563008; c=relaxed/simple; bh=qDiIvliRjSEpEOJTrSaZM7tuLe4Z9lw1T0mNPAza15E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UEU5AoKGmLkDQ5xVrPRKjcy1pQftHZwWscIzef9AVWj2n40k19C20Bx07DPZKDyjDSahnwksza4nxoRZG4+oUaPvVQuav0EXblkGF9/eZVWZDP9mgZryHzlVKy8ObcMSlLPTQCmoaS1ZGBJKFLiRsML/3gotkCj4DL4HN8NatHI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Fl7i8zg3; arc=none smtp.client-ip=209.85.160.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Fl7i8zg3" Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-27046394c9bso2451051fac.2; 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=vger.kernel.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=Fl7i8zg3KQI2Y8TuzKcIYr06xEgtgK1Nru4dDGaaH0/vQJYw2sok0kgqmgsmracK5y N0SD6qnXZ/SjKVBQSF9Ey4DTY3dWbwm+vQCcUoE35TMCx7U9ifMeO00Vl/H8LFrCXvBs 1jq82MgMzUHb7Ospea2dwC7hxUgkoga0LN37GkmeLFmdCVafwYSHZFan28UvoviWjSoa 11zepT/BBqxa2JAYIWeIpPYxtAFgn459EhfXLHBqrW+XEO4ftRY3Xq+8/LfmRnPyhPSl MTIZCrpZjYJSZ+NBssi1K7ymUrn9fQqBdctdXtDH8lfhb7/kyqS4CNfqEvOn1zsuHehS yLAg== 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=m9+Sbi+KDXeg47M6R5XJZ7Kvv1ZvUVHl//CGfyw4KbwERJmUcNuv+EnCOz2Fzydc8o vsKeFOV6nJn+SR76LkIp8xJmPajmhZGus+HpJjGe0tWktpsy/YRu33djhIz51AXKcGwj 0afbvB4dRosGZvAzQ+T3MIUATLdG4lyG09RVvq3j/KRfQ6p7wfjaNJYox2wK6cCFQFK4 u5rQ2YNPUFv0dsgqDdjbVk8n5cdpmDV/pqetL4alrg0adfRT1AZdjRyZAvMJDjmhM2QI xddMLbAvsJ+xTzyBXxWYw6p4SKojEIlsnQMDUGW2DG9rMIztyIbQUh0fzm2z6NuQ5+uS mTbg== X-Forwarded-Encrypted: i=1; AJvYcCUVjLvoBhvOcSd84gZs238T4uHFfRJ57jZeK9YqQAIl2VqiwlSxJi2+6i0+r3knnvLyIFJKM15ljMKWQzw=@vger.kernel.org, AJvYcCW7kdvtpv5uAf4ooJgMmM4K8O5SE/Af03sEYYDsSQGSPmv0SwsxtFGynb1//JkPFOSWibk96smaneFn2GM=@vger.kernel.org X-Gm-Message-State: AOJu0YzW15lCkDmGyMtfG9KvHGRDS5wkf5U6M45hInmNi55/uS/uCrLf B7gDAfLgHZt5h646duT48bycGZK/KaxAWgQ5ob/RTyhiU7kuCf/0viSgKg== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13776645 Received: from mail-il1-f180.google.com (mail-il1-f180.google.com [209.85.166.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FB9F6EB4C; Sun, 25 Aug 2024 05:16:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563009; cv=none; b=dl0J1vgq8e9R3OslBQTnGwyclNSn6XKl+tfnkWuJlm+9K0PAOn2zVH06oPpDrySWy+QBUaa0diYMTlEggjUZzcEzSRXtb7b5r1t1WK5NxrLnT+iphCEN2x0ZY6rkZ55X+Bl1u5pM2uixfLv83tmwOyvsPtZ2PpzhDkd22/M3El4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563009; c=relaxed/simple; bh=wJ0YIbK2Bowe6CEQFFxfyG1unJtNoBYloVGSQaRk9V8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fN9l42fb8IAFUwO8nyg7PynEf3KPrYwOxmdy4lz/UNRwIYnhzN6lUYx+jcELzaLtQnkYHvRVu5D1abt2rxkdeTT+w0z9ymQgNN3rJIQc4nwWBbG+USOUAtmlBnd2iYwRfWjOEjgbx39jfACrGYBNpg4AGpi9EajP+63LBV5CT4c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jeP0EA/O; arc=none smtp.client-ip=209.85.166.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jeP0EA/O" Received: by mail-il1-f180.google.com with SMTP id e9e14a558f8ab-39d311d8091so14036845ab.3; 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=vger.kernel.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=jeP0EA/OT4Yd1Dfp0u6zRMV5XY2o3n8cTDfyJAIfpVktwpZJ9UBKYXYGmbGSO7VBYr fS39gD4QdtVl+0xx5O3aIszq1qSQfh/vyUdq3iP1O6eewjU8ql+RMPQmDep08x9Xm6KP GGWCraztxU7s8mEf+ddwEa6z0RL36LMbfAwDruQolIcP3lBEJPK3RzHFeuR1pTUTSM68 OyGWWJv+tO9WiEitxBCF6zzU1gbdf+VfRQtmDN9pR7JGSd8adNX84/DgSVfhX+wibW5b YjtzePuwdI9AHMxsGOnDm7LYQLSNP6gJRJNbrdz8TlSnh3dox0OIY3IM4b+R6w2J7BAK VH1g== 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=lWRAd/eaU5oPT8zDClVFDQrPHr7HTV4DBXBnqRzLLgz4vTCUBuNxwaYJJ0AwPtL+bU uDGM7SXEsEEvMVeBWRqKMaDh1vNah0BCAQJhuowpo3R+jZ/SfvaeXHufUwc4u7CeaZJc nwISBukUNMvBKOceu3SFC0Y4hLXF2WGqXCY5yDG/OxlsktJQ3cTA5SwkKVudzs/V0lM1 9axJHXe+LHJfnG9X7jzQhCXQtt4u8yDktXz2Wzez+GuYjw4w4CMkCGqSIHYD9eP7+G27 VULBFNAbgb4VLnob4y/EzRyhVp2RIX1zTLGCliqKM9gCrB1qFBncZZZt/sv+QyOojEE4 jyig== X-Forwarded-Encrypted: i=1; AJvYcCWJsFGDkOYWFVNVUSpxwoXA51B1SbPK/gVDwQCAlUr0/xIgjr++8dEoGREPjOqyMcs3gDhE9Kh9bUPkRLY=@vger.kernel.org, AJvYcCXnV1KgdpEVwVPcnBlk6HMCoWbAtoG5nbIkNFEgkr9Lfw3il9Y8NThueXxbq1/BNyJmj4Ku5qBwBB1k4lc=@vger.kernel.org X-Gm-Message-State: AOJu0YzO7Lgdvf2J/qlN3wwgbswxoPdinLjimajaFB5/sTL3SKPs/Osj 2f6Rx1+EuV5CzLEq0t3gyTt28QJcj8+yGw7u0rn3RpAKc65o485pNUmniQ== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13776646 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 141CA770FB; Sun, 25 Aug 2024 05:16:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563010; cv=none; b=kXajDoxjpIkfILyNYtg/oto36gBJoysD1q7WFMpBXjtIRcyocMHYy4LV2a89VgH2xdbvsEVB3cECnTNS0T5ewUZuy3tmMROW4ERpbOzPXxqz/yYFeWql6ZyVokufUOpKjhmkmYVlu6P3B5wpwPQiTX8tAQyX5FpLjbuzBP8hKqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563010; c=relaxed/simple; bh=HRlUPdt8MUpsxTDaTLTMeZFznZxtpdiNcTlI0W/hXq4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iJPA4w022Tsi7nuHSQWhp7KvamV4W15kzw2Dq7AAb3FTnS2OcEARfceNJnizfWsr5jxYOR5nvqmGlR5CRYJKshDWDZbmGuEsIzE5sNCpI3GaeScfHcv2D5zJGpynjF9oGu4mKsXqCP/YBYMaq9FTOTeQ6iC35hVgYcYkaUKNqLw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EOjz1+lQ; arc=none smtp.client-ip=209.85.210.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EOjz1+lQ" Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-709339c91f9so2653229a34.0; Sat, 24 Aug 2024 22:16:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724563008; x=1725167808; darn=vger.kernel.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=EOjz1+lQdqv2OeXLfxmb02AfprzBKOXK5joa8+5+Nr0s+N7UTZA15UdPqWEmEZy+9Q 1rKb/kVRu8iRy7no3d8D0iCZAXXu/f1zcoAyhGsgGrMVhPQUYUhGR162ya6FnrRy14us rpnBgSUqS32hfsCt2Bc3+cbc2QoVv+YPNPBshe7a3o7G+jNiw7R/PTqpsVPrXbcKlS04 Q9hkExDmpuI7FkkcMpr2zYWZ/NDJ+LCLY1JJahgrs+jewuUS7a++N9JpNXoEM6NXM8+c HrHn5ss/4eh5zvda+4Jiqm16gor0wU9JcvdNSteQPlXOCqZD4rPLj+BsFbYwr+o310dD 1fDw== 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=ZccFw4LINflbfnhu6j6dC/AAOn/v3g7m8LmJHX2MYvnk/H+UDk5DdHE1vSZeBqkF58 rj7JV8Ku6qXms0kEId4EuRZd3vPSP/rg5kxKBnHoHM+mx0ZxlZw6htE2cNdXI+/BKlR8 wr87E4zfyFAOQ0hOe+0obwl8/FKOpU/Qdved1NvDn8qNlWhKb5tACSo3YQ7zZbikNr1c 7u8dDUnMKYUQ7ynSXaMsfHShkUSwbIt4V1KvKs/uWZZlfMN7xFuecPuAJ6T9DFOtS1vI 888gOAoCdunxhZTlZo5luZVCpxtj/6xYsMt12DNoLH5TjTqn0Ta0i86xpFq4yAhjXUWO vOmA== X-Forwarded-Encrypted: i=1; AJvYcCUdnMT7tcTl8bpQmAzTk2orNnRYtJeNrpXumgocXl5fh6AZZH7Jkglg0Zz1i4JhztKYDj/uKC9RFswIsEo=@vger.kernel.org, AJvYcCW/PBKX2AmCTjU5zcO4ph4OEMWXoFrSy98Gf/bKNQPxh5DhmFhNLECm6e7zFkyBiUPZWZ+7YZuOH6q1Gek=@vger.kernel.org X-Gm-Message-State: AOJu0YwRQ3NZpeF/jQIEOy/JHlv9+CYH8Db2eG/Qkpp9/+W/EYZLzWhX wMo9hlwlJ10VwzFnIMpufR+R5LX791T8NysEPOdvW5bM3ihGry70nKL0MQ== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13776647 Received: from mail-oa1-f47.google.com (mail-oa1-f47.google.com [209.85.160.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 457E678C93; Sun, 25 Aug 2024 05:16:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563011; cv=none; b=i7FLDd+vPYphqvYaA7cJrC1YxJbmRPqZEa85qX32vDvvHrgbJfW0AVh28U+1xrtPRn2J2U3TI3t6dXhKDzmisSV6h8qkOxYBSU6COdQ+gDoE+2GY6teFkP0nGTAV/7NRvSWULXfD1YO/DaJOIQVws4PG/LF9C/4s6XFPF5rP2hI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563011; c=relaxed/simple; bh=sqiJcekYlNvrERH/iNSK4e0C6d+JRc5y3DgjnZym+KY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tAvyH5fXI+f/ZJd8wsAUlXAEnUiDk/GMKdefTsY3dj/19Zu43BqwGX8axi42gKhp+aiRnJLWeboVyV0W6KV8k7NLJavxh28jLM/WFFx+wb1xMfk2wpCXghafsMYcdceucJvP/bv9W3Vyj53fY9VRAt/AX1sJeEx8eqDyiRH8+EM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=E64TMfDF; arc=none smtp.client-ip=209.85.160.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E64TMfDF" Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-273cf2dbf7dso2260960fac.1; 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=vger.kernel.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=E64TMfDF+Sm5RR13I1VktQC/zvcrh0qIZqGXgdNzK3eqRJNwlvDm1CN1qfsEdjv805 UcO7To85W7j5MB5U4WT0iheb51HPgxyqgZkPrRMMbERXJq5ClE3wG2t3PJmazTYMQUHU BfGV6ct4MSmZMIkJAViwNHLGlFuqvNH07Dlj/OFUNDJ4QgrJJUko6mhpC1CyaWbvl248 uLDCG/qTaaIKUv/vAdPNK3ADj4XAciX28ooarfZOh8BpBnqPOZrxNeVoGpVphehNlrC7 /Avp2ZTZm6WVe9QUv5zyCWmK/JBepyjUjjONCGZusTf7bBf/7GunLL4uD8L5RYVgny0A fcUw== 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=j11EGJMDS5fyem0Y4MYVR5BGTjpLn5gJ8kZA7ZsD923ql7WWIr707r3hKY0SNgFvdo LQjJK1M4CjnlG2edo96yMPAyB6Cm3MWfpk6+X1lbufMFrJrh2iCwsTClquQtwSyWJ/+7 fEDFP12isd+HBpMCoMxo8QMiilNHC3mWsw/GlVs8Mt2qI8MVX/Cqi7+nk4agLFO0ti+Z UPOF4Nlk+92gZykfq+8z5F+El27uXlASiDXQuXt1wIYD0l3iZvCUGmzSHRerBPgdj6c7 jPZxGs2iRrJZPhIK+E+B7FxqSPHPev4j0VeDN8foX+8tCmlls8ZSMpD8AEYl9cdnVhgr TZCg== X-Forwarded-Encrypted: i=1; AJvYcCVElGkKoLPIPRhoG8i2VMf8xLVjIpHoGzujYNaZNeBi7CD/F9jsQj8JGn/l0mmaOBqfx5y/5vxe70j87sQ=@vger.kernel.org, AJvYcCWTJwZISF+cYrgVnNBUvAGteyp4H8x0n4jjDIevRPTzE8obZpqiqZLoCDK8pVWKTO0XNUUuqGVl8bXxfjg=@vger.kernel.org X-Gm-Message-State: AOJu0YzuA+OweMkfEd7Mbg5btuteQ0VfVNiP4vUzVPaCB6IoGCci5Pmm vkcgvFjdtNpa3T4LxuvpUDFwAE2SmqG58hlBJH8WI/4Iq1UIL04qwpUSqA== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13776648 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D57317F7FC; Sun, 25 Aug 2024 05:16:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563013; cv=none; b=oLYUT3QI/ecUIhc3BBdU4xCxy8d7+t51Us8FjzvavUYsnshBc1VgxMK1WFxUZ6OYx87NtRf3T8yFzJSrbDEj5qwjOm7XsxE8npSmdVW4ntDKJKpqcO0QcK/lX2th+vNdA608FH5zgcD8AMlalM1q07s4fAkhYnIHidjU9cgz6QA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563013; c=relaxed/simple; bh=9QH0Z2k1Exe8nRbW09wHzcRQf5tH/6RKlkLk5/+ZLDM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F1Hk4bIMYjkTunbXxSdFxRWQyurfxMVJ7J3RK348i170ckg6dORpPoKYCNOmBYf/KPohuuqQl/luWhH3mJtkJ0p3flosDeIi8fYtjHV8CAs1I6KL7jkPMxXVzpzrUlQd3kgr6I0k/zU31MVAVCPGkt8vznlNAqZqjLaSyQztOd4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nhmQxu2I; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nhmQxu2I" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-714302e7285so2797474b3a.2; 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=vger.kernel.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=nhmQxu2IZqlUWVEZja/FcP6IxxfQC8aFtCdUDEqazlOptNsZ8dTuesJqL9IcGS3zRz ob5CPGzpOWlJDF6tW4A16N1LpjzwHSDEsPwyZVmXtRCjMdbkLCXhIgX/jOAdw0Jk/dcC 4hloWImfwFtmHOm4K7KEIcgFWl8jJ25hQNCPSv15xL7EAuh1oVnSZBJ85nk9xFWSn7fc FAfE1boLKbf4Gg5PCCpVt3nS94e/IZW6D8U197S3oZXbS8Prvd0elPlexyuBhIVxgL4Q Sbd4tHDhSgKveWDJfiy1w4OicyJQRLNOucN0dBwlkOvlVODxEcfefhuOweMl2kiT9KD/ 0mfw== 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=T8rqtk7V7rI4SAWxAogU0pOjah2/Q5ausj/RLeOWVHrzre0ZbIglQO+kzqSt6RsTAl 5GyYuiCGtByB5EVlySGUx8WV5y3hlDUxI/Gel+AhQEl+eVRVQjOZRTLYg41xUEVGZzFf aCquXb3CUJ45+tIvc7IOCOW3QsoC4cav5SNBd+C+SgTJ+4EtLMU40mWa/7++OpqeI+zo gkC7Sr9g17p2ROzQwtQGS4/Cgj0XrWDb353FpKc3QifhN7wVnnQMxymYADdaWKoCGNkw m3uFL402169eKNP/zYSBF6iS+z2Vztgw5r6kWpZ9ISOqd+x0scvr1nrwJPfi0ogcj3p3 ntYA== X-Forwarded-Encrypted: i=1; AJvYcCU8FDPVOutxIXTMJQMxX+nhR3pLbO39UvXxoOytA0rD67gY2/l/kxJCYEJaOkDYGt3JVnajwsP4DGtyhvQ=@vger.kernel.org, AJvYcCXKUpNnUBIgUyIJPJJyjLZBjlm8LWabhSoKF2GGyoiqgnuAaikhH4qOj8fm3aea0wfpfnz4qfFvNPnrCQY=@vger.kernel.org X-Gm-Message-State: AOJu0Yws9mp5uW3ntvTVcC+X4SWyV5wRVvNSjfw1026RPS6p6+Lg0RXJ 06iKoMA3QnsHuAIAJQhMgOvw/LyZuDa2T1A+A+csgUMtJ5/ZmlnRPaztQQ== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13776649 Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA1693C466; Sun, 25 Aug 2024 05:16:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563014; cv=none; b=QFuawjSlNoIqxGXSKIwivbMY0DiSjDydLmPNhGJjNYERYHVVbRzaFSPJvcgyr/w+gkuyzhe7m4t2kiFwjS7w/uoujUoCR3TOVgauJg6nmD4iz8+uWEPTMZOt3k8Absu7Wgn7dcU/lVnWpwIK01vUo20BeOKeC6wQSidr1h20hbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563014; c=relaxed/simple; bh=wNujzFkWY2QRnJ4eoygNvp/2j66nWvzzi/2rJGjoD6c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QEnMr2x+d7TqS54bakSD3CS9bIBNVnWMtI8XyJOVSYEdAv8Rapz8/SGcMfOkI1xt+e0V8om61KYltbV4Dpp5EOxkiIdVDiVP0WF9Ek+fMgpJITy+mkwCHfAZR0iYOI2HHHuvaK5CsoN6MP5SKGCEtyzVvbB8gfTGw5d5v1X6vDw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cH0JcXXb; arc=none smtp.client-ip=209.85.210.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cH0JcXXb" Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-7093c94435bso1933207a34.0; 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=vger.kernel.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=cH0JcXXbV2lvKKho+cCq3ozdf157nleRIP0RYiCoOuBT60yNaEE6roBwp1epEnItWl baoSotLbXupEcw9V9+Hff4D0Qs+jNC1reyYTHL4ok9cXrA0j/pC2P9j7EmgTUWmeY7cB eb5iQNs+5OEiAWlYEgaYdEdlxziIU8MMpz7i6qL1PQgRGHLliikyLDrGzxDRH9RsWDSV FwuQxGgE4M51s5BhElxcHAwet6CTQbDrJnIlcdQf7/vS34NpYYNiwgRpRmpUf1r/dDaC yeTn0HDBeG8BeUAnMNGF4CnplbR3TmINy317BTKOU7GYsE+VKhBEYlfS1K0gDaT/1yjE v3LA== 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=mVAy964Im+CAUrbCcm8wecp8DM0Ncjf6O3mty0gykGD8EGBknPsKrJUyJ2iNzgrbsX CzYyvLa4MtRRTUc1iVK754k0noYsiNcP+2RVGgK73UNpkCBfkBh1ABi8zZdUkBkzxtvv +IOIq5yqHq0UDF95buPYkvekQxL1+W3AV3pzqjH35a4WcB7SAR64VShdPSt2BECbDObY kQlWQ8937oAxGGKDrgiuSlCHt3YHA55buZXhk3Mmmty6fS/YEQtlHIEg+Bb0UIzmH/5Y D6eLY6y3sbCx8HzQJ+gOfr+o68j/B0jXwBTyeQuoT5hsoGRYvkM9+8i0tnziG8r4I5rI 2EfA== X-Forwarded-Encrypted: i=1; AJvYcCVsABSM6KocGKi4C2dYM+NcYsRMm/4m7lWRfTB8HdKBbY+7UHPzEtWNgz6vIqLH9pdFUIN2f1uqsADwNa8=@vger.kernel.org, AJvYcCWbLgxFp/xreBeAc+tbjxaoDt6IxDZAsAuLN/CuTIxkVqgwbkhbPcJo+aIQk5XaRnAX7FtzDAXXvjV815c=@vger.kernel.org X-Gm-Message-State: AOJu0YxQYs4ev8yJ/mqUhu3C6Am5hJy3dYFmysDUNYT1R34rDHwLEbvj tECOf5atXLFP7O2inW/zXRMLcwTOYGkmV1JzDcUOPadaUKQP7YP7cE0e+w== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13776650 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4706382899; Sun, 25 Aug 2024 05:16:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563015; cv=none; b=qQXXQ2qcE+sFE7HK+KUtx6Ep/8MUnXhvm+s8G5L6ptcwv7pioLIUxOkg3ZvzcaAhzODPJ8iCAWDDO7hBZDfsocByJqC2rN9oFnGX29IL5EryKFeOYTd2FeikP4ZZcLlW+jy8nm4lSDxY+LAV6hi8ynQEwo3tJmBr4wd770tIzeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563015; c=relaxed/simple; bh=t69M2XHLck0t1pHwwBsDi+zgTTfrFl42KdqvyDwMG1U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hpjsb4qk9vK/TvMilJf+fPAD3ILrzI7wO4aKGew8RxYpq5h3p9VcCavz6wYW4R6A3ZF5cJdUByUSq2PJLk0vTZ+eEWwNQi6Qk1qw43SaRQ4QSLHTJL/INejJ7M/aakpmqyafq7wZpWVXdUkGCaBrTxHUJNZhEO4n2NL/NZd/Et4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UQv5yTJY; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UQv5yTJY" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-7143165f23fso2467553b3a.1; 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=vger.kernel.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=UQv5yTJYa62HeYiH+RLBIZsLnZP79q2INDdxPt9NiRa9jWT1nblCIHnpRaXxK79dwW WaRt/CrMelLBFEy5DJudHXGkwm5lbY4RQBxNnubz49sknRx7puEvZdcwn6O/ymZcTu3B JPTGfwQk5eBruSp5AjgEAMzV0kKYLy7vfuUmhJLcwrPBrcN4Jyy+1czvMyQ0txUKmmMg yJ/LUrXlK6yfbxA4JqJnpKlej3kfjcRIdcJiypJXxdr0Dy0uQll/VLQS3wJXLuP6MC47 oqiemt2NpBiyKhcR07x2wm8WYQ27kzPl/flZgT98NywoYcv2HbDF/779v72dn1XJQget vc9A== 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=kR+Bz3SI2RUsLdxG/WYVYPrT2+g/TcjHm5Ko9tHNYVltOc3KO6YpNQ2F5GkzBr6h0P qA22hjrbkGDd3DLRLidsuYsmBHSbKsEoNnkMx7LHOuWEc0Y/dpRlXXh4RKWBi7ZoNoNv IqkTrnIb39HVsVM52g1BLUU7OkpZPOvk0P24hL0oD1PtiwhsLbMVFQq1saKi4SybOIa4 9xcrEKNqjNYYjV/Y1XzSCJ1kajPLx0vcKM11j7h/tUoeLTA6ZYHJfiM6okXBAGDUxPaT ZwCUTqlxgCrW30qH6bT+7n6SXOj9YV7gijTR7X4/WfpWOlBUQEZOxvHFf1Zhy/9mwrao YTTQ== X-Forwarded-Encrypted: i=1; AJvYcCVTNE6SRB4eAHxWX3qXia4uP+ZV1JV2YCmytPlE+vwhg11nLkM2HBCHzTOpEa/8ojvlSIwCTDwqm/y+6SY=@vger.kernel.org, AJvYcCXRvMrMvTfQ8UpyOoBhHo5/55M9Az60jHQq/ol+UJp/+9mpy5SSSKPTmf88/a+rBZMg6JkuSHtnUojrQSs=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9uGuOgJYRtQ8HoMCkgYO9xVxwN3pGDjx5hFy3+r/kNeUGTzqI AWZrgGkvQOlhi4Dz+o3tA+jDShlTybI7qmwY5wVHNi9icolBZuBE8vGUew== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13776651 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 623FA84A22; Sun, 25 Aug 2024 05:16:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563016; cv=none; b=kxrk9cwPUmZxx16UafTnByX8KXePLjbvKgGyDukk40o5t+lEM0WDckp9F6tWunvyNgWM26GoX1NQxyfSaIALbeGOZ1P1L7iExAXZn3qeDVai9mz7M00QRTpncI+ypAJnr6A4O4MZeKDRFjZdDvLQrZQzvtbc0KZ122aDkUFgkPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563016; c=relaxed/simple; bh=2WGS4zDij+Ixhpcdfhz854o1PCDNzbO0tvum2hvSOgo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XJPhMTLx/wUJPz5AxsCvR3JBnUBVDKKtvqkanHCUlt/uvPpa3ZfcTwZGXb0YjG7d4myTKnSiotWIBcafsodBk44UrOv6tdvk5dQapQpDilgS6Vqvd/JO3zxG7x/6X+mShiHRUIT6kTtz2pE6X2oeFeNdyeHD6djnl1/LFFr6S6M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kl6vJEcg; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kl6vJEcg" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-7142e002aceso2659942b3a.2; 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=vger.kernel.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=kl6vJEcgsVCFbDmEo2paVNJZss7mW81rcyrWJpnjDbHdBViPykRw4MAtMaIgFn42+K W6h11b8TJp1EeKqLn8icZOFbeNXX7NivWQnyfGwRhGO/0IzGF1Jv0JLRQpDncWIt5tMe DjOsXSBWdf3ulpVq6c1+CB/jplQrk2YK0Ds/+mBQm/Cv1QhB9NVTzNAvw/YOYcIp22Fl MqYtvfzOeQPfGGReuyHfjdKhcAqM/5iJTSMkloKj/lta5KsoiTyCdDIVvWHz9rTbVHPM T+s5vS5szTDueN1DxrMjOH/5i8VuJOKbXJNOHojIaqTqGfn/GqftBcLW0IcRieRWKOOR oDtA== 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=V/ntkCyVoBcAUsDoHrW/8koFIV23ddtQaUzsocJgVjNVMM8KJ19XgvQAthrF1QrAkU F62Lgf7VNT6QQSzvNVY9eVzSVEq30bQ4/WiKxv1GsccpcCNnb8S5o32hsxPGnz9dZ/Ue TLG7WtjSgE2GQLwpcE1hxz8UHOQn3/WtiNq9j692WH5Xpv/DJQvf5gpzkUEFVGTfKcT3 unsV1oUXLQxrNTHTDYIM6zti1NOMC0Mp+n5H3+myGflB1Cz4uPQbP72P/Dm/WQCJh8OJ cuWsscFpUvVbAk8QVaKNXDoP6H6xFIyFWFQcHVGWT3SiFmYIyEGeOPNVlL8AkZRgg5od pjHw== X-Forwarded-Encrypted: i=1; AJvYcCVPrjcehAGqWTSxJu72vfZdcg3LpWv9pRd3e/WThe9wdhzwxMaHf6QquYde+dRMI6dB1XTp8Ldw9hcrztg=@vger.kernel.org, AJvYcCVosHi7oMLqu6h3L0eSSU6vLU0MZNzmL5O7O3brf6Zn+CWrUzaEu5leR6RmEfvYyHuewiGejGf7+WK9OQc=@vger.kernel.org X-Gm-Message-State: AOJu0YwC7qper4uANrYcQU5hKehVHN7eHOgQm6eKWXC7C8gKr7mAM+YJ 7Rln5YpNXGxCc5iRdO19EsKZPoMWXAA5DmD5EPwxtGL34dz2X0ZiZ8Lxcg== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13776652 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A982985931; Sun, 25 Aug 2024 05:16:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563018; cv=none; b=ScnfdwgqtaiJZeQzy30nXq4TeDSPTTY6YCaB5ssEhUHXh7yqv3M+OkpZrzuYsxsb2We+wKzuHU9+6zceEoKO0m4tTl7yE265eH3bYaw5hVt60TpUeAf4707SAgNvA7VP37Bt1OCysdRd08rbVAHiC6GC0xfPUvwZIUQgieSyf5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563018; c=relaxed/simple; bh=8u/RKtoqbxN7uxSrDW1oudpA5Vw4YPRdgvHxBWSbWZU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aeTDG+sToIgKxAmEgdSkcnNEDzTX56jbbL0yAAU3IADmEa8+SN4fKhtMIzdsSzxIIUKbvQm/xBTZje80LjSa4iAVXEIVnU/GT8udIqnzYV58SQfupe7A5Ja3tcDuvfUScLeVh4/kexyLPnpBkylT8tpFkj3TM5Jh5+yCWjyyR/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GsUVSO+Z; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GsUVSO+Z" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-71430e7eaf8so2512896b3a.1; 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=vger.kernel.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=GsUVSO+ZdkLLpifLfO5I0HQXEi2eNjiPD5NmuHHM72d+D+gF7JIWzZTO5itJb+Lcrr +ypy3fgKzDB/A7XSONRqalRGtowZC3SRd24uHyfgkcOtzgM3KjWgOCnD8f1UTll9mpOC wZ4lYJyqYhCSn+lMVcD/hRLMbdouxDGjRShopUYi00ZqZxMhuaexOZZHZygWhshE5uuJ 9gc9RbGQwfnrc70rqO5q7ZSETK8jCq/dvwE/qJ8CQAQmSvSXtVAiT+WQ5a5hked3mNkf aMvIJ64RC6CLdFl4eWeLgQK8pxorsfi6np9YhjTXxjbuCd+bQSjqSB4Zq2zEK3kTsxFK QYaw== 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=FHAYbtd+HxmQaAJEgGEGDM0KLthdISFQKVNqhi/xJZ9YYIIGyqLgzKkqbmhU6/6CG4 9BxSiPimvwag69dxySoR9OOxx3aHwZjYvBYyF1czD/TnLpVvvYkvgcJ3ie43xA3A5deH HERnt0vqkMNCMBPSHLVsRkNyL702JfgKI6/7HSHtvyHwfcSw+MLfz7LjsEvexbORfR4M V6qHbVfwH21KPqvjORZakhYcDdQyf3cciv1nRFTtRTIZyIPNTkVbz9zBbGKzVNPYWuEN wXaxByYGW9r6/JUIS7tdUkiS2SFFjnEsvdqg12mxUFXFA1bniLSE1+TmxFs4zmco9+58 VY1g== X-Forwarded-Encrypted: i=1; AJvYcCWyBoazg1RDToGCURmDZvIJ3KofbhWBfa1M+ARek9ErzE451r7oTpsPTTMHpy8cY1UM+uEY5Dn2sqOU83E=@vger.kernel.org, AJvYcCX8kA7HhgXZ8p+nCF2ksL8fgB83e2Ppwtg2wjLmguCzBUfwtgxCNL5HrYXNo8k5l2QzT9ReLeq53lIShus=@vger.kernel.org X-Gm-Message-State: AOJu0YwByrVbelQ3K2tR7lOGpdJ+VEHL1DdaD2QDRL+hmI+YWiLKa03q tMgncugJMG+NaBXKu48aE9LlsklXvlsuPPb4FFFJdD5Eig+lVyjXCdSVow== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13776653 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11C2E3C466; Sun, 25 Aug 2024 05:16:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563019; cv=none; b=FE92Tr0/+BIPTgrgPGSxGfEhJYz4WjzthVbTLp2Dk2tFkYEgYAfn6PPk1pzANvCllAggS2GXuiiPI4rP7v/eoshe/tMwXYSpexAvKMVtBOXT3lDcAFR57BpAlPR4Qjden4tORXBm3f2SMuUp8Wj7ZE3uCqN9IX/7vF2N9Uat0RU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563019; c=relaxed/simple; bh=Pv/v6XA5FLvxkcuQkdC8NGA83UZemTXDDXhaA5ziTec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bngRzu/yEnJ9I/qqnmpCiMSlHrBPKdpRbBiNP2aA2dV+wTS7ySdrrOzIxix6R04cOp/gzwxeaLIr7TI/Q2a+6mT/spB2LtNLtSb632yk0bfmB/dvdp21+vD4r+EQmC/pvRHMqrjSQ+Hfibst7KzsGUK0OOH2CtiSAML84yYSonA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YjDzNU43; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YjDzNU43" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2021c03c13aso24234095ad.1; 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=vger.kernel.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=YjDzNU43bVM6107yn09oqkjQMLLw7K9ASQmVYKswPe40A3Soo8HQQC3pDrtxlUpcRl W+g/rNTFlGmXC+tKFEsAxeLz06c/XdCL0XKxr1nZNbhjfCjqG+Wb72tJP2SbDAItZQ1n YmrNd1GzUwu1qd5n/0YyLYX2XKKFb2Xqi37SCl4famrxcoLTt86cr+eseE1g7FLb7NBH kPpSI/6V/8eE/gR93JbHflyadHiFQ34jGyI+dvwGADhJ8FepfX18JgV/tROW9Q56nHjy 50HmOy/ejqMDPSiBB6H3Md8E3Gc4ERb4GlgIppMvr4fcltdipSiJX44262BgTmakSZeT zeEw== 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=oKZctDGIfBu1aUyK0NwkGSN3ay3wgi5pnS29aqMCCARp0galY0uPR4zmjjhV6TdunF izqnsjCqezzkSnPsRLrP4QHQP92hqF3xmaxs8MOAAHAf89lzRmjrnMdsTUPnkg0nIELS dW4VSMRf182sefzzh/BtQDnVsLHCbikAWVlcJMja4JjjE05tWWeWRgOWPBHgaU5jNCKG uGJc23KWQZROyrpnvDp1zMk4jd5IlmEm3l2pzkBsxZLxxg1tAivpx+PA+Nrj1nelS30t PV/AI52ZV5f0iB1LCi9wSyNSpuYJTsVH37StjXnHDrQk9lt8qHZR2YK1zR/dZEpJ5yYq iF0g== X-Forwarded-Encrypted: i=1; AJvYcCVdZJu2Bfd8cPMr4GOsBaWAaRzdSogFpUIqy5BuWRXVEkmVyVhdz+LUaMja2DCcngLVCS+/d4UJsZM3WkY=@vger.kernel.org, AJvYcCWa0Ph0oSGlVVAhMsa0XZikWXXhGoFrvDwnzFZyD6ltHnPsTq079Jkul2blqnzWpDOuM36kmtELC3oKCfc=@vger.kernel.org X-Gm-Message-State: AOJu0YxrBb7jPGzeHcuysyoMlSnqPpfPTa6kvdlLEFonHXoDFlQ3XOo7 StreEob4OswgQflbOsJsO0PqxC0OuqjsVEYeHmAuJgCy6wyTJJCUxayVNQ== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13776655 Received: from mail-oa1-f49.google.com (mail-oa1-f49.google.com [209.85.160.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F7A91369BC; Sun, 25 Aug 2024 05:16:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563022; cv=none; b=Si7nBrevrxVslNfQgb3sViCX+QPonX8OulthGpxeIr1BOasP937sHpiIVne+e5dHiSDWbqrWT4pJt948G7+hIurYIcq7SuutRtzuNLYrZup1jnuKyjG5KxUwTTRN6ONvh+i+VjrDmWdi3a+Zp96qqSClOJmarpTre/L3g9PrXB0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563022; c=relaxed/simple; bh=jwVJzglfziH/nV1kcY0Uo3ZHM0I6kZU1L/m/bOzcWFo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A4pUvCPlF6H5loxsYf5XyGuW/n6RfYiaJMf2pb3rYcndaym8Z+d9MTQ4q/0xbW7chjGkLXHQv8higZQAE1/+NBsG5kernvKTgh9QRkaHdcScCLVHapVq1tSkNfZJzlN5OtxWrBROedGQh2Ak2yFMkEVrxag9ELwTpiwhKcx22i0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IxLG+lpT; arc=none smtp.client-ip=209.85.160.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IxLG+lpT" Received: by mail-oa1-f49.google.com with SMTP id 586e51a60fabf-27022a3536dso2500625fac.2; 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=vger.kernel.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=IxLG+lpTWU5BUWhhQP73JYz8ObqBEVukJhldiZXlnPBRWoEWcEreCB0g8zKWr2IQ4h xn9QcBKuwXFiah8xkvdp4Tq+Re7hJ77T0op6f/QSxrOaTTBoXu5eYHda8p3nBRDzS0dM jbdzic3pU1djenBpx6PwtiDQPeiJWEwaLhdiccRUgXxlsawZ3JVSNWcM32I/zDLp4xoP 3blw8dy/1iK6eVoSiziUEWbJAmc3Qxdaidn4CirRTfOJUo6rdNcrhT6QBEQUjRDCuRgR 9qAoIG7jRpctqoYlN1/zyWGjRWDpQCFxf97roTBcbCaYjm3rVPxNHajtwv7A0jlMbSky 0I1Q== 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=nnvko0+2npddzLESQB/kDEJgbpQT9YVTW9oG1xj4gmMQyaNZHj0NbHG6wVYNulJvcp HKXZgieLSW0DQSdtKwBgKJ3OaJBTAJ4EZKDPtgzGXABiCLu8SKGka2laKKQ2PbLQ5rjD tTe3FWaISZYLOdBadpasGisA3DdhW/lCy8kmoHJal4M3No2trWmzhdqNkzU21Y8wzMtv q+rbPvedaPMU+fCc7fEnfItTAKx37Z9orFPcoQD2rqRQP0dKqwT3zjsm9rQySLpCCujI oBlyNIQCUoR29ILsN16M5HmlF67m+y1WaxUwDyBpWdypHC0R+LeK1l5heOcaOsATBLQz A/mw== X-Forwarded-Encrypted: i=1; AJvYcCVrXe2UVradkWV/31T82WiMfIdzfELnYmtSac7q+KUYLavXVi4PSzNvBfK4gyEIvYtyecGLZeK3dBH+px0=@vger.kernel.org, AJvYcCXwBHjes4YEMIcs3FrPprQGMHhqwow5p0/VKeAJ6ehNN/Sy8vM+RniXlTXubOVea2GkCESAmXenvgZCTD8=@vger.kernel.org X-Gm-Message-State: AOJu0Yyk6PkGCgrUJdYkQLyat/inf5zoL9yUa1TH3xh9wkOLByKl/MPX u2XS3QJv/DfScMIAznwcxB3WhrJicudJJUhm1V01WXjxDxeRICU1j6b9sA== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13776654 Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCF7B13A3F0; Sun, 25 Aug 2024 05:17:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563022; cv=none; b=Kd+2Tqu7NJt2/G2u15riQhkhyd6tLIMPgDjFXileVDzolvTWW7ur6kisB/T0RXpGt4AA+/FBT5EhDbJsyNyi5fvsJC7sq1hELHqXaADUHKOG0xGdLpq0k9H0X5eok/1ogUBE1b6TnN0zR68JLT+heb+7F22y4C1d3aMEZBr+eO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563022; c=relaxed/simple; bh=IrS48fhMXQ2EQDYHGq/C0cKMwPzDtqfAfI1Zv8GuGP0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MGMWIgtKIQAxAlE/CFgKmITZYV+3r5NuEcMMOFQTaJsg+adwAVlcloDthK/1/8nF65ZQia6cF16L3kuetqNlDEuXFeBNanr9a/AeKbRDapomw16TRIzuVqxjtzWSGWQ8AC9n8Oxg1nWSeAe7LUD/2yBbqg9EkKD3hXsjDfw55Xc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=W0Z66uEw; arc=none smtp.client-ip=209.85.161.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W0Z66uEw" Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-5dcd8403656so965790eaf.1; 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=vger.kernel.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=W0Z66uEwZC+qrLjUnM73suTAleI1duNUKlPO+jhot8S0z7a212rS50vnnqaljgc4oY 92L7cRdczYOXovlRFjZeRmerlQaCqYiPAUkf8+2JSfCwjUm9Dd3WUs4OS6fQO9mGYj7y xxjiFkEHoMzn4PXLGG8IeMd1rVtHBBnl5OuPOfUqrCqwtaxhFGkJd3xlbvtSHTJkDRut ZeUWvFoEtXAgZKPoppMI1JbEguQu4qVGAUVfpdC0c+maM8tLkZGkXXVA9xEo+1QgtlXW JsE/KSvmGAnrMXq5PHQLmGYw5V7eiFu/Swi6ttY7rOuDs5rSxhwhmJH+x15lXcRlrgV3 0Y0w== 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=h6kOvGittYmgZ+lzXHMtB5vWFdLoEtxPjHeMD8ILFDbpW3WvZYl31mT/z5xZKnqd6Z BlNlkwBgRegyyKUmqWzZni3tCYd8JQ+i5Q4FmkID+zYpJi+4pFBfKJIHfn3y3R3uykhq XbLEX7d2HNS1AvM6hG9bDcZhnYg0CbTK7AVSJF9Sy5JOvGY2CUOhDW49FRZ+Q7XQKd3S DQq1cVBZxSNfiKKEuYEbcjxMQPsJyVIj/HuZTAe3LxjSMU10T4gd2tKii1GtgUM85hbp Y7Thd4OETR1tA8Gu3X7ujKXRxjH53qCOB/DQbLWT6ARWcpfZ8bU2Zez6nMypGv+s8zLX rDsw== X-Forwarded-Encrypted: i=1; AJvYcCXpreuBQr/ztIuBV7vjmyuLtXnkbtcZgaiqIK/GqnF3GG7W5LvsUd9kBsNFAxMiqsn6ougwvWdD8YGI49s=@vger.kernel.org, AJvYcCXwlYMxWe/ZsiDTmn8RdOVCs5ZU9WBKtG/5CMC/zCqEfBK8HqpTcvRUlSzvfYhooVlWsuy0/b5y9y52CMk=@vger.kernel.org X-Gm-Message-State: AOJu0YzQU6QFRlXbZp8mZgOGTsFRxE+vz5Y5nLRRADdO1D/7ZlTXXchN 5s5UWl23hDcm5b6a3RyY58J/XdCNQqFeEiiklA/a1/ythZ1AbDbdrtn0rg== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 13776656 Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 320CA4778C; Sun, 25 Aug 2024 05:17:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563023; cv=none; b=LbaxOekw3ZOfi62Ncam0vVTzbGK5tghdM+WNEOvtVvHGczdGnS4nueSI1a+kGzKpwD5+LrwZE97iE+EpuD0T4kzRFbRX+TjQZHFte2e4yqonmFyUtKSApIRm3cbNXC25UyuXVhjHX04r4SMoQdEooCgEuXhQ9qP9h41B++bSWuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724563023; c=relaxed/simple; bh=yY4ZVaSxsIM1IRldiqRRPie18QZDpDnG/Gx5Op+I8sM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k+cLKGtSOAwjud0R9P9bbl0OmrjnwTwo7D6EuwgjTuRbimJD5YUe30bwCGbfZdjgmD3iEIMr1n0kXjsqLiIGnN4amiIZV/ttT9crBoPnrj+3LeEtDgb8fLtdBKAUf25AZARnfkSgVzOAr4N3s97QP3JnWeimT/raK+CKFZDu+Y0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ky5NFyOy; arc=none smtp.client-ip=209.85.161.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ky5NFyOy" Received: by mail-oo1-f44.google.com with SMTP id 006d021491bc7-5daa93677e1so2541516eaf.3; 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=vger.kernel.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=Ky5NFyOyT5Rs3ZCCPReCy0Q8a1H9MoPC/0KwgZS8O3dXX8/8pErvDUPXot/UbeWgWa Ezh+NsWryoKoPvSp3twIQqs7Ul2M6DOJpFZM9UrR1d0pw5gOPowtp9Ga9J2STMwhwaxU vWPMsk2W1SShX+UWmzIXtDLPrUsoTseOtu6LOLWGh+2MWaaEuKdWczlT5eryfX05/Amy 6jCfA2M+hwubmMkJyXeTSwnam26T8EDdVjxachlwWrh1Knk4XRMeTf8l6rvn8y3agPLa qsjOO0qbwTAWW3E98EXPRPHQJIuI24WcCW4J1NroS94DWAA3yHtcg7Yo8S+t6RE3LlQk R2Sw== 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=glzyEvkTDMDeoFoLvBff4ZZrE8eWwZBziAT1nPmFEUCAm5Bu59gHVpHoq0kLUZ4qyf LyZcfLfx85k/ngcCb8bkKRPWRQa74vbrMrriLtTdcwWFycAoNLkvCqI+Lv1VpDK7H0o9 54NCHBM/qgp5YTJd8oPZSDXEmuuW44tQ1DWd3drBy/qTCKRoJ8hJCCmjusIseQJ5mO82 df1iFmPuaYphT0q9bswyoZDawYNgyc092gM5fbq3MzoqvWdOmy+UXIiHEyeujbmy43w1 6TymS6z3XcLdKMRYfwailgcpTJTL794PDKeoPmC9iQ9l1bQYXz2E+Wyyb8LO9Wcv8LHP YzoA== X-Forwarded-Encrypted: i=1; AJvYcCVcqd6ID+rj6KhBMrc/+k/qc6RH105t1ocpN1sLIsVapF7tE4tC4B84uICtDSMA363GbP5UYor+CZOp/9A=@vger.kernel.org, AJvYcCXcyHhRfKF+LZyqiXIEUA5r1kTPBm/MSTcpoasRKBYw3jVz0Kfvu/f8ZrFuMNctaXrf3Lw4YL6zXl5RR64=@vger.kernel.org X-Gm-Message-State: AOJu0YzpPiRmvAxPoL/fG55etWJbhBmogLoE2jQYMldWorREIHX51OeZ 3m2PZxNOD2GFVBqY/XkKeCIuFMadzDwsQR3HAhAGC86uEAXu/vRzbOKZBw== 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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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,