From patchwork Wed Sep 4 04:42: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: 13789686 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 2B10581AC6; Wed, 4 Sep 2024 04:42:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424976; cv=none; b=BiGJ66KPugP4hsWpPdSx/ZONzB3mCVw2AwOkJ/Y7zWRL3z21dqmYGmBI+lis6pw8VKmwOa8XvV+gMVwaOoQFJwARfN7RmIfFg5FLg7+E2FSBLPlLOTOm3k/FjCB+ISS1C6XBWKT99Q4Be40RseXwggEMJGtBlzjF3F0+xcuciPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424976; c=relaxed/simple; bh=NjT4MvQwByttEN8VVRSC2XF5TVXi28xU8cKD0k0ahyU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ConfKugNBjZ1IFUXeIkVakA3VsbTjj7IMH2UyQ+Q8u44A70UuRYNsLKvaR2cFNS2cFgiOM555vpKbr1gagoQkqRS3Xc5B/JQPz519SeW5gImjFxCr6FtZ5/lxeBhLRRmXwnEF/9LXoCpPyS9pu7dwA7Ud4XelH7LoGF8XWSR+tg= 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=K7CPXjBP; arc=none smtp.client-ip=209.85.214.169 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="K7CPXjBP" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-202508cb8ebso38000665ad.3; Tue, 03 Sep 2024 21:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725424974; x=1726029774; 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=lDbTLvM6j/fXldgZ2pW2080JP3mjLaUhBxwYqY8D4GA=; b=K7CPXjBPQCAZSWfpYefrMbwtvqdo9GUWdS7Et/sJVQaFYggk96IcL0NacjBC6VK8RM 5lapnmBCz2DG9v+Q9BGun97YBj/LweQgtVHOHVnuZWC85cLBHEzzLZRIJ2eUL7WuYN2p VPzQXTnJqfdzO2oNbYu84yGAY2f3dPkncls+HZXW7yUJb9uD9SLfaqAkAKNtI8mQ4uv/ JivLGUe1/2QqZCym6oPSbRugY+pxq/cKXDYHksqgq5pSTSAdZr0YE2DrBSSe2C/27TG0 k758tVTsLw2+Ap9UZ7juSXcyQ1LKZh31oc/CWUCDLWbbrRtVWY683QIv1KuDmnF71wvb jrRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725424974; x=1726029774; 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=lDbTLvM6j/fXldgZ2pW2080JP3mjLaUhBxwYqY8D4GA=; b=Wlu2k0w6TUpG5i6gb0cPjI8fmBeOrTxqo37vbZACMUFLesprT+KCSpmnQhvo+ZibpC nzcquBQK4Spmfz+4HdtpcV0jnGDRbVsdrH6petojGYwOHXQa8SAXURsy44Kjd3zmgyY+ +vFnRe7HOK0C15U5mXg7szflgPjuweYHHdy01yaBtks1ysu8Si1sVfsoQYEuel28ZL8f ca7v/Jr9oItmKFLqL2XLCrlzC+a2IgwLIKqiSsAW/mDqQqrdHNa0tfsEn91m+LfBKVG0 apR94dwhc4EOt4SCx1BNJEM/e7E+X6u10pzw6FrQXPs/rmAoyGm23BerK6XRdmzEvEmP TVzA== X-Forwarded-Encrypted: i=1; AJvYcCWbIrf3hf8eFGbp2zuMVjZ7+Ol6LdjVEESiN48vA7QFlRH9sUIsGBA8ges1bKIMYsrkSuxYht8c8rXkSKo=@vger.kernel.org X-Gm-Message-State: AOJu0YwsgMiLfVbDF4bjp1jThW52pmN8XXkBfb9oLUCpMBDa+YRw1BVK bylAmJXXJkJ+rvjR0Qi4bhVY06DlT5s6e8Xv5hVIJ1u6ybpAIjMiXZdTXw== X-Google-Smtp-Source: AGHT+IHJcwiKdFYmZKy5qiXng/r7t1eytZrl5m4cs0vmg/t3rVxsHeg7bqOfpnL6lEog1Mv6yvwBjA== X-Received: by 2002:a17:902:e741:b0:201:f8b4:3e3c with SMTP id d9443c01a7336-206b7aabc56mr8291685ad.12.1725424973777; Tue, 03 Sep 2024 21:42:53 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae951c13sm5727665ad.103.2024.09.03.21.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:42:53 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 01/22] Input: ad714x - use guard notation when acquiring mutex Date: Tue, 3 Sep 2024 21:42:21 -0700 Message-ID: <20240904044244.1042174-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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: Javier Carrasco --- drivers/input/misc/ad714x.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/input/misc/ad714x.c b/drivers/input/misc/ad714x.c index 1acd8429c56c..d106f37df6bc 100644 --- a/drivers/input/misc/ad714x.c +++ b/drivers/input/misc/ad714x.c @@ -941,7 +941,7 @@ static irqreturn_t ad714x_interrupt_thread(int irq, void *data) struct ad714x_chip *ad714x = data; int i; - mutex_lock(&ad714x->mutex); + guard(mutex)(&ad714x->mutex); ad714x->read(ad714x, STG_LOW_INT_STA_REG, &ad714x->l_state, 3); @@ -954,8 +954,6 @@ static irqreturn_t ad714x_interrupt_thread(int irq, void *data) for (i = 0; i < ad714x->hw->touchpad_num; i++) ad714x_touchpad_state_machine(ad714x, i); - mutex_unlock(&ad714x->mutex); - return IRQ_HANDLED; } @@ -1169,13 +1167,11 @@ static int ad714x_suspend(struct device *dev) dev_dbg(ad714x->dev, "%s enter\n", __func__); - mutex_lock(&ad714x->mutex); + guard(mutex)(&ad714x->mutex); data = ad714x->hw->sys_cfg_reg[AD714X_PWR_CTRL] | 0x3; ad714x->write(ad714x, AD714X_PWR_CTRL, data); - mutex_unlock(&ad714x->mutex); - return 0; } @@ -1184,7 +1180,7 @@ static int ad714x_resume(struct device *dev) struct ad714x_chip *ad714x = dev_get_drvdata(dev); dev_dbg(ad714x->dev, "%s enter\n", __func__); - mutex_lock(&ad714x->mutex); + guard(mutex)(&ad714x->mutex); /* resume to non-shutdown mode */ @@ -1197,8 +1193,6 @@ static int ad714x_resume(struct device *dev) ad714x->read(ad714x, STG_LOW_INT_STA_REG, &ad714x->l_state, 3); - mutex_unlock(&ad714x->mutex); - return 0; } From patchwork Wed Sep 4 04:42:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789687 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.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 2309181741; Wed, 4 Sep 2024 04:43:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424983; cv=none; b=XolQXfRBij10eaaN1C+Lfv18Z3Yee7uFscyqfApd+QO1bEDB73kc3ZPDoG04PBjMpsSNiBOFYSxWdD2OkjB0PgYxxBfDBa2YTqSqsK/Zcvbe3ChNXwzYSfJBmK8F+CHdk+CH8sXhLqxoADbK16BlAATzZ8w3QwbpWkg817gqFAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424983; c=relaxed/simple; bh=tcXR5AGz4pSzTcX36c+o18LWMgynX1S7b5Pv+4NspDs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EuQ18HPOZtjY1DfGsdqZDrBP8DgzUAvcpORfDEcKrtSpLBhWsOu30/qLC6sSv6P+iFjbF794uYwNTj06KZXzEDAU4BxPPkOs1ZBVVURfGQP34NR7AAdguFvAfApVrp2nHciQaGIoIkMGfuA0BcHMI0Z1bAeO7TBauyBUxnWz+0Y= 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=IlmgBfr0; arc=none smtp.client-ip=209.85.215.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="IlmgBfr0" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-70b2421471aso3541989a12.0; Tue, 03 Sep 2024 21:43:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725424981; x=1726029781; 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=t3Pc0eyxDef3P0KBoPUQmWAHpcwzzIPRUi+2W2NqUf4=; b=IlmgBfr0i4pjnE9TmuS4sdmvxrV18LbWX/HsQWI9IeYkqPKb0uvGKL45Y10kZFF4TP ybT13nXk/Ck9FpfjqZHzGsMg5lv+2xQX6N0Tm5r/JPR1y36cx90g5vhYuRAvC4GmWLDB iJkzKNrxYMtwwE2w3K6AcdLnH6pCW0oUKsuiDSqH0sS/9VSONrNsTOkLjMk9Glx7rT/p A+kxOzoger2s5D446/loYlDbq1qJ5QFVSYyt9/VacJQJCRNvNLOU49Rn7AV/cSx2UCka F/eEURLGkGRr66Cd6LzBDXyKem/1Wxw2FgDU8Ru1wYtobz6Itg/hwJX52G3ej/w5eRpV IXjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725424981; x=1726029781; 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=t3Pc0eyxDef3P0KBoPUQmWAHpcwzzIPRUi+2W2NqUf4=; b=W/AJ6zO/a80q6p9lJsv8hcVOUR77RgHv8vc77g1+lt+sCICbE5PXz5OFtdEs41q1q+ iOa3Y/VDCg4AOPQQGmTQVwrsDYBXFkP6SnrvZfSgbTYCxLYBRgXLF37JvkpPGSHhYjIG l6wplHuaQyI7c0tNFeh99rnK/tSej9Tsp4cwNR05Z9hzDyce6Br5kmPgXseIgAecM5TM h6k0NhQ8i8OO3GfoULhRL5143f9Ls+3diKXPbRdof/F+u422GqHez+E1/8a+16qjprgI X8jrOGIT4F/xLgWZRxU+CeyC6cV/zSvez3qKy4JCTnM4rkxccAhQOqTfIQrDCYGStioO tqAQ== X-Forwarded-Encrypted: i=1; AJvYcCV9YGQj/JrAx13vBwvLVQPk1OBnjvHSJlv2HL2RjrQJnx7zY6S2mGYDNGdV0WOYpV4gLPTUWraNjNu4fV4=@vger.kernel.org X-Gm-Message-State: AOJu0YxRmycfnA3mfF7ELiLuO/+pZa/1Tl5GLOr+EU6nRctxAxdgIy8D 52vhHhgfURjfZjVMkqOlW2U0MYwPEoi0rn64sHAyyW2K/J26WnbNLrtRmg== X-Google-Smtp-Source: AGHT+IEzcHcvuKJ++miL0w6S6yT5dQk2bZhueChLCLRI1AK2ZIgPdeH0aB9Muw7TtIDLPGL/5F1h5w== X-Received: by 2002:a05:6a21:918c:b0:1c6:ba9c:5d7b with SMTP id adf61e73a8af0-1ced619532dmr9415520637.23.1725424980869; Tue, 03 Sep 2024 21:43:00 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae951c13sm5727665ad.103.2024.09.03.21.42.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:42:54 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 02/22] Input: ati_remote2 - use guard notation when acquiring mutex Date: Tue, 3 Sep 2024 21:42:22 -0700 Message-ID: <20240904044244.1042174-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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: Javier Carrasco --- drivers/input/misc/ati_remote2.c | 57 +++++++++++--------------------- 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c index 795f69edb4b2..e84649af801d 100644 --- a/drivers/input/misc/ati_remote2.c +++ b/drivers/input/misc/ati_remote2.c @@ -244,29 +244,21 @@ static int ati_remote2_open(struct input_dev *idev) if (r) { dev_err(&ar2->intf[0]->dev, "%s(): usb_autopm_get_interface() = %d\n", __func__, r); - goto fail1; + return r; } - mutex_lock(&ati_remote2_mutex); + scoped_guard(mutex, &ati_remote2_mutex) { + if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) { + r = ati_remote2_submit_urbs(ar2); + if (r) + break; + } - if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) { - r = ati_remote2_submit_urbs(ar2); - if (r) - goto fail2; + ar2->flags |= ATI_REMOTE2_OPENED; } - ar2->flags |= ATI_REMOTE2_OPENED; - - mutex_unlock(&ati_remote2_mutex); - usb_autopm_put_interface(ar2->intf[0]); - return 0; - - fail2: - mutex_unlock(&ati_remote2_mutex); - usb_autopm_put_interface(ar2->intf[0]); - fail1: return r; } @@ -276,14 +268,12 @@ static void ati_remote2_close(struct input_dev *idev) dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); - mutex_lock(&ati_remote2_mutex); + guard(mutex)(&ati_remote2_mutex); if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) ati_remote2_kill_urbs(ar2); ar2->flags &= ~ATI_REMOTE2_OPENED; - - mutex_unlock(&ati_remote2_mutex); } static void ati_remote2_input_mouse(struct ati_remote2 *ar2) @@ -713,16 +703,14 @@ static ssize_t ati_remote2_store_channel_mask(struct device *dev, return r; } - mutex_lock(&ati_remote2_mutex); - - if (mask != ar2->channel_mask) { - r = ati_remote2_setup(ar2, mask); - if (!r) - ar2->channel_mask = mask; + scoped_guard(mutex, &ati_remote2_mutex) { + if (mask != ar2->channel_mask) { + r = ati_remote2_setup(ar2, mask); + if (!r) + ar2->channel_mask = mask; + } } - mutex_unlock(&ati_remote2_mutex); - usb_autopm_put_interface(ar2->intf[0]); return r ? r : count; @@ -892,15 +880,13 @@ static int ati_remote2_suspend(struct usb_interface *interface, dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); - mutex_lock(&ati_remote2_mutex); + guard(mutex)(&ati_remote2_mutex); if (ar2->flags & ATI_REMOTE2_OPENED) ati_remote2_kill_urbs(ar2); ar2->flags |= ATI_REMOTE2_SUSPENDED; - mutex_unlock(&ati_remote2_mutex); - return 0; } @@ -917,7 +903,7 @@ static int ati_remote2_resume(struct usb_interface *interface) dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); - mutex_lock(&ati_remote2_mutex); + guard(mutex)(&ati_remote2_mutex); if (ar2->flags & ATI_REMOTE2_OPENED) r = ati_remote2_submit_urbs(ar2); @@ -925,8 +911,6 @@ static int ati_remote2_resume(struct usb_interface *interface) if (!r) ar2->flags &= ~ATI_REMOTE2_SUSPENDED; - mutex_unlock(&ati_remote2_mutex); - return r; } @@ -943,11 +927,11 @@ static int ati_remote2_reset_resume(struct usb_interface *interface) dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); - mutex_lock(&ati_remote2_mutex); + guard(mutex)(&ati_remote2_mutex); r = ati_remote2_setup(ar2, ar2->channel_mask); if (r) - goto out; + return r; if (ar2->flags & ATI_REMOTE2_OPENED) r = ati_remote2_submit_urbs(ar2); @@ -955,9 +939,6 @@ static int ati_remote2_reset_resume(struct usb_interface *interface) if (!r) ar2->flags &= ~ATI_REMOTE2_SUSPENDED; - out: - mutex_unlock(&ati_remote2_mutex); - return r; } From patchwork Wed Sep 4 04:42:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789688 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 49D1681749; Wed, 4 Sep 2024 04:43:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424984; cv=none; b=uGaqOH48gy9Y5AuC5HU6M4KPq33/G+W3IkYieDr19eKOCHUBKLWV2jgujBkn5SM3W3wWOjRrFBonRJcdCy+aXL2YU7zVdsX0SeY7VcanMPgZ5BpCIAeRdw59T8y+XDuKz5BHfeZ7Jj1keCSfg+tYdh3NvK+QUZsLzMNwHSms8/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424984; c=relaxed/simple; bh=qfvlCrBeuMgTvWKCSq3+kjGo3PjVwBhBNztu9yeU170=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZojKgbGxkkTNRJBIB5TX8dU6jPvwm1MrbfIEtmh6xYO/zbMRphfgoCiKkUcqmpWG0YLH2dfLX10U9q0TMcgL1lU4K915CrSEELGuwym72s6nza+KpAHpWoc2uxOrCQZ2Vh2ycpStY4/Nntq+4NhPybumO1Qwrckk2sEUnxejKmU= 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=m/b1ghwm; arc=none smtp.client-ip=209.85.214.182 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="m/b1ghwm" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-20693995f68so3055075ad.1; Tue, 03 Sep 2024 21:43:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725424982; x=1726029782; 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=JojHCZ9pdFR3fnOlIkAMjYzH0C7qL1RERgC3ObqXljU=; b=m/b1ghwmmUMY8kGNfe2tQWE6PHBZfjjnM09PbTNL2M/ncvoUiLYcl7R4oEMZEpFjdA VvGbjH0ti73pQV0KNW1nqPQebzzta2rKvapRCxn6e+t62eoc1SBUpWKNrffObat4DtCS 1s0ub8w/e631gJ2Qa5nGPZQEinLapOeWcHpYdhZKR4vHAAsf3/Ln0KP6LtcDoR1f3PmR ZuTLY6PS8kEa+w2ErqCp4Uv7sKlP4o3ZXhLRoZMBfVIzQekeDiZASdliaG0j9ac9PAIT Of6x8D3edaFAvazSIqmZ6P/2ObqOb+yB/IH6QBUJ61inNqUcmS3S7V2cpS5LGqfKurht ERaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725424982; x=1726029782; 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=JojHCZ9pdFR3fnOlIkAMjYzH0C7qL1RERgC3ObqXljU=; b=svxGiQTu9FNKu75QrY0LkWhZSfO7eY3Slqh8pm0RL7fF7cGZyRN9U9foWkWcCSHVTM BGRBCuJabjkRQoY88UH3b+rRF7FwVIgwmoJ1wgfm+djp6EDzG0/TDY9ZqCcPRWzx5DwW IbqBD1IKjPvdfgMRXaa869H5i+v1osLibiev03Cx1xi2veuZvpP6Vbk9IsVfyHd+fpev l20CYnwf+2nVQUh2/KBx8sCfTToBNbwJdIP9UjMCcY6wfJu0upxGZgjVUp5zo8ehn5mz izvo6UI15fU+AE+I/s5gY8Y9A/PYeTYzJL/Yw16YTvetfhqE5XeqAdFGR+8XDOl7bMNL ai8w== X-Forwarded-Encrypted: i=1; AJvYcCX0FYCll0Y2RmrkZq1GabVdD80Gds66R4IyZ9KtqSefD86cwStB9JarGQm4KAgEQdO40XJiNwrWAt3+Wl0=@vger.kernel.org X-Gm-Message-State: AOJu0YyS2XsPV0GN/LFnLfyJzIFiyeImNCp61jp1dLPbp7TvZS3i+LrQ KgBu5sStZ40X66ZAIDlxzSDg9bVdnq70G+FjQnAlovG/aEPT+izBTgzvLw== X-Google-Smtp-Source: AGHT+IGOFFEns1wNokErTakojm3rlnCIKY69vUPMATabICZ8Hi+3xBILYaG/Vcr0BBQXHQu1oMKz/Q== X-Received: by 2002:a17:902:e852:b0:206:94f5:c2e6 with SMTP id d9443c01a7336-20694f5c61amr49940535ad.7.1725424982220; Tue, 03 Sep 2024 21:43:02 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae951c13sm5727665ad.103.2024.09.03.21.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:43:01 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 03/22] Input: cm109 - use guard notation when acquiring mutex and spinlock Date: Tue, 3 Sep 2024 21:42:23 -0700 Message-ID: <20240904044244.1042174-4-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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 Reviewed-by: Javier Carrasco --- drivers/input/misc/cm109.c | 167 ++++++++++++++++++------------------- 1 file changed, 79 insertions(+), 88 deletions(-) diff --git a/drivers/input/misc/cm109.c b/drivers/input/misc/cm109.c index 728325a2d574..0cfe5d4a573c 100644 --- a/drivers/input/misc/cm109.c +++ b/drivers/input/misc/cm109.c @@ -355,6 +355,35 @@ static void cm109_submit_buzz_toggle(struct cm109_dev *dev) __func__, error); } +static void cm109_submit_ctl(struct cm109_dev *dev) +{ + int error; + + guard(spinlock_irqsave)(&dev->ctl_submit_lock); + + dev->irq_urb_pending = 0; + + if (unlikely(dev->shutdown)) + return; + + if (dev->buzzer_state) + dev->ctl_data->byte[HID_OR0] |= BUZZER_ON; + else + dev->ctl_data->byte[HID_OR0] &= ~BUZZER_ON; + + dev->ctl_data->byte[HID_OR1] = dev->keybit; + dev->ctl_data->byte[HID_OR2] = dev->keybit; + + dev->buzzer_pending = 0; + dev->ctl_urb_pending = 1; + + error = usb_submit_urb(dev->urb_ctl, GFP_ATOMIC); + if (error) + dev_err(&dev->intf->dev, + "%s: usb_submit_urb (urb_ctl) failed %d\n", + __func__, error); +} + /* * IRQ handler */ @@ -362,8 +391,6 @@ static void cm109_urb_irq_callback(struct urb *urb) { struct cm109_dev *dev = urb->context; const int status = urb->status; - int error; - unsigned long flags; dev_dbg(&dev->intf->dev, "### URB IRQ: [0x%02x 0x%02x 0x%02x 0x%02x] keybit=0x%02x\n", dev->irq_data->byte[0], @@ -401,32 +428,7 @@ static void cm109_urb_irq_callback(struct urb *urb) } out: - - spin_lock_irqsave(&dev->ctl_submit_lock, flags); - - dev->irq_urb_pending = 0; - - if (likely(!dev->shutdown)) { - - if (dev->buzzer_state) - dev->ctl_data->byte[HID_OR0] |= BUZZER_ON; - else - dev->ctl_data->byte[HID_OR0] &= ~BUZZER_ON; - - dev->ctl_data->byte[HID_OR1] = dev->keybit; - dev->ctl_data->byte[HID_OR2] = dev->keybit; - - dev->buzzer_pending = 0; - dev->ctl_urb_pending = 1; - - error = usb_submit_urb(dev->urb_ctl, GFP_ATOMIC); - if (error) - dev_err(&dev->intf->dev, - "%s: usb_submit_urb (urb_ctl) failed %d\n", - __func__, error); - } - - spin_unlock_irqrestore(&dev->ctl_submit_lock, flags); + cm109_submit_ctl(dev); } static void cm109_urb_ctl_callback(struct urb *urb) @@ -434,7 +436,6 @@ static void cm109_urb_ctl_callback(struct urb *urb) struct cm109_dev *dev = urb->context; const int status = urb->status; int error; - unsigned long flags; dev_dbg(&dev->intf->dev, "### URB CTL: [0x%02x 0x%02x 0x%02x 0x%02x]\n", dev->ctl_data->byte[0], @@ -449,35 +450,31 @@ static void cm109_urb_ctl_callback(struct urb *urb) __func__, status); } - spin_lock_irqsave(&dev->ctl_submit_lock, flags); + guard(spinlock_irqsave)(&dev->ctl_submit_lock); dev->ctl_urb_pending = 0; - if (likely(!dev->shutdown)) { - - if (dev->buzzer_pending || status) { - dev->buzzer_pending = 0; - dev->ctl_urb_pending = 1; - cm109_submit_buzz_toggle(dev); - } else if (likely(!dev->irq_urb_pending)) { - /* ask for key data */ - dev->irq_urb_pending = 1; - error = usb_submit_urb(dev->urb_irq, GFP_ATOMIC); - if (error) - dev_err(&dev->intf->dev, - "%s: usb_submit_urb (urb_irq) failed %d\n", - __func__, error); - } - } + if (unlikely(dev->shutdown)) + return; - spin_unlock_irqrestore(&dev->ctl_submit_lock, flags); + if (dev->buzzer_pending || status) { + dev->buzzer_pending = 0; + dev->ctl_urb_pending = 1; + cm109_submit_buzz_toggle(dev); + } else if (likely(!dev->irq_urb_pending)) { + /* ask for key data */ + dev->irq_urb_pending = 1; + error = usb_submit_urb(dev->urb_irq, GFP_ATOMIC); + if (error) + dev_err(&dev->intf->dev, + "%s: usb_submit_urb (urb_irq) failed %d\n", + __func__, error); + } } static void cm109_toggle_buzzer_async(struct cm109_dev *dev) { - unsigned long flags; - - spin_lock_irqsave(&dev->ctl_submit_lock, flags); + guard(spinlock_irqsave)(&dev->ctl_submit_lock); if (dev->ctl_urb_pending) { /* URB completion will resubmit */ @@ -486,8 +483,6 @@ static void cm109_toggle_buzzer_async(struct cm109_dev *dev) dev->ctl_urb_pending = 1; cm109_submit_buzz_toggle(dev); } - - spin_unlock_irqrestore(&dev->ctl_submit_lock, flags); } static void cm109_toggle_buzzer_sync(struct cm109_dev *dev, int on) @@ -556,32 +551,30 @@ static int cm109_input_open(struct input_dev *idev) return error; } - mutex_lock(&dev->pm_mutex); - - dev->buzzer_state = 0; - dev->key_code = -1; /* no keys pressed */ - dev->keybit = 0xf; + scoped_guard(mutex, &dev->pm_mutex) { + dev->buzzer_state = 0; + dev->key_code = -1; /* no keys pressed */ + dev->keybit = 0xf; - /* issue INIT */ - dev->ctl_data->byte[HID_OR0] = HID_OR_GPO_BUZ_SPDIF; - dev->ctl_data->byte[HID_OR1] = dev->keybit; - dev->ctl_data->byte[HID_OR2] = dev->keybit; - dev->ctl_data->byte[HID_OR3] = 0x00; + /* issue INIT */ + dev->ctl_data->byte[HID_OR0] = HID_OR_GPO_BUZ_SPDIF; + dev->ctl_data->byte[HID_OR1] = dev->keybit; + dev->ctl_data->byte[HID_OR2] = dev->keybit; + dev->ctl_data->byte[HID_OR3] = 0x00; - dev->ctl_urb_pending = 1; - error = usb_submit_urb(dev->urb_ctl, GFP_KERNEL); - if (error) { - dev->ctl_urb_pending = 0; - dev_err(&dev->intf->dev, "%s: usb_submit_urb (urb_ctl) failed %d\n", - __func__, error); - } else { - dev->open = 1; + dev->ctl_urb_pending = 1; + error = usb_submit_urb(dev->urb_ctl, GFP_KERNEL); + if (!error) { + dev->open = 1; + return 0; + } } - mutex_unlock(&dev->pm_mutex); + dev->ctl_urb_pending = 0; + usb_autopm_put_interface(dev->intf); - if (error) - usb_autopm_put_interface(dev->intf); + dev_err(&dev->intf->dev, "%s: usb_submit_urb (urb_ctl) failed %d\n", + __func__, error); return error; } @@ -590,17 +583,15 @@ static void cm109_input_close(struct input_dev *idev) { struct cm109_dev *dev = input_get_drvdata(idev); - mutex_lock(&dev->pm_mutex); - - /* - * Once we are here event delivery is stopped so we - * don't need to worry about someone starting buzzer - * again - */ - cm109_stop_traffic(dev); - dev->open = 0; - - mutex_unlock(&dev->pm_mutex); + scoped_guard(mutex, &dev->pm_mutex) { + /* + * Once we are here event delivery is stopped so we + * don't need to worry about someone starting buzzer + * again + */ + cm109_stop_traffic(dev); + dev->open = 0; + } usb_autopm_put_interface(dev->intf); } @@ -823,9 +814,9 @@ static int cm109_usb_suspend(struct usb_interface *intf, pm_message_t message) dev_info(&intf->dev, "cm109: usb_suspend (event=%d)\n", message.event); - mutex_lock(&dev->pm_mutex); + guard(mutex)(&dev->pm_mutex); + cm109_stop_traffic(dev); - mutex_unlock(&dev->pm_mutex); return 0; } @@ -836,9 +827,9 @@ static int cm109_usb_resume(struct usb_interface *intf) dev_info(&intf->dev, "cm109: usb_resume\n"); - mutex_lock(&dev->pm_mutex); + guard(mutex)(&dev->pm_mutex); + cm109_restore_state(dev); - mutex_unlock(&dev->pm_mutex); return 0; } From patchwork Wed Sep 4 04:42:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789689 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.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 26D75823AF; Wed, 4 Sep 2024 04:43:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424985; cv=none; b=e7HB6Y0pBDs07Vj05Jo6tnk14NZrbOrjNUNqxeacrF6VFaH+G0lqPNZcZSvuD1CavB9OL3gk19GmefMlXLg3Z/EBaJn9t+KAzdNVghYgv9KKcK5fVVWvcbxSa8nhO6vwJxXGOsdFy0Ie5m/SqLgNQdFSZohxMT0N4DsPeYSjNDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424985; c=relaxed/simple; bh=Z7nsIGt5YhOtj9TKDzIi/YcNVdcAY9ONCb+aIMRoifs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aTpQzRkHBJ5PPCPSHDMYV/rQAUv2A42MJ5WOUTQpqh3xlfRkm+ui/BQdA4AvjnL21OLV6dJOhrkrdk38QB4CwWrX0gknO5gYdCRqkJEmR+wcUkKeEurcUJLLoNz5+ERzb1ki2F7a4zVeCgDihtpjU0Dwv1bEHO0PHrYNu9YYkbw= 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=Rc1/nP7B; arc=none smtp.client-ip=209.85.214.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="Rc1/nP7B" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-20570b42f24so28760645ad.1; Tue, 03 Sep 2024 21:43:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725424983; x=1726029783; 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=gQjFNREllbEtpcW9yUf75en1G/awvfMmLJq7sa9fQM8=; b=Rc1/nP7BScWjw+nq9uXeeBX/fy3ybto+fVELz0OOHTynqvp9An+j2k7sayTNZkg0x8 LjSFc4tTu+oi0EqPgIV+gFUuJbSEur3u0KQ+Vy8zrYQ9A+IQ/naqIn9e23vEpRUyya9v 4yIDme3ue44vpzWrW1P76gIWlmpVRRZrN+yAwaXFQSQLe8hmYjUnD5H6GoFuqDixchN8 VoGjhCpLLRw0w0DtkPPzhfp8TAbVo/Vz3zsPAI27FXyoedsUkRf15bfOHvhzDV2obi8U Z8oZXXXZON2dt+lQnAgsP5SRSgAv10QH+u512wLo52NSJYRF91cZ/2SxszpoCQpIUgNx vnLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725424983; x=1726029783; 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=gQjFNREllbEtpcW9yUf75en1G/awvfMmLJq7sa9fQM8=; b=OePAR00/5Ts5MW+l7Z338X5WO+pSudFVpXn6daXb63PsftemcJQ4H+BqnTXi0pZ5wJ AklC0BMWA9lZoWvPRMxNI6+coB3SRhlHyc1AdAzemL2GfGnZvGtMNOAsOLsTZr6/9RUc vhiTrz+TaGyaNYvm4U/IfFpROLnCgdIxiqIA/SlQS/noCkPu+TRDmUQ7ngwRS7LPn9jo BduGPcYYHZg8/LCDa+rIAi+CYpE4ZiyUyTnQUEQNueVyMxUH4Qg61HGejRotC8uTPbbZ 6CkaEsvYhxmpSNFlQcpFe2Y9gnrgo/1Lvl9PXTgHs6ii40jt75zlmYcXsFSrssPo3mXN IHrw== X-Forwarded-Encrypted: i=1; AJvYcCVLcoBODV5VH9RIl8J6KCTTmlL0IKV0wqM+tIwh1WtaJUmmXIyGBBjzv/P/Dafp7ZCDSVgEj7GKHRbZrxc=@vger.kernel.org X-Gm-Message-State: AOJu0YxpfrNiIGXA8+mrfwfJbcTq3q6oQj/bxQc8gmEes4WeEEwpvoBa drktu1gMqDqowNw8y0zOKvP8m1sEdJ+JOu6EQzWWkx7S84XqDVA3Qko1QA== X-Google-Smtp-Source: AGHT+IFz2IBREdG4bnpMKSTq9/1/sHY92r6ILi9UHKnQwI3cSc41SJgB8oji0+T//1jl3dDmedPW3A== X-Received: by 2002:a17:902:ce07:b0:206:ac11:f3bb with SMTP id d9443c01a7336-206ac11f49cmr33072625ad.47.1725424983330; Tue, 03 Sep 2024 21:43:03 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae951c13sm5727665ad.103.2024.09.03.21.43.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:43:02 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 04/22] Input: cma3000_d0x - use guard notation when acquiring mutex Date: Tue, 3 Sep 2024 21:42:24 -0700 Message-ID: <20240904044244.1042174-5-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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: Javier Carrasco --- drivers/input/misc/cma3000_d0x.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/drivers/input/misc/cma3000_d0x.c b/drivers/input/misc/cma3000_d0x.c index 0c68e924a1cc..cfc12332bee1 100644 --- a/drivers/input/misc/cma3000_d0x.c +++ b/drivers/input/misc/cma3000_d0x.c @@ -217,15 +217,13 @@ static int cma3000_open(struct input_dev *input_dev) { struct cma3000_accl_data *data = input_get_drvdata(input_dev); - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); if (!data->suspended) cma3000_poweron(data); data->opened = true; - mutex_unlock(&data->mutex); - return 0; } @@ -233,40 +231,34 @@ static void cma3000_close(struct input_dev *input_dev) { struct cma3000_accl_data *data = input_get_drvdata(input_dev); - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); if (!data->suspended) cma3000_poweroff(data); data->opened = false; - - mutex_unlock(&data->mutex); } void cma3000_suspend(struct cma3000_accl_data *data) { - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); if (!data->suspended && data->opened) cma3000_poweroff(data); data->suspended = true; - - mutex_unlock(&data->mutex); } EXPORT_SYMBOL(cma3000_suspend); void cma3000_resume(struct cma3000_accl_data *data) { - mutex_lock(&data->mutex); + guard(mutex)(&data->mutex); if (data->suspended && data->opened) cma3000_poweron(data); data->suspended = false; - - mutex_unlock(&data->mutex); } EXPORT_SYMBOL(cma3000_resume); From patchwork Wed Sep 4 04:42:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789690 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 7870E84A32; Wed, 4 Sep 2024 04:43:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424986; cv=none; b=IWDLxyWDd+1v4kIiXWd7Kjgu5PG9vAzooh/mE8aJhSWOzvcSCO5Z9MXYfN0g45ZxhfLnt9tuLZv1gfa66PzvR/sDAgTmyQdMYJQG60Xh7Xs4dSZNE6PmztTIdbV3TzNe1mgmgkghyYrCDrs0jMiMPpWNpSwfs3Ql7mu93vyBtOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424986; c=relaxed/simple; bh=ntJRQE7i5EHSpWxAGqsFMIM6I1u1MMOt+WMjZtKBSpA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lerNXQGqCbFod1IWFFmH02vEj8hDxbR982l1aYwr9wayYcy2X6kbyhHJwoHdRpiisnbvkPImJP7hN4IWyYRzxWdijfGWaw4x1Bjl47WhzU+3H0tcLT5xjschkKEowf0FRzzDxEpffiFRDAg8kLiCzgLTQL+C1Tf9XfEy5d6HzVs= 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=SMkYk+fc; arc=none smtp.client-ip=209.85.210.170 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="SMkYk+fc" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7143165f23fso4878838b3a.1; Tue, 03 Sep 2024 21:43:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725424984; x=1726029784; 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=Qt3lIbqEzBLG2ARFdyUWJzIIEgp9iN6FwkL6CSsxPmo=; b=SMkYk+fc2T5ZC3QYAzjoR6h1AGucQ+xleW7wAYjPm0pmjLazV04oaxkX4+3NzgC+65 GyzaPfGK4r8Y4wpKQNf3Ek5iRxvqDCjEiddOkPmQmQMsd7JqAJKtsrdhyMGx8W3G1JB8 TByOLiJaUKL+gDkyNa+nOyhy6F8/XPsQU+K49xXsXcIcBlRQTza1mOmV7VRi9ruo5RoG GB/WyKfAJ3hplU/+/Lzw6gVm58IYMwbegtJ2rRbfEoj9j/aRKEfH0aBzzaLt4szuugj3 WLNAbZIZw7qlgUUlC6CgfWkZqQuAz3BChQZgdpV3X7vhqdcpYbHYJHnmRkpJBngUN9ts EkWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725424984; x=1726029784; 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=Qt3lIbqEzBLG2ARFdyUWJzIIEgp9iN6FwkL6CSsxPmo=; b=v2Hpns8YPo+VNrGezPnMKxZvdzzdjc9MuqKZI1KvyoSEAzMSQWWO4WeZBbJ05NHrcn erltqVTYsrPoDlvLfFT8IP/j5rfwf/TeTYKUklgAra2LmBJTFtJspU1+uybyeMiks4Br Qn5/Y6AviEmaHjj0h3sNToDurkZOm1SgKsEe5yuKQ5r+IKcPXQOMr7saTiJz2Lgoqh24 QhZHwM9PuY3+Ee7HB6IP54LLHN5ntGCJziXcP7QX0LbLWMnYKBqWaXlRoUWOpYGJbps8 cemZtXpEd9nSDLXQrW5uqhZtsDhUoOjMg3GFabXI88/Jqpk8nhBUG2DTqZNjRvwwKGz/ bCOw== X-Forwarded-Encrypted: i=1; AJvYcCXRJwmRNfMZqTzXeJEDLDcaq78pUkt9PMkE2W6KVo/8FARJrU/ILzRcyQegQffDjx03/IWAHDOORdE00d8=@vger.kernel.org X-Gm-Message-State: AOJu0YzPuO9X3atnsnXFpp49eXiM7m7XeyH3N8ZTl8Tw3cjDcZSD/ksr 54FyjBN2CHmuQRl51rjRGSWuQH469dOh9gHbqcqrMjT3TycI+OKtlBeEXg== X-Google-Smtp-Source: AGHT+IFNC8TLv1cx88xGH3pwH1vAazusFQZm0bGvrQnQR0jeYN70CGQDBhRl7ZtFk2U7+lwmIWjtEA== X-Received: by 2002:a05:6a21:789f:b0:1cc:e1a2:4335 with SMTP id adf61e73a8af0-1ced058ab02mr11718585637.50.1725424984473; Tue, 03 Sep 2024 21:43:04 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae951c13sm5727665ad.103.2024.09.03.21.43.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:43:04 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 05/22] Input: da7280 - use guard notation when acquiring mutex and spinlock Date: Tue, 3 Sep 2024 21:42:25 -0700 Message-ID: <20240904044244.1042174-6-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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 Reviewed-by: Javier Carrasco --- drivers/input/misc/da7280.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/drivers/input/misc/da7280.c b/drivers/input/misc/da7280.c index 1629b7ea4cbd..e4a605c6af15 100644 --- a/drivers/input/misc/da7280.c +++ b/drivers/input/misc/da7280.c @@ -1263,39 +1263,37 @@ static int da7280_suspend(struct device *dev) { struct da7280_haptic *haptics = dev_get_drvdata(dev); - mutex_lock(&haptics->input_dev->mutex); + guard(mutex)(&haptics->input_dev->mutex); /* * Make sure no new requests will be submitted while device is * suspended. */ - spin_lock_irq(&haptics->input_dev->event_lock); - haptics->suspended = true; - spin_unlock_irq(&haptics->input_dev->event_lock); + scoped_guard(spinlock_irq, &haptics->input_dev->event_lock) { + haptics->suspended = true; + } da7280_haptic_stop(haptics); - mutex_unlock(&haptics->input_dev->mutex); - return 0; } static int da7280_resume(struct device *dev) { struct da7280_haptic *haptics = dev_get_drvdata(dev); - int retval; + int error; - mutex_lock(&haptics->input_dev->mutex); + guard(mutex)(&haptics->input_dev->mutex); - retval = da7280_haptic_start(haptics); - if (!retval) { - spin_lock_irq(&haptics->input_dev->event_lock); + error = da7280_haptic_start(haptics); + if (error) + return error; + + scoped_guard(spinlock_irq, &haptics->input_dev->event_lock) { haptics->suspended = false; - spin_unlock_irq(&haptics->input_dev->event_lock); } - mutex_unlock(&haptics->input_dev->mutex); - return retval; + return 0; } #ifdef CONFIG_OF From patchwork Wed Sep 4 04:42:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789691 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 C4F5684E0D; Wed, 4 Sep 2024 04:43:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424988; cv=none; b=K20U/GhCm1JeL8B9XjxbZQ5sMDNPw6mtuHApQQHEv/GxwLHwEiXIYik/hCwj+s8gtcsKmNaAOaVEVQpHK/+5IqtdEeEWUCh/vTKnB78F/mCh4TvdY6acK2oRlBqGJDnYadNXQounX6LCQ3cEDh4AA+S56Ed9RYeoEAsVQ9UXLMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424988; c=relaxed/simple; bh=ZwmF1IcBskxRDxGqbU3BxmePdaxQNe2xsTrvQC+AKc0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pmOusnwAV8/yXZi7OjuagArECauSCuZm9v+484TgrUE8yzeeE7iWno9fxfAFzO/bJCiOLDow4ETfgfrnvkHpcuxrfmEWkK79HbgndCqMnMOecAWuM+Ib4ICGwYi33mdxIH+PKBsDR0MJKu2Xtc1X77OP0EAIl4l561Uy5gFhB6Q= 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=U91gOzrR; arc=none smtp.client-ip=209.85.214.170 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="U91gOzrR" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-205722ba00cso21242345ad.0; Tue, 03 Sep 2024 21:43:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725424986; x=1726029786; 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=CofU3FPlAau2C+uDy1gGfBp2z32YQ2vYmUn+IAuO6yQ=; b=U91gOzrR89zom76kR56aCP6PcbGPwB7u2uslxFRMArUwlNuVpYZ8mllQ2WV9f8a/Ck goGoiJBj3cD350DvnvKKFezfN++Z/BFZFmSQgUe8Lgva7xMY3W0f/QslIkZcQ61696+o q9/yFZrb8WAf4gB6zuEn/laamCk4oIZToNDU2Ujp68OB6qBkfJUrAfjneXXCUpMbXGOr +oc1NHVMeQBb8JCnusvk/7lbrtJmC1XOpGQNDLSMN/ySKYWzFQ9W7RY8j1Lh4eratfOI YmEq5D8tfNyyDgImvOF6giu55c0KXKygm+jFFITyZWVX/JSG1+jYIAglu/OGETn3RT57 97uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725424986; x=1726029786; 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=CofU3FPlAau2C+uDy1gGfBp2z32YQ2vYmUn+IAuO6yQ=; b=wcaObx88ERC3WRxTEuVwkf4QJQNT19yf7SXTB+BYg/TufeTIycOkQXKgnyppyKAQIq CckXU2jyGOB4PgAeBeugipV87SHiE6cpHsTvDP0HYByV6umNLflOubQi2p0n+5BRtlHi WdlhF5lxARMaRkm7VIbfg+J+lp54zRl0klIsXc22U6pstlMlfykfBsKhz7hGjtYYODTz yGiv5lm8xIRsc1Bt6AqHcrIaxBUid057isxRUttsw4qbFo504FXggX3qzH7tcDK/pCTI PSUREvNn4p+7mY9sUCIvsLbC33On9FRJ0N0W8b5/V7ZhaUqNMQcgGrm9Ls5YIZKM4XuH qVLw== X-Forwarded-Encrypted: i=1; AJvYcCUjsIK7rfCbuHkWYhrM3u6M2jX6b5mK9og3n220p/xhKmesf2I+K1GWWw3DdsKGlR1RZ7V9fHRTnBFtLho=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1Z8X90UdpX3Y6nC+KZCDNur23OX9/o5qS7tQDvugfZJfhsdCy wfSrn78Sdo8bj3xGin0K6szyvbE/9tdrMTju0Ooy7JyM1+vaRRO8uauWqw== X-Google-Smtp-Source: AGHT+IF6bV7qkawi5DzOxfYgshmXdy3EZLNlfAEDj5Hu3oUYEZu2AmASuDYEqp1iuXr/1vLXmrvwsQ== X-Received: by 2002:a17:902:db0f:b0:205:5f35:80b6 with SMTP id d9443c01a7336-2055f358700mr84495025ad.61.1725424985793; Tue, 03 Sep 2024 21:43:05 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae951c13sm5727665ad.103.2024.09.03.21.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:43:05 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 06/22] Input: kxtj9 - use guard notation when acquiring mutex/disabling irq Date: Tue, 3 Sep 2024 21:42:26 -0700 Message-ID: <20240904044244.1042174-7-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation makes the code more compact and error handling more robust by ensuring that mutexes are released and interrupts are re-enabled in all code paths when control leaves critical section. Signed-off-by: Dmitry Torokhov Reviewed-by: Javier Carrasco --- drivers/input/misc/kxtj9.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/input/misc/kxtj9.c b/drivers/input/misc/kxtj9.c index 837682cb2a7d..c6146bcee9f9 100644 --- a/drivers/input/misc/kxtj9.c +++ b/drivers/input/misc/kxtj9.c @@ -314,9 +314,8 @@ static ssize_t kxtj9_set_poll(struct device *dev, struct device_attribute *attr, return error; /* Lock the device to prevent races with open/close (and itself) */ - mutex_lock(&input_dev->mutex); - - disable_irq(client->irq); + guard(mutex)(&input_dev->mutex); + guard(disable_irq)(&client->irq); /* * Set current interval to the greater of the minimum interval or @@ -326,9 +325,6 @@ static ssize_t kxtj9_set_poll(struct device *dev, struct device_attribute *attr, kxtj9_update_odr(tj9, tj9->last_poll_interval); - enable_irq(client->irq); - mutex_unlock(&input_dev->mutex); - return count; } @@ -504,12 +500,11 @@ static int kxtj9_suspend(struct device *dev) struct kxtj9_data *tj9 = i2c_get_clientdata(client); struct input_dev *input_dev = tj9->input_dev; - mutex_lock(&input_dev->mutex); + guard(mutex)(&input_dev->mutex); if (input_device_enabled(input_dev)) kxtj9_disable(tj9); - mutex_unlock(&input_dev->mutex); return 0; } @@ -519,12 +514,11 @@ static int kxtj9_resume(struct device *dev) struct kxtj9_data *tj9 = i2c_get_clientdata(client); struct input_dev *input_dev = tj9->input_dev; - mutex_lock(&input_dev->mutex); + guard(mutex)(&input_dev->mutex); if (input_device_enabled(input_dev)) kxtj9_enable(tj9); - mutex_unlock(&input_dev->mutex); return 0; } From patchwork Wed Sep 4 04:42:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789692 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.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 EB950126BFD; Wed, 4 Sep 2024 04:43:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424989; cv=none; b=XYkrA1tBBbZdUWXWr7LeUKGJfpKBntneJ1s1lcbiCZWSPqmaIAPtssXjeEQ35Gc9zVNYbmL6v6PRLDpGyrHmTE6cLsLQnY7/MktvFveoZAKOyfQWKzwBNaa5m1p/bESbvSe0YCdmScHbQPBsheGiI+Rn7wLK6zMVabTF0J7rGVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424989; c=relaxed/simple; bh=UO5tdz28zf6P49QFmFryD8fHoZAMUUMLPprETK3ohXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a5AUuaoLosMx58g/M+bZmP9fVfqeh90yjj4y9b8XQOJActnii7cqGacl2xqfZDrsndObF3OvuYWKfr0BLnQUC9Gxn19j2RpHIMindN7vOqDq3EBySfKbEUA1pCjPuSubLwLKhHqUO4Y8Q/T27IS8Uwk4AfweiT15Ox7FbPHfbCA= 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=GFvRGgrE; arc=none smtp.client-ip=209.85.215.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="GFvRGgrE" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-6bce380eb96so3449508a12.0; Tue, 03 Sep 2024 21:43:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725424987; x=1726029787; 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=tt6lvz54FLu2yt0+MuKREUCSNC/E33zVcfi/wJ5rHi8=; b=GFvRGgrEVXDkGsUo9eAbPTZhplz43ZdPDe37XDR7mmIGYRkqIiuh7qacJf2TXRFwTu oewyrHUWMn/2z0gp4GJZUbm6/Z7H+ValOkdV08ZpF+vj4p0wlHYaMK63k1MPB1jQEcdJ jicBUjI8+hT/4lBCdEkqBpS5HbmjJ3/2cjaWnpS2HNpSZ6hSNvR2t3r+onijzmN16eRP jswoA1n3i79KUAYRGsFv3DbsvcP+K2sYsGFXnNFLfH+wT1EnrJxtjPEnUp6sPYsjKSvm ly1JoQ0AkKT58hcSYF5EiksP+q7BBXwAk77/hmILA2TY+1Zp7sTerWrRtjpjdGqJSuZn Hkng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725424987; x=1726029787; 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=tt6lvz54FLu2yt0+MuKREUCSNC/E33zVcfi/wJ5rHi8=; b=hDCtH44dLrcAPIEhKC+VcqBkp2dZgB04UgIJPZ5Qn0h4iMLkXY1S8O9M7Cm30kt5wq 47vOFizlrc03G7d8u0thGWOarnEoQNYPcB0myYbBA0+E7AW3N2QGPmOhyRrH/RkJbxUc ThmUQEr6gbsSXez6g5HzKtYXMxUhuROKK6wlM+o2toimJbLuXzQBbAsAvJAHt2T5d3DM 1kIJ5TM2ALwg6LWJJvAU6ywqUhEBJimIDzZI8ZzfIMX3457+Hbz0bwwPNQBOlcxG3luy GKh4eVx/ORl/69iGaE32nFcP1DIcbyI/LhXcykYQtAVq+u3nL2FsJTumwVsovV1qdBLx 4OHQ== X-Forwarded-Encrypted: i=1; AJvYcCWrEEL7i+VIDrBxFNPxeKNABfzzEyb5zUveGYsBqj4BAkYn8Gv3CAwwV+BR0k/eGUGO+cTw566XYm/ac1I=@vger.kernel.org X-Gm-Message-State: AOJu0YyMFjjh6GGfch7mxGrdoZfpKT6sa9gOx0yU1SWR3et2GM5Y1M24 bPvKSK16yxI6n9mTiFSQMVLW8TNeJHwTRgEiMSAvyZfS9EXd6OU8/KpZGQ== X-Google-Smtp-Source: AGHT+IGPb3PpMZ/VEpa9wnSlL3PiK9uo22oOIgqwAyk1NF1r0jwyW5MLPmpjGblzlcP/m8rIDEZKnw== X-Received: by 2002:a17:902:daca:b0:202:54b8:72e5 with SMTP id d9443c01a7336-205444f14d9mr119647375ad.22.1725424987017; Tue, 03 Sep 2024 21:43:07 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae951c13sm5727665ad.103.2024.09.03.21.43.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:43:06 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 07/22] Input: drv260x - use guard notation when acquiring mutex Date: Tue, 3 Sep 2024 21:42:27 -0700 Message-ID: <20240904044244.1042174-8-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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: Javier Carrasco --- drivers/input/misc/drv260x.c | 50 +++++++++++++++++------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/drivers/input/misc/drv260x.c b/drivers/input/misc/drv260x.c index 61b503835aa6..96cd6a078c8a 100644 --- a/drivers/input/misc/drv260x.c +++ b/drivers/input/misc/drv260x.c @@ -537,64 +537,62 @@ static int drv260x_probe(struct i2c_client *client) static int drv260x_suspend(struct device *dev) { struct drv260x_data *haptics = dev_get_drvdata(dev); - int ret = 0; + int error; - mutex_lock(&haptics->input_dev->mutex); + guard(mutex)(&haptics->input_dev->mutex); if (input_device_enabled(haptics->input_dev)) { - ret = regmap_update_bits(haptics->regmap, - DRV260X_MODE, - DRV260X_STANDBY_MASK, - DRV260X_STANDBY); - if (ret) { + error = regmap_update_bits(haptics->regmap, + DRV260X_MODE, + DRV260X_STANDBY_MASK, + DRV260X_STANDBY); + if (error) { dev_err(dev, "Failed to set standby mode\n"); - goto out; + return error; } gpiod_set_value(haptics->enable_gpio, 0); - ret = regulator_disable(haptics->regulator); - if (ret) { + error = regulator_disable(haptics->regulator); + if (error) { dev_err(dev, "Failed to disable regulator\n"); regmap_update_bits(haptics->regmap, DRV260X_MODE, DRV260X_STANDBY_MASK, 0); + return error; } } -out: - mutex_unlock(&haptics->input_dev->mutex); - return ret; + + return 0; } static int drv260x_resume(struct device *dev) { struct drv260x_data *haptics = dev_get_drvdata(dev); - int ret = 0; + int error; - mutex_lock(&haptics->input_dev->mutex); + guard(mutex)(&haptics->input_dev->mutex); if (input_device_enabled(haptics->input_dev)) { - ret = regulator_enable(haptics->regulator); - if (ret) { + error = regulator_enable(haptics->regulator); + if (error) { dev_err(dev, "Failed to enable regulator\n"); - goto out; + return error; } - ret = regmap_update_bits(haptics->regmap, - DRV260X_MODE, - DRV260X_STANDBY_MASK, 0); - if (ret) { + error = regmap_update_bits(haptics->regmap, + DRV260X_MODE, + DRV260X_STANDBY_MASK, 0); + if (error) { dev_err(dev, "Failed to unset standby mode\n"); regulator_disable(haptics->regulator); - goto out; + return error; } gpiod_set_value(haptics->enable_gpio, 1); } -out: - mutex_unlock(&haptics->input_dev->mutex); - return ret; + return 0; } static DEFINE_SIMPLE_DEV_PM_OPS(drv260x_pm_ops, drv260x_suspend, drv260x_resume); From patchwork Wed Sep 4 04:42:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789693 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.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 1D9D512CDB0; Wed, 4 Sep 2024 04:43:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424991; cv=none; b=AqAyrJsvx8WNQzyzkK/Cztpi7Abj9NMfE8B0t7XgU5p/kbX+05Ivo0whBxtexxuA0cGNt3M/3jVgEgEo7vJWeZst/lYSZ3ZHAaVRE1JUe+pzNSI64XpCr/eTN+8YA5wwo0pqdrKWX4z6vpWDQ9QD6pOTfLoSdzAQ/A5w8uPfllw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424991; c=relaxed/simple; bh=UTU0Q6nqcjXo8U72mkhmNRNfnaA6FZQfpIyIp/8HXS8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k57D3oGS3CH5PmpTc381DJ0fseLnnRex66fiWtx0KgO24mrhMXbXopONFdCrN6QTbsnFwYRANVbkV+IaTSiHC6ruKyyb/rlNxgqIXxU74D7m3NrBjGAdSWDVfA0WP4brELICx3Uq96yd4M+jIRcsf1PsvJzmRIBv5G3Sl8uvrqM= 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=PJOANGwF; arc=none smtp.client-ip=209.85.215.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="PJOANGwF" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-7d4f85766f0so884870a12.2; Tue, 03 Sep 2024 21:43:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725424988; x=1726029788; 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=tnKUsf8sYZk0+1pS2fn63M21zdwO+i7FFD1dgf0fueU=; b=PJOANGwF8D3ZPFH9qfENScR/mO5FOYI60iu8wVaeGqPf7OrCAu3IBBeudLVv3l1sl+ Y8G1h2sMTWSynnmvEL1VlaXxYchjf4M3k/mE3z8Xusz2Bq8oQ05chlm25cbJmjLzBSZw DOJeMKsyM2pC/5QTPOZiVCNXeq3zNz+tPfIjXOHtdWimpNj48W1M3HlCslX3KXkqLVqh meh9w7ypQrLtjoGP3zYYSKRw1Yu5fDhy0hvUwXQQxwe7pfSH50E64w4ltx0D6kQdiW7p uIz9IBE/5KqOgjNTokpplz29g2rxL2000+Slgan1sbdHRlML4WF6SSveoQg609IogrBN uJBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725424988; x=1726029788; 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=tnKUsf8sYZk0+1pS2fn63M21zdwO+i7FFD1dgf0fueU=; b=sXz9r12YyG6nueEBVxfYI0HeFoJqWOZHLDZMh1n3M/eniFU46dfVOT3Bn2fDrcZPyP txUFKRcmsAT8/7QqSWvUFTKHO/32pzdJBTp9PNkyLj3YDnU7LPMGBPBb5MwPplz/TTCC /WQQYoxtiYtoxqaemXJpyOg67wuQbYY1agNusLGO9hv89sU6oKMIfG2YsqPS4FS3vgzC sL4WZ5ZhPkdsBSE4+TKnqy+4fzy6tV3tWmHjyYoAWlbpMlOtkQJZ9hyd9koDpJ1giocu jPE7N3DMjoAgzTSD82+L3EkQK1aDS3+/PfizbfBXArDih8IyoHYjU6XZhnLHCe+Lidj6 0MIg== X-Forwarded-Encrypted: i=1; AJvYcCVBFtGDmXzCL3DG9B3xzwFAEW0Q7TRMU+JGVLsC9jzmoFq9fTZkab8+m1EOZb8xE5Nsy3Zg3fc+CiHL1y0=@vger.kernel.org X-Gm-Message-State: AOJu0YxH/fz0wuk0Cj1kJtH+AjXIQ/UY3B9ItBRSjd1mSAGTHFFISfVd IgjJxK5maom9YXFdGuFQKkM+CJahKgTZu4zurso9LMAERtc98BJRS/GcmQ== X-Google-Smtp-Source: AGHT+IEHc1zEMjCZ2hL7VhZi07U+zjl3L7wzRyGNxE8xUAoVUAt/IC74rbslg9f8MjNdBGjAqmdbyQ== X-Received: by 2002:a17:902:f606:b0:205:410c:f3b3 with SMTP id d9443c01a7336-205410cf6c0mr151781095ad.59.1725424988146; Tue, 03 Sep 2024 21:43:08 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae951c13sm5727665ad.103.2024.09.03.21.43.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:43:07 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 08/22] Input: drv2665 - use guard notation when acquiring mutex Date: Tue, 3 Sep 2024 21:42:28 -0700 Message-ID: <20240904044244.1042174-9-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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: Javier Carrasco --- drivers/input/misc/drv2665.c | 44 +++++++++++++++++------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/drivers/input/misc/drv2665.c b/drivers/input/misc/drv2665.c index f98e4d765307..77ec96c7db76 100644 --- a/drivers/input/misc/drv2665.c +++ b/drivers/input/misc/drv2665.c @@ -225,59 +225,57 @@ static int drv2665_probe(struct i2c_client *client) static int drv2665_suspend(struct device *dev) { struct drv2665_data *haptics = dev_get_drvdata(dev); - int ret = 0; + int error; - mutex_lock(&haptics->input_dev->mutex); + guard(mutex)(&haptics->input_dev->mutex); if (input_device_enabled(haptics->input_dev)) { - ret = regmap_update_bits(haptics->regmap, DRV2665_CTRL_2, - DRV2665_STANDBY, DRV2665_STANDBY); - if (ret) { + error = regmap_update_bits(haptics->regmap, DRV2665_CTRL_2, + DRV2665_STANDBY, DRV2665_STANDBY); + if (error) { dev_err(dev, "Failed to set standby mode\n"); regulator_disable(haptics->regulator); - goto out; + return error; } - ret = regulator_disable(haptics->regulator); - if (ret) { + error = regulator_disable(haptics->regulator); + if (error) { dev_err(dev, "Failed to disable regulator\n"); regmap_update_bits(haptics->regmap, DRV2665_CTRL_2, DRV2665_STANDBY, 0); + return error; } } -out: - mutex_unlock(&haptics->input_dev->mutex); - return ret; + + return 0; } static int drv2665_resume(struct device *dev) { struct drv2665_data *haptics = dev_get_drvdata(dev); - int ret = 0; + int error; - mutex_lock(&haptics->input_dev->mutex); + guard(mutex)(&haptics->input_dev->mutex); if (input_device_enabled(haptics->input_dev)) { - ret = regulator_enable(haptics->regulator); - if (ret) { + error = regulator_enable(haptics->regulator); + if (error) { dev_err(dev, "Failed to enable regulator\n"); - goto out; + return error; } - ret = regmap_update_bits(haptics->regmap, DRV2665_CTRL_2, - DRV2665_STANDBY, 0); - if (ret) { + error = regmap_update_bits(haptics->regmap, DRV2665_CTRL_2, + DRV2665_STANDBY, 0); + if (error) { dev_err(dev, "Failed to unset standby mode\n"); regulator_disable(haptics->regulator); - goto out; + return error; } } -out: - mutex_unlock(&haptics->input_dev->mutex); - return ret; + return 0; } static DEFINE_SIMPLE_DEV_PM_OPS(drv2665_pm_ops, drv2665_suspend, drv2665_resume); From patchwork Wed Sep 4 04:42:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789694 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.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 3A77612E1EE; Wed, 4 Sep 2024 04:43:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424992; cv=none; b=bac8GqCQnVsyjuomGN3+8gddw2jhuhIVNnAPegWOyVM+UwmsLwLKLR38QBzmoDFWCMA/FuwDamx/WhBM0Jr4uXXPwJUdjdxI4sKeOO99dgVwebppL86iD8eZaiwXFFTnksmaY4SJ2V2ARFWU4wPT6FoxT3Lr8F+XLVjDQekJkXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424992; c=relaxed/simple; bh=+QCYpClhTtmr9oxKcjIusJ3w9NUyshfTFgW/7Dfamok=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SiEOB3Sv4I3YArp8Tus46X6ObOS5/Fa2dhFnf+6zI1XOY5dWKOZgt1A+/sHBK3MbRnPKLZDFkVC7UmrDPY82h0GQeBMxdT0mY5JmxZZEpRcN/K9uk6AcxoqcEFcwKxLB7H9vFDO1ni6TDlDGcO1JB52okTTQoUDdtY780aBBgJw= 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=KHOkwgEJ; arc=none smtp.client-ip=209.85.214.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="KHOkwgEJ" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2068a7c9286so17730755ad.1; Tue, 03 Sep 2024 21:43:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725424989; x=1726029789; 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=2T8reovlUAD3Peiwe00gk1a2SyLBGNIf5F8eFsRkOIA=; b=KHOkwgEJU5aZnW9w1eI4dO5oBcuRjvRyb42UWyb5xrEc4QyVwGUIlUaIt9HiJefnYo jkGkMMLcrl7zk5pMSBhrTUBHWaWgeZNO0AabG2ydsTe5Ij+FnFEyoVghk0+GcFfc3bss HJdfo9rLB6rLjRBUWGULvhQrog32IByYCVOYtD3/kHqY3CsouoVMoViaXB46NFFMQsyU Y+tI+jRn6F6takSayA48c/tRiCbUo985XWx6Vq2amT+JwPfJcmDujGovbKTvaQVSDb6X Ot9h5uOE+ypr5jmJNhL7RBJgo5weNASrPkqQI8W/DizUtZ0j1WNIYI/Vs6DVBUUwMFH/ iVsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725424989; x=1726029789; 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=2T8reovlUAD3Peiwe00gk1a2SyLBGNIf5F8eFsRkOIA=; b=oI4NyolpIx0rHcjoT+Coyglw2dcuxSi/VvL+A9ZoGv7oRTwa5C/Mp/R6xe21jAutXX f34Ut5K1SnO+0tuy3dxUkQro3SvVcVXko7OSAspobPDhJSQKuF+nZ79fki/1FGfn58ar +FZ++06S4wdxlQjykU/f/5AP7F/Yf+fcYLfp/UJto72f14n6YoXUQCgKcW4+J0+HEz0e 9La6qkvJ/BY50N7B4ylkGilVgywWwLO508CKTLzC27N85JbDQiFp6zaQy1JSZ2ArFn1r WpROyneAKI6V8yF1SN4jR5LyGwjWkStZpsVoY1FkY5fY/tB5sCQF1X4F8FRrl85kOacZ CPdg== X-Forwarded-Encrypted: i=1; AJvYcCVEFBaCU/pN3BZCUef4Z8Jt8XBr0gn3G9cArU+ZcxQvjZkVTPveT+fwbpQRbpdwZmwRcoeIcwhir8Tdjp8=@vger.kernel.org X-Gm-Message-State: AOJu0YzHkEjIgki5G8lSogYEqAAccxreHDG+75kMKIKMQC+VtPGSXvTb wvfByyACpF9BQhld7WXDecv+QVrHUmb1Yw0U+Y9W7/jfYZolH9xPuQgnAg== X-Google-Smtp-Source: AGHT+IGORmxL/SQuwsCZkQ3nC4/WLtFGKhEMLIfdw0V/9CXgLV5KYObwTLCund5/qyilAWA2un+ABA== X-Received: by 2002:a17:903:2286:b0:202:38d8:173 with SMTP id d9443c01a7336-205841a60ddmr81282225ad.29.1725424989323; Tue, 03 Sep 2024 21:43:09 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae951c13sm5727665ad.103.2024.09.03.21.43.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:43:08 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 09/22] Input: drv2667 - use guard notation when acquiring mutex Date: Tue, 3 Sep 2024 21:42:29 -0700 Message-ID: <20240904044244.1042174-10-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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: Javier Carrasco --- drivers/input/misc/drv2667.c | 44 +++++++++++++++++------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/drivers/input/misc/drv2667.c b/drivers/input/misc/drv2667.c index ad49845374b9..906292625f84 100644 --- a/drivers/input/misc/drv2667.c +++ b/drivers/input/misc/drv2667.c @@ -402,59 +402,57 @@ static int drv2667_probe(struct i2c_client *client) static int drv2667_suspend(struct device *dev) { struct drv2667_data *haptics = dev_get_drvdata(dev); - int ret = 0; + int error; - mutex_lock(&haptics->input_dev->mutex); + guard(mutex)(&haptics->input_dev->mutex); if (input_device_enabled(haptics->input_dev)) { - ret = regmap_update_bits(haptics->regmap, DRV2667_CTRL_2, - DRV2667_STANDBY, DRV2667_STANDBY); - if (ret) { + error = regmap_update_bits(haptics->regmap, DRV2667_CTRL_2, + DRV2667_STANDBY, DRV2667_STANDBY); + if (error) { dev_err(dev, "Failed to set standby mode\n"); regulator_disable(haptics->regulator); - goto out; + return error; } - ret = regulator_disable(haptics->regulator); - if (ret) { + error = regulator_disable(haptics->regulator); + if (error) { dev_err(dev, "Failed to disable regulator\n"); regmap_update_bits(haptics->regmap, DRV2667_CTRL_2, DRV2667_STANDBY, 0); + return error; } } -out: - mutex_unlock(&haptics->input_dev->mutex); - return ret; + + return 0; } static int drv2667_resume(struct device *dev) { struct drv2667_data *haptics = dev_get_drvdata(dev); - int ret = 0; + int error; - mutex_lock(&haptics->input_dev->mutex); + guard(mutex)(&haptics->input_dev->mutex); if (input_device_enabled(haptics->input_dev)) { - ret = regulator_enable(haptics->regulator); - if (ret) { + error = regulator_enable(haptics->regulator); + if (error) { dev_err(dev, "Failed to enable regulator\n"); - goto out; + return error; } - ret = regmap_update_bits(haptics->regmap, DRV2667_CTRL_2, - DRV2667_STANDBY, 0); - if (ret) { + error = regmap_update_bits(haptics->regmap, DRV2667_CTRL_2, + DRV2667_STANDBY, 0); + if (error) { dev_err(dev, "Failed to unset standby mode\n"); regulator_disable(haptics->regulator); - goto out; + return error; } } -out: - mutex_unlock(&haptics->input_dev->mutex); - return ret; + return 0; } static DEFINE_SIMPLE_DEV_PM_OPS(drv2667_pm_ops, drv2667_suspend, drv2667_resume); From patchwork Wed Sep 4 04:42:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789695 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 632C012F5B3; Wed, 4 Sep 2024 04:43:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424992; cv=none; b=coq4Vj8ZrYUqKrHA+eGrsdTlMGneKUOlhPLk9W4Q3eHLQKBsXTStHrv+cijiTyj4YZI0SYjDtxYXdnqTOPu+IjVGcQJK+uRDR+JYUz5YWV79S0k/N1NgkTSpBLQ2SCH6CifJDDJqtMEJsdCnS62QsaRdvoN07A/fQHYVDs2oVrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725424992; c=relaxed/simple; bh=1Pt6or8cuLRPc9wW+hTjki8JybNe3kymIZ/5ddMvGr8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OqSifD2bTdwqWNvc6nPFtQ9bKsA49UPyvOZ0m7nwg8fj6bq6rYy/dtinSjsj/kBSOhaLrjj1KCalDcNymW1s1ey74Q6stm0wM3SW5F0Fbuj6cZt50Z/i9CmOxw+j4dfIOLLuz8S3ucaqgTJdm6ABdafmczzpaXdosUm/MJHVxFQ= 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=E4Q5UMPo; arc=none smtp.client-ip=209.85.214.171 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="E4Q5UMPo" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2055136b612so34892585ad.0; Tue, 03 Sep 2024 21:43:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725424990; x=1726029790; 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=xV5jGamf0WtM+OqwlCcf8yN7/00KMm+XqnA+y9L7oQk=; b=E4Q5UMPonUibQLZs+bPE5qP6Q1yez027p6I95bSnbtO+lJBA7WyUc5ZiEyyMSBQaKA HDxKTU4SiaKBnfnx5qVO+ovoirEbmdu4wGHSw06w8IZSZ6+Z3KQZFtq3ZViT7EGKgRVF WSCwGznb2GRdVMFYDo5yPr5uTRPn+YtCm5hO9g1M4f0NA7UvlwluzN7fZvdqbO6wC9HN 30Yeva60XWWaDd+WGtU+gRmJYJSlmp+JJsEvFMKs4jJup4bM+Z/7ymtBSvUl6WSzFx9G 3s3gMOGnBYxQIb+Dn+74sAGVvYKCre1gcZAt0kR0DGhzJ/6SOL8UGMtkbCYB+EJrXFsi YPwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725424990; x=1726029790; 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=xV5jGamf0WtM+OqwlCcf8yN7/00KMm+XqnA+y9L7oQk=; b=CMjFA0+NXrT0sF15UakkPPNodNG9d19WRJn4C1zpS4LvSKx/dfqVCS1ABsVA0ZEfJu J4sJiscPo4JDI6N83IPdv+/I50PNc1VAmAbnuCmfbjPP3Nd+SDofc78Rmmu0pzse1FDP FRSBliNlCAIkIknv1Az1y+AaZ+L8iY5hSZs16aFpIC97udVT4bQQxYDacMf+FSLNla6c LORGk0SEznXBbxjJ3TwUqk2s68IufIviaGlxULfTO32mgDBSDQDxrZYAa9/WIyG2FvsD BPzkbnQVwgDAY6G+PPXSPMHalMiggURRGxjKmJqvyZS5DpYA4q3utn1fYy10I7DXjbtE FAbA== X-Forwarded-Encrypted: i=1; AJvYcCUyDcgpI8Y0Mp9edOLdGhymc3VmotcH+Ib4SC0xWbzh8YKVvgrIzqs2DTupkYwTmCE99V5wRZtlJj1NFv0=@vger.kernel.org X-Gm-Message-State: AOJu0YwxF/qZLfeTmwUKRm23Q+5Kn1eNH+I4oSSyhCXf6aCv3pSwtma6 3IsmwIh/7aD7GWmnmOok7L/heRMx3Ah9dzxybsKY9Nb7hRndSR8c5czSTg== X-Google-Smtp-Source: AGHT+IHFL6ukxR/ccsMugP5VjPf9FnxxkLtel9Fym4Edwu4xHTBNAqg6vXiFm3NDAZZbOn1qkQYwPA== X-Received: by 2002:a17:903:1cf:b0:203:a279:a144 with SMTP id d9443c01a7336-2054650bf3dmr163102295ad.25.1725424990447; Tue, 03 Sep 2024 21:43:10 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae951c13sm5727665ad.103.2024.09.03.21.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:43:10 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 10/22] Input: ideapad_slidebar - use guard notation when acquiring spinlock Date: Tue, 3 Sep 2024 21:42:30 -0700 Message-ID: <20240904044244.1042174-11-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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 Reviewed-by: Javier Carrasco --- drivers/input/misc/ideapad_slidebar.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/drivers/input/misc/ideapad_slidebar.c b/drivers/input/misc/ideapad_slidebar.c index fa4e7f67d713..592bd159a194 100644 --- a/drivers/input/misc/ideapad_slidebar.c +++ b/drivers/input/misc/ideapad_slidebar.c @@ -95,41 +95,29 @@ static struct platform_device *slidebar_platform_dev; static u8 slidebar_pos_get(void) { - u8 res; - unsigned long flags; + guard(spinlock_irqsave)(&io_lock); - spin_lock_irqsave(&io_lock, flags); outb(0xf4, 0xff29); outb(0xbf, 0xff2a); - res = inb(0xff2b); - spin_unlock_irqrestore(&io_lock, flags); - - return res; + return inb(0xff2b); } static u8 slidebar_mode_get(void) { - u8 res; - unsigned long flags; + guard(spinlock_irqsave)(&io_lock); - spin_lock_irqsave(&io_lock, flags); outb(0xf7, 0xff29); outb(0x8b, 0xff2a); - res = inb(0xff2b); - spin_unlock_irqrestore(&io_lock, flags); - - return res; + return inb(0xff2b); } static void slidebar_mode_set(u8 mode) { - unsigned long flags; + guard(spinlock_irqsave)(&io_lock); - spin_lock_irqsave(&io_lock, flags); outb(0xf7, 0xff29); outb(0x8b, 0xff2a); outb(mode, 0xff2b); - spin_unlock_irqrestore(&io_lock, flags); } static bool slidebar_i8042_filter(unsigned char data, unsigned char str, From patchwork Wed Sep 4 04:47:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789696 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 776C4635; Wed, 4 Sep 2024 04:47:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425263; cv=none; b=hGrIUUaALsEMa88kz3zMYRQYU1YltNsITsa5VIAnagemPHm5lDy8XWRtz5o/daN3gJbfaL7tEeenLzHTKu+QA71dN/itrz0nwIUYqMCxvFpKcPhTklshHoG5E+N4ojb25QNdwtEyI5bQgZ508e1d58ASG4y/a0g1vCwKE8bSKps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425263; c=relaxed/simple; bh=UfoRdmNk/XYFtIzagaoRqPWgeFpbrTmSQZq4azm6Zc8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cMO8IPRodubiUGO55ANiP7E2DvxfGa3DtLRIAKlEg3Euyx3pw7tN+6POpfO1nkJkh4b7/QGNCcgqSczJU/9SlTlZYIqjGYDMyxZ3HUEp2X9G7EiXEvz2lxy9/mgDcdqUA8TF0FmvdStLIwghg/+SWnABEyJVlvBepC1nVMyme+c= 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=TNqDlc+O; arc=none smtp.client-ip=209.85.210.176 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="TNqDlc+O" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-71767ef16b3so1375589b3a.0; Tue, 03 Sep 2024 21:47:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725425261; x=1726030061; 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=HaWnxQRR5EhXIyZCyKMArrzFlASuF/6sHrZCH/pRRu0=; b=TNqDlc+ObZ3cdqcnxZWJG9OHUuhbonCZcnkPWxk+OSnH6S1iraHTfyOumQPZxwGoUw V58vst6x2Nm6RPlbm0V5GMmJUMIGT3+eOfp4Qxh8nRK/ruA5CnO7Z1eXejNAmhgDDr4G Arty5MeHuODzg1ZWHrds145IJZrlwNgqMY8Ii4xDrtRDkXywPh9nFiRJRiW262cLwjdO SK3eld5xOr554p2v6Vd3l4An06BD3sw/O0c8Va5BghUdkEDQiSnMTpuP57bcbpbANOtU tjHmpAQP2Xo2/91rPphn7BuaUl08b01rEtvTvMwGlBEyJzcbfKOdyVWj1H14YDzEU5h+ etTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725425261; x=1726030061; 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=HaWnxQRR5EhXIyZCyKMArrzFlASuF/6sHrZCH/pRRu0=; b=Ba246QM2L+YpPLsK+ASu5GWihpJnFOcOeSSNuP3A3LA/EBcUwZ8hELygkwQ6QEzLgr c5ogeVRo+kpioH114CTEREAaonIW5OZQCCPf35hoB8Ippi6XE/54FX2d2nPU9YBLjrv8 +V1NXozdwYFZvXAM5L+d9FzbdaggOSccykiTqRxHsaGTUbyd4grEqzeNRI2hnxL4pVbF WX+gHpBkaX9S13UmdmIUhvqKU/wdsf7A3cpyLRMT0QPHy4dzml6t/CeqhRjCqPmQa5Zv Q5PjHsN0DOxYXfmo4tYt07/VhNXa50gfQNroKCSemJxLrzL9WvSooWZFFDuimqq1CKtT r0lQ== X-Forwarded-Encrypted: i=1; AJvYcCUYdnQ6Dvnkwh5Ne9/aGITe2OUitFZ62+bTUQCvhQnRhTcJzLHbL0FI8iYtdAa/a/9tnpkJQN1H5ay4jtY=@vger.kernel.org X-Gm-Message-State: AOJu0YwuZYX4OQPfGlOxpeHFukr4q/7vwS5ByLNE0mHRydP3oEoLQbWj Ex5GfaJQEx3pQ7a3igFumUCpvDM0gVq+evun5Fwyr+GdTlmRKv+SeGCuzA== X-Google-Smtp-Source: AGHT+IH2CdS/UypR16T7AMe0GB1VgEku/dxvrySvQbIWqCHvxWedibg09mnGSR2Ofxaxr1UpmqTLnA== X-Received: by 2002:a05:6a00:2e90:b0:713:f127:ad5c with SMTP id d2e1a72fcca58-717449c68demr10729173b3a.28.1725425260953; Tue, 03 Sep 2024 21:47:40 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-717785a70fdsm698350b3a.188.2024.09.03.21.47.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:47:40 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 11/22] Input: ibm-panel - use guard notation when acquiring spinlock Date: Tue, 3 Sep 2024 21:47:33 -0700 Message-ID: <20240904044735.1047285-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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 Reviewed-by: Javier Carrasco Reviewed-by: Eddie James --- drivers/input/misc/ibm-panel.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/input/misc/ibm-panel.c b/drivers/input/misc/ibm-panel.c index 867ac7aa10d2..aa48f62d7ea0 100644 --- a/drivers/input/misc/ibm-panel.c +++ b/drivers/input/misc/ibm-panel.c @@ -77,12 +77,11 @@ static void ibm_panel_process_command(struct ibm_panel *panel) static int ibm_panel_i2c_slave_cb(struct i2c_client *client, enum i2c_slave_event event, u8 *val) { - unsigned long flags; struct ibm_panel *panel = i2c_get_clientdata(client); dev_dbg(&panel->input->dev, "event: %u data: %02x\n", event, *val); - spin_lock_irqsave(&panel->lock, flags); + guard(spinlock_irqsave)(&panel->lock); switch (event) { case I2C_SLAVE_STOP: @@ -114,8 +113,6 @@ static int ibm_panel_i2c_slave_cb(struct i2c_client *client, break; } - spin_unlock_irqrestore(&panel->lock, flags); - return 0; } From patchwork Wed Sep 4 04:47:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789697 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.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 D7C1847A6A; Wed, 4 Sep 2024 04:47:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425281; cv=none; b=O4m5g2uflzT50htQ0wnc2rwvcBSFJI04E599KQsL8KvuRqyRdwkz+105Lp/oOVLbZ83rdTxR6VqTwc9sQNC7mdvROWBMvvKf5IoLBNXGcqsOZKqeFxG1vd78c/Heik34Nride8SzS3ZOfvBBdR4oM8cTsdf5uPJuZOErcqX1LPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425281; c=relaxed/simple; bh=XzuF0WAITKAGkM6GQTvjbAvIys92eTsF/ZZlU1T/dtA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=czVIy/bbUrLhLh5HPSg3aRUwsTyCnjDyyai/RVxncNillshUGJKID6KajSEnq8k0/oXursdQZZVLSDIyMktY2j9WrkxREeCmllKmMbYJzeMegHjDKzISP7shMhbWBwR5wX+c65kg6V8LU8/CsL9oAt1i3syMGZcgu7QP1EXC3sA= 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=XL9p4Rrf; arc=none smtp.client-ip=209.85.215.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="XL9p4Rrf" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-7cd8803fe0aso312455a12.0; Tue, 03 Sep 2024 21:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725425279; x=1726030079; 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=V77A++HLf9lpZI2obJz1GB0ENLYF8i6nppAYlu8YwEA=; b=XL9p4RrfqrxCuZo4qjeFZBIfy7VIaA7JdIi7RwhB4sjpqJFCU/Azw4vGzuNTxxwpFI nn6a8aO7dpU7uR0lWcPOFBDjeQB+060OVrXFBOsh5wantJ0okwaBphE0ZmPYOKftOjax bvWuwKR8pJxcjKDAp91W4L4gb9tBi7NUua55MBX4gwNrlGNT0bBjdcv6SgKkysp91Qaz mYCULdsR8KjMHmQaZOil1Tq+AJPnZxKJLkfykLJrZfIGa5HZyBhEJ35FKdzcFRlSX0B2 uM8ZWZBe1Q3PqeXb1SVWhVVjWua0GUMenqbJOzY2rDBSpZ+Vj6gMoqY3N9yR9pFUimp+ /AIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725425279; x=1726030079; 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=V77A++HLf9lpZI2obJz1GB0ENLYF8i6nppAYlu8YwEA=; b=spbrGcBNTgQkD+qNEl8DEApTYxJNe/zNPnmE0Ew9030z9TI73YIIodUup636vLwIQO huiSTjQmn88tY/2qWHug9/FuQ9HTLnr3X2Pw4vPpy8VXWhcaUFg0ASvctxoPdKSwBxIX 3+l8uRT8wEjMHBHSd94yLPLsoKJPo3V/byRoCLl4vYmfUH7UsWYurYtaZHSjaYGQRReG isrk9+SgpNGKnWI53I6HJTMyhlTmAuVzG6G1d6OKnp0Nb1FEXAoteiggxCXnKNXAEILp I5KqR8cc38s83Y4IprX6YmBeG8+ghliy4mx02dfIlOe8lcphdCfLWg6b7sln8h/iz+fi Sc+Q== X-Forwarded-Encrypted: i=1; AJvYcCVFrWrwaomQE/etkMXnD2GL3HOFTdXDamX+7HR8b5UlpfXhe3t/Bm/sVeOuVX3gA5GPWlTChkl3uJjr5dM=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0r8FZoO6+eWShirMIj3sHw+FMKM43oZl8LOBvWI106+bMJssl JHk/S8rSiGBTv5n33GVlpGtIdIdQg0UPM5Sd20OO9Xx9Blu+6LDkDURB8A== X-Google-Smtp-Source: AGHT+IFpspVJ8zUAOGCf+pCI+Ry0xtQO1WKzqSTSQ2FcvjTqYYYAEo41E1DGVJ5DxIugN+IFMV5t7w== X-Received: by 2002:a05:6a21:1693:b0:1ce:d6ea:2163 with SMTP id adf61e73a8af0-1ced6ea3fd6mr13310718637.25.1725425278694; Tue, 03 Sep 2024 21:47:58 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae953dadsm5790245ad.92.2024.09.03.21.47.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:47:58 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 12/22] Input: iqs269a - use guard notation when acquiring mutex Date: Tue, 3 Sep 2024 21:47:55 -0700 Message-ID: <20240904044756.1047629-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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: Jeff LaBundy --- drivers/input/misc/iqs269a.c | 46 +++++++++++++----------------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/drivers/input/misc/iqs269a.c b/drivers/input/misc/iqs269a.c index 843f8a3f3410..c34d847fa4af 100644 --- a/drivers/input/misc/iqs269a.c +++ b/drivers/input/misc/iqs269a.c @@ -365,7 +365,7 @@ static int iqs269_ati_mode_set(struct iqs269_private *iqs269, if (mode > IQS269_CHx_ENG_A_ATI_MODE_MAX) return -EINVAL; - mutex_lock(&iqs269->lock); + guard(mutex)(&iqs269->lock); engine_a = be16_to_cpu(ch_reg[ch_num].engine_a); @@ -375,8 +375,6 @@ static int iqs269_ati_mode_set(struct iqs269_private *iqs269, ch_reg[ch_num].engine_a = cpu_to_be16(engine_a); iqs269->ati_current = false; - mutex_unlock(&iqs269->lock); - return 0; } @@ -389,9 +387,9 @@ static int iqs269_ati_mode_get(struct iqs269_private *iqs269, if (ch_num >= IQS269_NUM_CH) return -EINVAL; - mutex_lock(&iqs269->lock); + guard(mutex)(&iqs269->lock); + engine_a = be16_to_cpu(ch_reg[ch_num].engine_a); - mutex_unlock(&iqs269->lock); engine_a &= IQS269_CHx_ENG_A_ATI_MODE_MASK; *mode = (engine_a >> IQS269_CHx_ENG_A_ATI_MODE_SHIFT); @@ -429,7 +427,7 @@ static int iqs269_ati_base_set(struct iqs269_private *iqs269, return -EINVAL; } - mutex_lock(&iqs269->lock); + guard(mutex)(&iqs269->lock); engine_b = be16_to_cpu(ch_reg[ch_num].engine_b); @@ -439,8 +437,6 @@ static int iqs269_ati_base_set(struct iqs269_private *iqs269, ch_reg[ch_num].engine_b = cpu_to_be16(engine_b); iqs269->ati_current = false; - mutex_unlock(&iqs269->lock); - return 0; } @@ -453,9 +449,9 @@ static int iqs269_ati_base_get(struct iqs269_private *iqs269, if (ch_num >= IQS269_NUM_CH) return -EINVAL; - mutex_lock(&iqs269->lock); + guard(mutex)(&iqs269->lock); + engine_b = be16_to_cpu(ch_reg[ch_num].engine_b); - mutex_unlock(&iqs269->lock); switch (engine_b & IQS269_CHx_ENG_B_ATI_BASE_MASK) { case IQS269_CHx_ENG_B_ATI_BASE_75: @@ -491,7 +487,7 @@ static int iqs269_ati_target_set(struct iqs269_private *iqs269, if (target > IQS269_CHx_ENG_B_ATI_TARGET_MAX) return -EINVAL; - mutex_lock(&iqs269->lock); + guard(mutex)(&iqs269->lock); engine_b = be16_to_cpu(ch_reg[ch_num].engine_b); @@ -501,8 +497,6 @@ static int iqs269_ati_target_set(struct iqs269_private *iqs269, ch_reg[ch_num].engine_b = cpu_to_be16(engine_b); iqs269->ati_current = false; - mutex_unlock(&iqs269->lock); - return 0; } @@ -515,10 +509,9 @@ static int iqs269_ati_target_get(struct iqs269_private *iqs269, if (ch_num >= IQS269_NUM_CH) return -EINVAL; - mutex_lock(&iqs269->lock); - engine_b = be16_to_cpu(ch_reg[ch_num].engine_b); - mutex_unlock(&iqs269->lock); + guard(mutex)(&iqs269->lock); + engine_b = be16_to_cpu(ch_reg[ch_num].engine_b); *target = (engine_b & IQS269_CHx_ENG_B_ATI_TARGET_MASK) * 32; return 0; @@ -1199,7 +1192,7 @@ static int iqs269_dev_init(struct iqs269_private *iqs269) { int error; - mutex_lock(&iqs269->lock); + guard(mutex)(&iqs269->lock); /* * Early revisions of silicon require the following workaround in order @@ -1210,19 +1203,19 @@ static int iqs269_dev_init(struct iqs269_private *iqs269) error = regmap_multi_reg_write(iqs269->regmap, iqs269_tws_init, ARRAY_SIZE(iqs269_tws_init)); if (error) - goto err_mutex; + return error; } error = regmap_update_bits(iqs269->regmap, IQS269_HALL_UI, IQS269_HALL_UI_ENABLE, iqs269->hall_enable ? ~0 : 0); if (error) - goto err_mutex; + return error; error = regmap_raw_write(iqs269->regmap, IQS269_SYS_SETTINGS, &iqs269->sys_reg, sizeof(iqs269->sys_reg)); if (error) - goto err_mutex; + return error; /* * The following delay gives the device time to deassert its RDY output @@ -1232,10 +1225,7 @@ static int iqs269_dev_init(struct iqs269_private *iqs269) iqs269->ati_current = true; -err_mutex: - mutex_unlock(&iqs269->lock); - - return error; + return 0; } static int iqs269_input_init(struct iqs269_private *iqs269) @@ -1580,13 +1570,11 @@ static ssize_t hall_enable_store(struct device *dev, if (error) return error; - mutex_lock(&iqs269->lock); + guard(mutex)(&iqs269->lock); iqs269->hall_enable = val; iqs269->ati_current = false; - mutex_unlock(&iqs269->lock); - return count; } @@ -1643,13 +1631,11 @@ static ssize_t rx_enable_store(struct device *dev, if (val > 0xFF) return -EINVAL; - mutex_lock(&iqs269->lock); + guard(mutex)(&iqs269->lock); ch_reg[iqs269->ch_num].rx_enable = val; iqs269->ati_current = false; - mutex_unlock(&iqs269->lock); - return count; } From patchwork Wed Sep 4 04:48: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: 13789698 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.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 1E9C881AC6; Wed, 4 Sep 2024 04:48:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425290; cv=none; b=VFFFH6Kpxx2+5tIcn/MHytjNvHYtllQY/ak68PHCcy10ZXKdWlIUNGlv6p3VF3Axk2lIhF/VnB1fit5rLRX+sJIsA4ZmLYoWt2UPRwEeps6gjPhC3LRtNoW08MeCbg+wHsymdx74lCgYTg81ZiFaimwJh8xYjjkbgfdDjeJjnv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425290; c=relaxed/simple; bh=MX5l2245cWCFyuhSmKfBVeeYOzs0rOpu1V+s5MOaWJw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o/IKFRwaBR9mDT2lQ9brT0NKibiphB0kUYP6I7c3vrcHvPoVw+Sm3FJTeRxPWJLYNnc8exD3ZLjRx2GGTC1XtRhwhlmEQUI81JDTW6Zi0VwdH96LKciiww/7463N2pftoPgEt64c2FMxg5o9VI+cNYwYqyurp5zjHHyIFKfDsV4= 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=QQ9riGPe; arc=none smtp.client-ip=209.85.214.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="QQ9riGPe" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-204d391f53bso43382765ad.2; Tue, 03 Sep 2024 21:48:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725425288; x=1726030088; 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=mnxH3T+Ol4TDlhRgYhMY4wGMLL57Q4XBAJGggFJOTOY=; b=QQ9riGPe9dSB05xRIWsoMSxZE0Y2fbqHf+9jfkU5WCXL43ag/+yKhFy52l38pwPJZk WuQLvBMVko+ah/y1hLo/1XUoHZoy8TwvEubzw1LWihkO0jRr5HG+Qgy46sFGPKc9JM+P 3Kw+bCGe4SwcR0K8RfVRTJDa16CpnXZLv1z8Ak9dn8JybCFDthBEicRJm3h4S3eXuOMo g7GB0XbBqp6LxJ/mQSRxhDPTNvhHEVMGpCn5vVuydFZYPEX5Zuh+wNbcz6yRTitJCSoo IU89o9n708lASq69vS4EciI2z9e5Zh3jQnL6gk+9fjmkFBdQ5OL78yvuUpPsmLsNbZRd QBtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725425288; x=1726030088; 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=mnxH3T+Ol4TDlhRgYhMY4wGMLL57Q4XBAJGggFJOTOY=; b=S9izdsxo9zNK9+WPKqzfhSiSv4YL1JOM/POZ1Qi47SbEF0Qd3tQcySwU/j0qSTtKCD W+Zs694Fity53yZuRBCVeryan10cG/bu45SpU+hNBnFpPNT7zcYvZAfAbvPrIT8B4+LA bnJi3ORRp2oQUOw8BW+zPJW9YpZ+Kj7gBvLBB0dpgCOLclOUM/PtKUnT4689VYOwoJQF 4/1zxCw3YH9D3NqO8+P2Y0DPCzh6cMIhkQrOVgJjP9ORZS4xTFu4MD4TYncyuZaPGspj 8kc1Ta280W0piylgJYO99XhqhequXZ7/Rm2OuMOgCzRsx5rGntYbbdWcBkSVnFjv3yaS cDuQ== X-Forwarded-Encrypted: i=1; AJvYcCXbe5Znt6XvqUSFyb9cda3W0aB7PphUQVUadbCTjX9Ie6E56VXEMxfo1QYV3nQMKN7RCx4nbyDZvNMFxQI=@vger.kernel.org X-Gm-Message-State: AOJu0YzWj4vhFwRu+rx/m9EXUsd0zm6WUhPKSBEF6jnd8NVVOW0KX7V/ j60ICPvg1jatzWvw9RpyVWKFjPtqE8cZEYxAaOJLlsxnF0PTJK1Ea2UPKw== X-Google-Smtp-Source: AGHT+IGCNNDATluGCJQMVRn/XlNKlVLUKMJL9/RA/MWvy83Qu6cCSjryl1F2mI6VPQlSSd31efn2kQ== X-Received: by 2002:a17:902:d58f:b0:1fd:aac9:a72e with SMTP id d9443c01a7336-205476430bcmr128155175ad.43.1725425288242; Tue, 03 Sep 2024 21:48:08 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae9131dbsm5769765ad.62.2024.09.03.21.48.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:48:07 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 13/22] Input: iqs269a - use cleanup facility for fwnodes Date: Tue, 3 Sep 2024 21:48:05 -0700 Message-ID: <20240904044806.1047847-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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: Javier Carrasco Reviewed-by: Jeff LaBundy --- drivers/input/misc/iqs269a.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/input/misc/iqs269a.c b/drivers/input/misc/iqs269a.c index c34d847fa4af..1851848e2cd3 100644 --- a/drivers/input/misc/iqs269a.c +++ b/drivers/input/misc/iqs269a.c @@ -550,7 +550,6 @@ static int iqs269_parse_chan(struct iqs269_private *iqs269, const struct fwnode_handle *ch_node) { struct i2c_client *client = iqs269->client; - struct fwnode_handle *ev_node; struct iqs269_ch_reg *ch_reg; u16 engine_a, engine_b; unsigned int reg, val; @@ -727,8 +726,9 @@ static int iqs269_parse_chan(struct iqs269_private *iqs269, } for (i = 0; i < ARRAY_SIZE(iqs269_events); i++) { - ev_node = fwnode_get_named_child_node(ch_node, - iqs269_events[i].name); + struct fwnode_handle *ev_node __free(fwnode_handle) = + fwnode_get_named_child_node(ch_node, + iqs269_events[i].name); if (!ev_node) continue; @@ -737,7 +737,6 @@ static int iqs269_parse_chan(struct iqs269_private *iqs269, dev_err(&client->dev, "Invalid channel %u threshold: %u\n", reg, val); - fwnode_handle_put(ev_node); return -EINVAL; } @@ -751,7 +750,6 @@ static int iqs269_parse_chan(struct iqs269_private *iqs269, dev_err(&client->dev, "Invalid channel %u hysteresis: %u\n", reg, val); - fwnode_handle_put(ev_node); return -EINVAL; } @@ -767,7 +765,6 @@ static int iqs269_parse_chan(struct iqs269_private *iqs269, } error = fwnode_property_read_u32(ev_node, "linux,code", &val); - fwnode_handle_put(ev_node); if (error == -EINVAL) { continue; } else if (error) { From patchwork Wed Sep 4 04:48: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: 13789699 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 003B382866; Wed, 4 Sep 2024 04:48:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425299; cv=none; b=JC531pwypra/zqnzpB06TTA30LZUpjg6eGKbwPguCBfMBqLiipTf+mW5B4P8hrJ7ws4IL1A7YORgl/Kg0zYKeeh85T1DeQP7Q0B+N+2nuGctYeOTcYOBOFFrpt8fB3w7m81yU6K1aswXHmFFAJkww4JOWiUMnxUvoIvetsNIVZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425299; c=relaxed/simple; bh=FflQ4qz5JVnnnMDPwm8UqfGtcO0cKx77kcMuOsvE81o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lgr8B4KxM5XQtLlg9pefj1RWG1Jyna3PUp7bj8BcfuwEfeIQW8jC5PcwhW9NitBB8nsy0GInQ5S3mTfJXWMgOPOTRoZu0Vt3zTvU8hMEPuaDAYj7XqihJ/hD9+n5GSCLvTGVWwgmNygf7Iib7XXZN1/UcdSVqWJmXSf8LOAyS3s= 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=evVIMEWc; arc=none smtp.client-ip=209.85.214.171 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="evVIMEWc" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2053a0bd0a6so39132415ad.3; Tue, 03 Sep 2024 21:48:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725425297; x=1726030097; 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=lENcgYQuI00iy6j6bXO670dW3Fp3O318OXfbMbYxm2E=; b=evVIMEWckj+gOOwtKaRFyGmYXMCLOuUYeJM0tPraN0TzudcmQ6PnMCdR9TWCifOnSP Uxao94QzFJPb4jD5Vy0HstywraP/3j5/Wk6dWf+12kwwd9zDsLUUVFP4GWBstS71kaUV c3tTNxVx6VxhRKUWqEFany6/J5l6stncqdnoZ2r9rOxoK8ghd/J+N31RMyNEmgq/qKpA S+YbVr8IJwx9hveneyyCKTwkaJcEVXf1+J4OKdX2jcA4PwP4feSBtFKWLR9T6TlPFNhN TM4/Ss8tVPuWWD3gUICrgq8xIMSeVEtBYMFUhKmoV608JCqCK3PgreRq0wN1R+dPXFEm 8cJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725425297; x=1726030097; 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=lENcgYQuI00iy6j6bXO670dW3Fp3O318OXfbMbYxm2E=; b=lLNDeNLPpEB0wPOx9b24Ere/ZqBzHsss1RvuEorCxBXgJTG1SfNxRop5hw1qa/M3VG poa4BR/D59KTlDWN7ERaVb5TKUbIMBeQVXy+JZxByA5LD+KOZc37Ol2w6mmLNk+sLBFa Vhcx5Mn+ACjQQmx5dUX/hBCy4ozSdKnLsj1yWErWJPMKoQztriu5iSgsFMVnqKh5gn9E kSJYMjkffVr0zjWxKJKlubEy5yoBgTbE9I+vF0QoHqQUHHSqriH/DgB0mw2dYyzXNdsK QDMlW3dcJofVhXXr610fxZq/VWobdl1i+GZxrUeDUoxTVMIJPjsfWjrdm9vGjlc5QFWn 1mbw== X-Forwarded-Encrypted: i=1; AJvYcCWx8H8nTOaR0Jke2SjYo7SAiOY8rjsZO5zUMpZOvUSXL2n6vY0Z+WFMjp3o5UNcvvglh67E93YVUnDfrpw=@vger.kernel.org X-Gm-Message-State: AOJu0YzXUPzCc5XfeiOioNouMAgiGM/Z2ImZiKyhClx61uh8tH22SLTS ofHHPx3zelr1Gp6WtyQlz6loNgHu7IIeKANbxs5y2R+tmcU0agHXg0jUuw== X-Google-Smtp-Source: AGHT+IExTTRLClg9mGxPiOHjn8IlhbjvIT9ij/VL2ZI/6vUhFmjWuz4edhNiyUuSgZ9BZBXgpFFYpQ== X-Received: by 2002:a17:90b:3812:b0:2c9:6aa9:1d76 with SMTP id 98e67ed59e1d1-2da62fde7efmr5017176a91.18.1725425296793; Tue, 03 Sep 2024 21:48:16 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d85b0fe266sm12320014a91.11.2024.09.03.21.48.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:48:16 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 14/22] Input: iqs626a - use cleanup facility for fwnodes Date: Tue, 3 Sep 2024 21:48:13 -0700 Message-ID: <20240904044814.1048062-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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: Javier Carrasco Reviewed-by: Jeff LaBundy --- drivers/input/misc/iqs626a.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/drivers/input/misc/iqs626a.c b/drivers/input/misc/iqs626a.c index 0dab54d3a060..7a6e6927f331 100644 --- a/drivers/input/misc/iqs626a.c +++ b/drivers/input/misc/iqs626a.c @@ -462,7 +462,6 @@ iqs626_parse_events(struct iqs626_private *iqs626, { struct iqs626_sys_reg *sys_reg = &iqs626->sys_reg; struct i2c_client *client = iqs626->client; - struct fwnode_handle *ev_node; const char *ev_name; u8 *thresh, *hyst; unsigned int val; @@ -501,6 +500,7 @@ iqs626_parse_events(struct iqs626_private *iqs626, if (!iqs626_channels[ch_id].events[i]) continue; + struct fwnode_handle *ev_node __free(fwnode_handle) = NULL; if (ch_id == IQS626_CH_TP_2 || ch_id == IQS626_CH_TP_3) { /* * Trackpad touch events are simply described under the @@ -530,7 +530,6 @@ iqs626_parse_events(struct iqs626_private *iqs626, dev_err(&client->dev, "Invalid input type: %u\n", val); - fwnode_handle_put(ev_node); return -EINVAL; } @@ -545,7 +544,6 @@ iqs626_parse_events(struct iqs626_private *iqs626, dev_err(&client->dev, "Invalid %s channel hysteresis: %u\n", fwnode_get_name(ch_node), val); - fwnode_handle_put(ev_node); return -EINVAL; } @@ -566,7 +564,6 @@ iqs626_parse_events(struct iqs626_private *iqs626, dev_err(&client->dev, "Invalid %s channel threshold: %u\n", fwnode_get_name(ch_node), val); - fwnode_handle_put(ev_node); return -EINVAL; } @@ -575,8 +572,6 @@ iqs626_parse_events(struct iqs626_private *iqs626, else *(thresh + iqs626_events[i].th_offs) = val; } - - fwnode_handle_put(ev_node); } return 0; @@ -774,12 +769,12 @@ static int iqs626_parse_trackpad(struct iqs626_private *iqs626, for (i = 0; i < iqs626_channels[ch_id].num_ch; i++) { u8 *ati_base = &sys_reg->tp_grp_reg.ch_reg_tp[i].ati_base; u8 *thresh = &sys_reg->tp_grp_reg.ch_reg_tp[i].thresh; - struct fwnode_handle *tc_node; char tc_name[10]; snprintf(tc_name, sizeof(tc_name), "channel-%d", i); - tc_node = fwnode_get_named_child_node(ch_node, tc_name); + struct fwnode_handle *tc_node __free(fwnode_handle) = + fwnode_get_named_child_node(ch_node, tc_name); if (!tc_node) continue; @@ -790,7 +785,6 @@ static int iqs626_parse_trackpad(struct iqs626_private *iqs626, dev_err(&client->dev, "Invalid %s %s ATI base: %u\n", fwnode_get_name(ch_node), tc_name, val); - fwnode_handle_put(tc_node); return -EINVAL; } @@ -803,14 +797,11 @@ static int iqs626_parse_trackpad(struct iqs626_private *iqs626, dev_err(&client->dev, "Invalid %s %s threshold: %u\n", fwnode_get_name(ch_node), tc_name, val); - fwnode_handle_put(tc_node); return -EINVAL; } *thresh = val; } - - fwnode_handle_put(tc_node); } if (!fwnode_property_present(ch_node, "linux,keycodes")) @@ -1233,7 +1224,6 @@ static int iqs626_parse_prop(struct iqs626_private *iqs626) { struct iqs626_sys_reg *sys_reg = &iqs626->sys_reg; struct i2c_client *client = iqs626->client; - struct fwnode_handle *ch_node; unsigned int val; int error, i; u16 general; @@ -1375,13 +1365,13 @@ static int iqs626_parse_prop(struct iqs626_private *iqs626) sys_reg->active = 0; for (i = 0; i < ARRAY_SIZE(iqs626_channels); i++) { - ch_node = device_get_named_child_node(&client->dev, - iqs626_channels[i].name); + struct fwnode_handle *ch_node __free(fwnode_handle) = + device_get_named_child_node(&client->dev, + iqs626_channels[i].name); if (!ch_node) continue; error = iqs626_parse_channel(iqs626, ch_node, i); - fwnode_handle_put(ch_node); if (error) return error; From patchwork Wed Sep 4 04:48:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789700 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.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 848D1823A9; Wed, 4 Sep 2024 04:48:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425310; cv=none; b=azTMgqmCvLirIoPq2TXSPYtrF9TdhR6Lh5rEbxjtWpd0HV1jBi1av6FMSB14EKxgVNHpJoBiEzj7EXQm93Mpms4WAyDO5zYol4jlyxrgVdW595umY0Kgh/3Q63Aw/dom3LnrHueygAWrB/175pNThblK1bMw5/5mCjZ4NxSxmB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425310; c=relaxed/simple; bh=4f0a7RMGVEaFLLMDvCfdgQS4qMzwfU5Zv9nYxQhpP7w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ftwq9pRPoGoaehUf1npAuYIfcSE3BlTkT3eL/qmcU/kPGG/MV9/y2l7K45Qh7W6cpWP9TKQu/ih0OGXPhu/V2qonH1VzjNUapixbzEo2iPvCGc0uxYyj3yB6wkhrFk8UygQaTz3uH9heC6cMtD+CVBQSjHMMtaGGHe1Fzsnv7w4= 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=OjGVOujk; arc=none smtp.client-ip=209.85.210.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="OjGVOujk" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7141285db14so5198042b3a.1; Tue, 03 Sep 2024 21:48:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725425308; x=1726030108; 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=oWAIKnqWBa9v7wl3AMunuiCdn7/Enw0Y7rIDLTFVb+s=; b=OjGVOujkDm4gTGN3w5cldh0IVVz/1+edjAu02TWfUysHR4tWo9MbheDnuIG2ffHDRh ljWmLBc7a5+sJ1N+LXw4uen8xgMYRzyJFmVAVLIx5/jnwrO+V13t0L0GLjSkVJpOEvHV lrZcPkOt9AkWYRW6fC68So2WDzh4HWGaV1dRCVdxK4gqJGNVd28zgIumneoIG2rNF3t0 M219KDK0PANUrwDpAd6xGMjjoK6riGqo1W19WgnqmxepIastlgWI3vb5cjj+p0ii/39d FAa8CS+AGIfIcbw5haNnqkwgMQnxl1W7BB1kC3M7ctCJy8yIipsFABOzh+pZsvezZdr9 8etg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725425308; x=1726030108; 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=oWAIKnqWBa9v7wl3AMunuiCdn7/Enw0Y7rIDLTFVb+s=; b=nZnWLA+hmcFGUED9hEO7zlPDaak6kbCdw+oK+PUBUZ0oD31dQpQctGAkUiE1VJKVbY m25sTGUW3hrdi57U5p1ZOxkAroEqEqERYa0llzGbmTcgO4nzzkhRgFla0Qw4xw7SoP66 AiWllufHQQyav21OJKEPJUKs85NV0VDaxLAEiDSQAbE/jbnC6jl6ssZKv3d1FAjp3jdb +3UkcZ+Uz5GiUQohx/6YxQYYFZEpOqX4zoiT1T1qxQQSAoB5CqlG48IKyYuExC4gpcie fU5o7Eub9PhC1fAxsM9HaGZI/bmS46F1HDpS2mUe56t/ENYYP/rGuB2YJN/mjzOyvFAb i/cA== X-Forwarded-Encrypted: i=1; AJvYcCUQZfZrWrZuuihLSB+ikn8kYOHtkrgJEUsQDLlf3LVTLZcUxanDQncp+e+OXSoHH5NgQeEqqkT9H/9w+/M=@vger.kernel.org X-Gm-Message-State: AOJu0YyXfeZFhum3cUEGhV2to2utVC0Z4MwfrQykALnrbzQiZSnTZLGx h1dHCdIGmQJ021DsK1EwmaV3fT+Ck0j/feoom7a5XqP0oJ+9IDNC4xI6ew== X-Google-Smtp-Source: AGHT+IGn79LEbWhdhwOTPZBdO2a4PuoJ5GJDvJEIEIgvNDAAVpfZNV2plGXAtZezzDnZm8lhPqng/Q== X-Received: by 2002:a05:6a00:22c6:b0:706:74be:686e with SMTP id d2e1a72fcca58-7173b6b6229mr16457733b3a.26.1725425307569; Tue, 03 Sep 2024 21:48:27 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71778520e66sm717098b3a.21.2024.09.03.21.48.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:48:27 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 15/22] Input: iqs7222 - use cleanup facility for fwnodes Date: Tue, 3 Sep 2024 21:48:25 -0700 Message-ID: <20240904044825.1048256-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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: Javier Carrasco Reviewed-by: Jeff LaBundy --- drivers/input/misc/iqs7222.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/input/misc/iqs7222.c b/drivers/input/misc/iqs7222.c index 9ca5a743f19f..d9b87606ff7a 100644 --- a/drivers/input/misc/iqs7222.c +++ b/drivers/input/misc/iqs7222.c @@ -2385,9 +2385,9 @@ static int iqs7222_parse_chan(struct iqs7222_private *iqs7222, for (i = 0; i < ARRAY_SIZE(iqs7222_kp_events); i++) { const char *event_name = iqs7222_kp_events[i].name; u16 event_enable = iqs7222_kp_events[i].enable; - struct fwnode_handle *event_node; - event_node = fwnode_get_named_child_node(chan_node, event_name); + struct fwnode_handle *event_node __free(fwnode_handle) = + fwnode_get_named_child_node(chan_node, event_name); if (!event_node) continue; @@ -2408,7 +2408,6 @@ static int iqs7222_parse_chan(struct iqs7222_private *iqs7222, dev_err(&client->dev, "Invalid %s press timeout: %u\n", fwnode_get_name(event_node), val); - fwnode_handle_put(event_node); return -EINVAL; } @@ -2418,7 +2417,6 @@ static int iqs7222_parse_chan(struct iqs7222_private *iqs7222, dev_err(&client->dev, "Failed to read %s press timeout: %d\n", fwnode_get_name(event_node), error); - fwnode_handle_put(event_node); return error; } @@ -2429,7 +2427,6 @@ static int iqs7222_parse_chan(struct iqs7222_private *iqs7222, dev_desc->touch_link - (i ? 0 : 2), &iqs7222->kp_type[chan_index][i], &iqs7222->kp_code[chan_index][i]); - fwnode_handle_put(event_node); if (error) return error; @@ -2604,10 +2601,10 @@ static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222, for (i = 0; i < ARRAY_SIZE(iqs7222_sl_events); i++) { const char *event_name = iqs7222_sl_events[i].name; - struct fwnode_handle *event_node; enum iqs7222_reg_key_id reg_key; - event_node = fwnode_get_named_child_node(sldr_node, event_name); + struct fwnode_handle *event_node __free(fwnode_handle) = + fwnode_get_named_child_node(sldr_node, event_name); if (!event_node) continue; @@ -2639,7 +2636,6 @@ static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222, : sldr_setup[4 + reg_offset], NULL, &iqs7222->sl_code[sldr_index][i]); - fwnode_handle_put(event_node); if (error) return error; @@ -2742,9 +2738,9 @@ static int iqs7222_parse_tpad(struct iqs7222_private *iqs7222, for (i = 0; i < ARRAY_SIZE(iqs7222_tp_events); i++) { const char *event_name = iqs7222_tp_events[i].name; - struct fwnode_handle *event_node; - event_node = fwnode_get_named_child_node(tpad_node, event_name); + struct fwnode_handle *event_node __free(fwnode_handle) = + fwnode_get_named_child_node(tpad_node, event_name); if (!event_node) continue; @@ -2760,7 +2756,6 @@ static int iqs7222_parse_tpad(struct iqs7222_private *iqs7222, iqs7222_tp_events[i].link, 1566, NULL, &iqs7222->tp_code[i]); - fwnode_handle_put(event_node); if (error) return error; @@ -2818,9 +2813,9 @@ static int iqs7222_parse_reg_grp(struct iqs7222_private *iqs7222, int reg_grp_index) { struct i2c_client *client = iqs7222->client; - struct fwnode_handle *reg_grp_node; int error; + struct fwnode_handle *reg_grp_node __free(fwnode_handle) = NULL; if (iqs7222_reg_grp_names[reg_grp]) { char reg_grp_name[16]; @@ -2838,14 +2833,17 @@ static int iqs7222_parse_reg_grp(struct iqs7222_private *iqs7222, error = iqs7222_parse_props(iqs7222, reg_grp_node, reg_grp_index, reg_grp, IQS7222_REG_KEY_NONE); + if (error) + return error; - if (!error && iqs7222_parse_extra[reg_grp]) + if (iqs7222_parse_extra[reg_grp]) { error = iqs7222_parse_extra[reg_grp](iqs7222, reg_grp_node, reg_grp_index); + if (error) + return error; + } - fwnode_handle_put(reg_grp_node); - - return error; + return 0; } static int iqs7222_parse_all(struct iqs7222_private *iqs7222) From patchwork Wed Sep 4 04:48:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789701 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 97F17824AC; Wed, 4 Sep 2024 04:48:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425318; cv=none; b=uNBRzjXVaKklcgyMuOUgIEJJrInO/g6iqfR8Y6KW51D6zt10ut1JoTp6ROm8pg0PJ4NudjqJCtK76lTCJ/uNTH/3WRt/1ncDGnWMCC2SCf6ULH2jSzC1xzn/yvXPsv4MPOXmeSCqh28/4HpAl09D+/0s248VAfPwtQiOWiuMY0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425318; c=relaxed/simple; bh=+sJCHBs05d5XAEiDqdU0Kg0HhhyIg2rxMZOxVqZJKMg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hJxGMggxtbDe9HPEss7A913sP+pZckENzRsDQ8EQvSBSul4liR5gkpesQaNzqkE2almiHp2rlZt4PIzdvdwh6sXre7TL9q9WTyKeUmmNOusE8QhxRtMYOO5X9eRBELJOJNdnppq29cqPdAfhSHakXcALM72XSlOmKmmRrpPmGxo= 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=F/FkpZAa; arc=none smtp.client-ip=209.85.216.46 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="F/FkpZAa" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-2d8f06c2459so1681667a91.0; Tue, 03 Sep 2024 21:48:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725425316; x=1726030116; 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=vQyGz6AvMInN2zNoaaQnQeciLOQyRW21Wcs2MhQ1DXw=; b=F/FkpZAa1gfdTbARrqVwIjLi3E16PnXbtDCMDFSt/Nb+rvRub5ZOVswZ+veT09bhvN 3RKZiTGL/qwL0gNfzUhuSWK2q3mOXdWfCtMxie8/OuQa14Fdyk59ZJBB05QA3yDn5b9o DToNfsyYcQ3q5zQjsYQPlQBGhtHhlNniL6x7NzIR+uJSLeREw1jlnLqzaJGMqEQL32Z0 /b9hmfKD24wtzSMJXW43kJcwKliiyHAYRaNhEs2EIfOaVMD49n6IEwThD+OfH3XESwLy m6p9NWE4Wn1qY/ZwDIbTK0G8HNKee/z8XU6kg+aYhow34W6WS2GFrFg6Y8/JaVCJgM1u KO9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725425316; x=1726030116; 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=vQyGz6AvMInN2zNoaaQnQeciLOQyRW21Wcs2MhQ1DXw=; b=SVEP2+EKdU7H8YPes/jY6OrEkkBBFU8iV2TBHfo/U0Ztwv8IJp1RmBkuONgdluaQZA FFEtOVRQHH9HSqAbC/cgN7cjqAYTZP8VgXbqtlCKMBEOprY0VdKQEm0XodCLMOFXcRoy djjlqXEkhqT8T5IElgjA02J7LaOYhxMmb4tEA6jwT9SWgdpzS9G0JbSrnANQDCJOIM8v Haf9lRXVVn3Kt3hJK99lZ0EoQ5/VIwchGq+WLPYVf3AEI+phILI04fTI0jsRlhM72DB9 Mdc6Cy50IZjnbnIkcCazxkbcspb/Q5R0vIHdVX+UNCVAM9IsQxGd40NfMJ46re/cb+bV OnEw== X-Forwarded-Encrypted: i=1; AJvYcCXhMtw0YDSJaxdoczZgpVU8AOqqYjwN/RWM6XWVYfM1IG+JjVmj6kub0oAMSP/2S7El8UKiFj5NcZKdDu8=@vger.kernel.org X-Gm-Message-State: AOJu0YxTGgZdlVIlEfxbfvm1Usxn6v6fwvH9gk/BuRJnWg88UbpHVFdI nfU34HkvO8skYotpPj+r7jXivS5YzXyZWFqKjQu7ppw2ItPS5YJnSUnIbQ== X-Google-Smtp-Source: AGHT+IHVXuFImtk9unJ2lcRJdwgQdZ6afQn5WeSiERAD9YXRyWhkeY4NIG5Rmkd78fBBk3I2jOTgdg== X-Received: by 2002:a17:90b:3a92:b0:2d8:f99d:48d2 with SMTP id 98e67ed59e1d1-2da55a4400emr5488932a91.29.1725425315648; Tue, 03 Sep 2024 21:48:35 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d85b3b95e8sm12334081a91.54.2024.09.03.21.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:48:35 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 16/22] Input: max8997_haptic - use guard notation when acquiring mutex Date: Tue, 3 Sep 2024 21:48:33 -0700 Message-ID: <20240904044834.1048468-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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: Javier Carrasco --- drivers/input/misc/max8997_haptic.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/input/misc/max8997_haptic.c b/drivers/input/misc/max8997_haptic.c index 11cac4b7dddc..2853455daef2 100644 --- a/drivers/input/misc/max8997_haptic.c +++ b/drivers/input/misc/max8997_haptic.c @@ -153,19 +153,19 @@ static void max8997_haptic_enable(struct max8997_haptic *chip) { int error; - mutex_lock(&chip->mutex); + guard(mutex)(&chip->mutex); error = max8997_haptic_set_duty_cycle(chip); if (error) { dev_err(chip->dev, "set_pwm_cycle failed, error: %d\n", error); - goto out; + return; } if (!chip->enabled) { error = regulator_enable(chip->regulator); if (error) { dev_err(chip->dev, "Failed to enable regulator\n"); - goto out; + return; } max8997_haptic_configure(chip); if (chip->mode == MAX8997_EXTERNAL_MODE) { @@ -173,19 +173,16 @@ static void max8997_haptic_enable(struct max8997_haptic *chip) if (error) { dev_err(chip->dev, "Failed to enable PWM\n"); regulator_disable(chip->regulator); - goto out; + return; } } chip->enabled = true; } - -out: - mutex_unlock(&chip->mutex); } static void max8997_haptic_disable(struct max8997_haptic *chip) { - mutex_lock(&chip->mutex); + guard(mutex)(&chip->mutex); if (chip->enabled) { chip->enabled = false; @@ -194,8 +191,6 @@ static void max8997_haptic_disable(struct max8997_haptic *chip) pwm_disable(chip->pwm); regulator_disable(chip->regulator); } - - mutex_unlock(&chip->mutex); } static void max8997_haptic_play_effect_work(struct work_struct *work) From patchwork Wed Sep 4 04:48:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789702 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.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 5142882486; Wed, 4 Sep 2024 04:48:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425329; cv=none; b=tXD5dURA/cCzdcDI+jZbfU29tL5Bhf4fcPLrcG9XWOBOSu65wCq1n7aLow7sIXLjl5U//xhS4QqMHMtV/cWhNUF25fdJCISLWhSW2/bUMVsK2NPBLFQs+IAL6v2Owc2FOCFN0v4cP87cOD0qRSrLbb0O2AsKnZSpHf7/EQyYs3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425329; c=relaxed/simple; bh=qYXli+rMDzDdxksshgRO0eamRjvRQceGJSKtyCxtcoc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uRGGC4WNW+nhVUStq6BFfulbqaBFucMqRnIiUOAXSVKIvl65hVzoTLwtvdCLnKOVT19Ue4rtdDtWTMMsmIpEs3FbQ3cIwCWB84mitM+1mqd0jatI6bDHYERaR1nxGc/X/Qshn3btSns/aVrmYGYHlgxdPqdGmUYig/yvY9Eo+wY= 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=cpEzmcG5; arc=none smtp.client-ip=209.85.214.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="cpEzmcG5" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-20696938f86so12097875ad.3; Tue, 03 Sep 2024 21:48:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725425327; x=1726030127; 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=s5yyqOr6cGCL7nTVS+XsLNq9IrclibEZcZLI/ZlueT8=; b=cpEzmcG5rBiSoBEjk7mdoHP3IeXXbCq2dq/n+TQPA8KyYwvrfuq1shT3pINhGpt7Fc KOyNOkvJgX+QR7iGSH0EevHFjJ/EmIBGaON3grEj9IpMMYxpNNrTiBRa2P8PUbA30IfT isR/dAwAe/9q/VoM/7tFYNPgH03Ta9DVJWDtuk87/cWVGQxoSHCxvkIMagV9nGw6cQ7A uC/N0p41Q5EBlor6fGjptZMH5lbJlfeaHWYtMn5Lye5o7uiiUHyNsnbIgKYsyjW/GWjv 9pFRajsj3roWw2woEOrHsPBooJ3qiivRV65cGmKwuhBWPJ2BVowhQJ0K1sPxcrxWftda lLoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725425327; x=1726030127; 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=s5yyqOr6cGCL7nTVS+XsLNq9IrclibEZcZLI/ZlueT8=; b=BJ0AVyi9eAYN3hRDCHL1j/FzjlHOSgqSFlvM3F9IaOYsvTev38E6/fcu9y2BjTSST2 PLWNcP1OaRT4OF2t5+rrCm0iO2rjLrS1R8uB7+/SW2PpAj/SgfT6WYtn0euGPp7Zl4eJ /Y74fKaqKS3IUSG/31FeHSVrczrf+nod7ofOam23fqcLQKsxOilBxZ7adHRNCqIRwtib 26L9rWrs1p+Wz/0BVd1IRIporHOA8jxdL2UXdJBdE50mfPV3lNDM1dPseuYtgYROAbeg XSKJd8CXGvWWSRMwB5c4sSV18RNI44prUkNnhIiKkagSmy2668slhQ03wmZiZm4yn2lE rgCw== X-Forwarded-Encrypted: i=1; AJvYcCWCsIs9TFeFioyw1r5+SBS8UG/Q9ffw3ZSiYbHrMi0GouGT5+4fyDjdwPeO/b5bkcVmoYie/kvg9daLqpA=@vger.kernel.org X-Gm-Message-State: AOJu0YzNOMUBFT/WbBzgT7Byhuvx3Yk1+0BdQP/8uS1VgVbzLQF7Nvda Ffbx7mxgI+jg0lurIu2HU11F/hHvRV0h0x/jDUhHIELwCo0G0qlrIrQ1+w== X-Google-Smtp-Source: AGHT+IGtfLzPi3XmtSZZfqjZoloiJmZZ2HyIixI1FkpsrYzpRUo8YsaJMsNneqbi1+dpPdkyXlsPFw== X-Received: by 2002:a17:902:f650:b0:206:88fa:54a6 with SMTP id d9443c01a7336-20688fa580emr59269835ad.21.1725425327293; Tue, 03 Sep 2024 21:48:47 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206aea56918sm5652615ad.218.2024.09.03.21.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:48:47 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 17/22] Input: pegasus_notetaker - use guard notation when acquiring mutex Date: Tue, 3 Sep 2024 21:48:41 -0700 Message-ID: <20240904044842.1048638-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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: Javier Carrasco --- drivers/input/tablet/pegasus_notetaker.c | 86 +++++++++++++----------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/drivers/input/tablet/pegasus_notetaker.c b/drivers/input/tablet/pegasus_notetaker.c index a68da2988f9c..e1dc8365bfe9 100644 --- a/drivers/input/tablet/pegasus_notetaker.c +++ b/drivers/input/tablet/pegasus_notetaker.c @@ -214,6 +214,28 @@ static void pegasus_init(struct work_struct *work) error); } +static int __pegasus_open(struct pegasus *pegasus) +{ + int error; + + guard(mutex)(&pegasus->pm_mutex); + + pegasus->irq->dev = pegasus->usbdev; + if (usb_submit_urb(pegasus->irq, GFP_KERNEL)) + return -EIO; + + error = pegasus_set_mode(pegasus, PEN_MODE_XY, NOTETAKER_LED_MOUSE); + if (error) { + usb_kill_urb(pegasus->irq); + cancel_work_sync(&pegasus->init); + return error; + } + + pegasus->is_open = true; + return 0; +} + + static int pegasus_open(struct input_dev *dev) { struct pegasus *pegasus = input_get_drvdata(dev); @@ -223,39 +245,25 @@ static int pegasus_open(struct input_dev *dev) if (error) return error; - mutex_lock(&pegasus->pm_mutex); - pegasus->irq->dev = pegasus->usbdev; - if (usb_submit_urb(pegasus->irq, GFP_KERNEL)) { - error = -EIO; - goto err_autopm_put; + error = __pegasus_open(pegasus); + if (error) { + usb_autopm_put_interface(pegasus->intf); + return error; } - error = pegasus_set_mode(pegasus, PEN_MODE_XY, NOTETAKER_LED_MOUSE); - if (error) - goto err_kill_urb; - - pegasus->is_open = true; - mutex_unlock(&pegasus->pm_mutex); return 0; - -err_kill_urb: - usb_kill_urb(pegasus->irq); - cancel_work_sync(&pegasus->init); -err_autopm_put: - mutex_unlock(&pegasus->pm_mutex); - usb_autopm_put_interface(pegasus->intf); - return error; } static void pegasus_close(struct input_dev *dev) { struct pegasus *pegasus = input_get_drvdata(dev); - mutex_lock(&pegasus->pm_mutex); - usb_kill_urb(pegasus->irq); - cancel_work_sync(&pegasus->init); - pegasus->is_open = false; - mutex_unlock(&pegasus->pm_mutex); + scoped_guard(mutex, &pegasus->pm_mutex) { + usb_kill_urb(pegasus->irq); + cancel_work_sync(&pegasus->init); + + pegasus->is_open = false; + } usb_autopm_put_interface(pegasus->intf); } @@ -411,10 +419,10 @@ static int pegasus_suspend(struct usb_interface *intf, pm_message_t message) { struct pegasus *pegasus = usb_get_intfdata(intf); - mutex_lock(&pegasus->pm_mutex); + guard(mutex)(&pegasus->pm_mutex); + usb_kill_urb(pegasus->irq); cancel_work_sync(&pegasus->init); - mutex_unlock(&pegasus->pm_mutex); return 0; } @@ -422,31 +430,33 @@ static int pegasus_suspend(struct usb_interface *intf, pm_message_t message) static int pegasus_resume(struct usb_interface *intf) { struct pegasus *pegasus = usb_get_intfdata(intf); - int retval = 0; - mutex_lock(&pegasus->pm_mutex); + guard(mutex)(&pegasus->pm_mutex); + if (pegasus->is_open && usb_submit_urb(pegasus->irq, GFP_NOIO) < 0) - retval = -EIO; - mutex_unlock(&pegasus->pm_mutex); + return -EIO; - return retval; + return 0; } static int pegasus_reset_resume(struct usb_interface *intf) { struct pegasus *pegasus = usb_get_intfdata(intf); - int retval = 0; + int error; + + guard(mutex)(&pegasus->pm_mutex); - mutex_lock(&pegasus->pm_mutex); if (pegasus->is_open) { - retval = pegasus_set_mode(pegasus, PEN_MODE_XY, + error = pegasus_set_mode(pegasus, PEN_MODE_XY, NOTETAKER_LED_MOUSE); - if (!retval && usb_submit_urb(pegasus->irq, GFP_NOIO) < 0) - retval = -EIO; + if (error) + return error; + + if (usb_submit_urb(pegasus->irq, GFP_NOIO) < 0) + return -EIO; } - mutex_unlock(&pegasus->pm_mutex); - return retval; + return 0; } static const struct usb_device_id pegasus_ids[] = { From patchwork Wed Sep 4 04:49:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789703 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.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 D16E381AC6; Wed, 4 Sep 2024 04:49:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425346; cv=none; b=GWs2Ip9AFH1wJwWJcjmmzbKeoIfKi9ZlW0whEpFyAxCGuCeKahGMRlqXkSf1IhiJLYW+W3gSqr0vwfBjJqK4bg9f5zav8XDPsE3KgBRVwIaO6s6Qx1SwevQIMda656BLqt4z6XKotTzR/9oZ66+vasDT2T5aspp+NthcnmHzpqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425346; c=relaxed/simple; bh=6H2O+hymwVqCkSxF4BNUpyqoY9L8X4Xll/N219fJmT0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JADgHig4QZTeVpKOT8zW+1GhWtBBvVDf9OfVAxTik9ahviv9kb7cMtIdiFlyxMZfE18wyHkKr1+kJezvMX9HUnruqY+jqZcgBJlwMzF85kulH3U+ei900fKykE4l3GeywZbD/WWklJw1t9jJgIM6zW0pbN1MzDpp4mmvzxiaK3k= 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=jUQOagCW; arc=none smtp.client-ip=209.85.215.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="jUQOagCW" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-7c6b4222fe3so4035216a12.3; Tue, 03 Sep 2024 21:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725425344; x=1726030144; 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=dcGffBkg5gfBz41muJc+ok399PNqaO5iRm+4RBz3HMU=; b=jUQOagCWUCFBQaTNWChTAEarSzR3OxVkNgB7je/tPlJ/qLTJdJhls/l5J29oBu/Y2J 4CzgkoF+yXgjWQbsxRxPkYJmO9cjFdpNygSeZBQHWm/74ISdrajhIiilbEKV1xH1oSf6 gnJU36qf7ZBbzU9qhkaGwk23ae2OgZcKlimM/10Hne3BPkROyhohIbo4chHhwHeeYsqB RfD0397jn4o5w9YBzVMMcv0l363Tn8nNRBBmaIXZrx6fqYjemy7Oa28U9uszB2z+O1/j Uu6Lmyo6EZCN+Evr6JSllp3DZIYfiCz0/E6Bnx9MfZhvaRajs/ETrS5sL81PHxTyk9Lf DgNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725425344; x=1726030144; 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=dcGffBkg5gfBz41muJc+ok399PNqaO5iRm+4RBz3HMU=; b=F8yTcOCcDBt3xywUnP4x8oVjRo+3Bx3eihIt9qDeUDak+cL2vWvU0xfnAir4yqsGjb CMFaZQfAD37WYjl0hXr9h8HF6IEfzZJ7WLLfHW39pPJdZpyfyRCL8p2hUzda6eeLp7EL cF2BZfVeE8YNpmT7HN3hDQMc+UCTZz80nveXVfird9RErALgUEvGM6qO22lsLAjH+p56 TJbQ4Xm5QYHG9fSBFCaCJQgwXugAkc/9pXQCHwgYDJbG+6FbkgX7mG9Np/6clw7E5xuU 9g+xKE2CDt6giuqZhWoCu6M8sSEYVCH9TFiUwu8Rzygdy2dGC0a+hUGhoHWiEjX5POHy Qwvg== X-Forwarded-Encrypted: i=1; AJvYcCVCFS+Tx/h27QO5hBb9+Z2RRibfsYv636jlQ+XtC8/Tx61ov0l7xpjdeifYhYVbexNKlcDEqNTUYBCTUyI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4LWPLrb+uX0e4L7qbod9hfhUeCEOA0aCasUWd3m0jKjInPx7r L3EBVCyKeFl7Hb+9WyH7PXJ4CBZF8+O2l/+IB7pD2Z7gXJaP8zxaOU8MYQ== X-Google-Smtp-Source: AGHT+IErqCaBS207q6JPA9qp9bojr6rVBoZ9wVsgoquhlnGBD+lWPn4JgjSt08cHAwMFXSCSLgxUGw== X-Received: by 2002:a17:902:f650:b0:205:5de3:b964 with SMTP id d9443c01a7336-2055de3bbe9mr75798305ad.5.1725425343757; Tue, 03 Sep 2024 21:49:03 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206aea392cdsm5727045ad.156.2024.09.03.21.49.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:49:03 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 18/22] Input: powermate - use guard notation when acquiring spinlock Date: Tue, 3 Sep 2024 21:49:00 -0700 Message-ID: <20240904044902.1049017-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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 Reviewed-by: Javier Carrasco --- drivers/input/misc/powermate.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/drivers/input/misc/powermate.c b/drivers/input/misc/powermate.c index 4b039abffc4b..ecb92ee5ebbc 100644 --- a/drivers/input/misc/powermate.c +++ b/drivers/input/misc/powermate.c @@ -194,22 +194,18 @@ static void powermate_sync_state(struct powermate_device *pm) static void powermate_config_complete(struct urb *urb) { struct powermate_device *pm = urb->context; - unsigned long flags; if (urb->status) printk(KERN_ERR "powermate: config urb returned %d\n", urb->status); - spin_lock_irqsave(&pm->lock, flags); + guard(spinlock_irqsave)(&pm->lock); powermate_sync_state(pm); - spin_unlock_irqrestore(&pm->lock, flags); } /* Set the LED up as described and begin the sync with the hardware if required */ static void powermate_pulse_led(struct powermate_device *pm, int static_brightness, int pulse_speed, int pulse_table, int pulse_asleep, int pulse_awake) { - unsigned long flags; - if (pulse_speed < 0) pulse_speed = 0; if (pulse_table < 0) @@ -222,8 +218,7 @@ static void powermate_pulse_led(struct powermate_device *pm, int static_brightne pulse_asleep = !!pulse_asleep; pulse_awake = !!pulse_awake; - - spin_lock_irqsave(&pm->lock, flags); + guard(spinlock_irqsave)(&pm->lock); /* mark state updates which are required */ if (static_brightness != pm->static_brightness) { @@ -245,8 +240,6 @@ static void powermate_pulse_led(struct powermate_device *pm, int static_brightne } powermate_sync_state(pm); - - spin_unlock_irqrestore(&pm->lock, flags); } /* Callback from the Input layer when an event arrives from userspace to configure the LED */ From patchwork Wed Sep 4 04:49: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: 13789704 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.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 0686A47A6A; Wed, 4 Sep 2024 04:49:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425358; cv=none; b=FpYalDXWkqXg4M+k0GC2MFCNvxstH+Ds7CaSxKwPbZ2gsT2iXa9AV6K6A2O9cdHJdPKhmVjfDmCkvvVuK8UreeSYnWdC3MKs6Z89YMToxTXd6kUfhjYSK1H6OX0RLJz4UcYoI8zRE+6256ISAVo11M0apAbTsNJYPk2uqioZhCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425358; c=relaxed/simple; bh=nUdcUk0n40QbjO8u1pYU6pVpuCTqIUYlN9e2hTZhJ0s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KSC15tk75TnBil+Ymu9AIBUbCj3hGpa1i9bgk7pBPB8Y2ZOoj0XErVtfdyByb9jToV25KF1jFydTKMn1DYE9iFI3JxYGFYoqGymPuNyX2wl7F6YgeanUfnmiM+OZP9+0NF8JZw00D4dn0Mp0Eo14xn9jjKZB39ggqQxvhpYpD0g= 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=cvUkLZzq; arc=none smtp.client-ip=209.85.215.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="cvUkLZzq" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-7d4fbe62bf5so429485a12.0; Tue, 03 Sep 2024 21:49:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725425356; x=1726030156; 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=VNM1TbwY3bzDwgc7KYSWOhzEj80svR9YA5h2CIzmPCA=; b=cvUkLZzqt7Z57fPeen2zDEzFrmZUZIHB6utlGBSyXbELWc2Dzna8Ma0AdH8QW6ojbb C/IxqWg4vjYB8zP4BCDFT7acmWxyGQeKzs4U57QoD2SYp81B5MrMBVfrWIi2lIE9GO1O 563MVlLZYJYu6y47uYkrw3f+zR+0uJ+b3Rb35NyJQKRGlwYkp7sHTWierH9xYm1vUa6L h5a4KBd91BS99fXAL3Qekm4vw4JcmhFiWga90bUX7Wh8UT2rJG2TczZN/wMPO1kvfqpR mlA88za5YJBPDXb9PRYKeIKpzZ/i94z3jv7WXNrKfoFD8huSucnGIlMXr5h9SKnGCPHX kqOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725425356; x=1726030156; 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=VNM1TbwY3bzDwgc7KYSWOhzEj80svR9YA5h2CIzmPCA=; b=TgUS3VVsbGYwwRgZpP+LgOTh5Q0T14E5rSxvcUyZN1LHCRAdG1c1JDt501vV/L7lux sN+tbnjnV5wUoTZuvJhlpKO/KQJmH1xZ+3tURMhdmbBSVoFFNiwi5eX42pBZh1Sgb2aQ /2TFD8LLmq+BDQI1E9UugjNrBg0p/UflvMpUTLVApvdPkzKj1O0RM1CNkVVxtGMhkh1G fGH/5/h2fwu3suAByFl3p2Z2cR0CptJJzjIoYhWfnBwEqBp8ADNbgdXpWvsZfjBYocbs M9JPWrLYAAIt/6sBDgcYT6zb0p4GYCJs0UegB8XVJSHwWJwf+EJ1VLAsYQ1GksoGOfeR VWLg== X-Forwarded-Encrypted: i=1; AJvYcCUGit5oJjMJDo80nSQ4EUrNIZCZxUCvBL4zmCqwqI32JDR1Jyj2YGW0UkWDvg0Q/iYUZxug2ScCzuWfhcw=@vger.kernel.org X-Gm-Message-State: AOJu0Yyz20pEDDIIj4tkg1dIDgHO058HwBVs4Ykl9qubXGvJ5Egu5UYK 0l/NbPo7z0hVFTn3LRteg+m6mIpoJbReTHNKoJQsViAHsyX68gULFp49yg== X-Google-Smtp-Source: AGHT+IH96zZqHTBl+pedV3aEY995kllbLfzD8RbqaAZQdE55RmOvvfB7Lg1v1DedpcB2kFL41N/dqA== X-Received: by 2002:a05:6a21:3483:b0:1cc:de68:436b with SMTP id adf61e73a8af0-1cece503ad2mr11545611637.20.1725425355958; Tue, 03 Sep 2024 21:49:15 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae953d92sm5777595ad.73.2024.09.03.21.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:49:15 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 19/22] Input: pwm-beeper - use guard notation when acquiring spinlock Date: Tue, 3 Sep 2024 21:49:12 -0700 Message-ID: <20240904044914.1049280-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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 Reviewed-by: Javier Carrasco --- drivers/input/misc/pwm-beeper.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index 5b9aedf4362f..0e19e97d98ec 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -203,9 +203,9 @@ static int pwm_beeper_suspend(struct device *dev) * beeper->suspended, but to ensure that pwm_beeper_event * does not re-submit work once flag is set. */ - spin_lock_irq(&beeper->input->event_lock); - beeper->suspended = true; - spin_unlock_irq(&beeper->input->event_lock); + scoped_guard(spinlock_irq, &beeper->input->event_lock) { + beeper->suspended = true; + } pwm_beeper_stop(beeper); @@ -216,9 +216,9 @@ static int pwm_beeper_resume(struct device *dev) { struct pwm_beeper *beeper = dev_get_drvdata(dev); - spin_lock_irq(&beeper->input->event_lock); - beeper->suspended = false; - spin_unlock_irq(&beeper->input->event_lock); + scoped_guard(spinlock_irq, &beeper->input->event_lock) { + beeper->suspended = false; + } /* Let worker figure out if we should resume beeping */ schedule_work(&beeper->work); From patchwork Wed Sep 4 04:49: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: 13789705 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 DD2F8823AC; Wed, 4 Sep 2024 04:49:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425366; cv=none; b=I4O7ObI2ABdfyTp5xaVpzpjWI/rpObonypMts38fYUXFw1faLZexjjy7ATsD4zPGTTYrBt/aprvX5citolL2+vMSZNassUd9KBVOt7kCsi8URB9sOmI7k/QpPCkzhjPAQ/88RVoXnUuAwzz+38uB6CiFfuDIshHDB5yiqGqogd8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425366; c=relaxed/simple; bh=iqKox10L/BMJRep//TxFHzNzv1gmE/5Z24V0pFtPVQY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=avjkYjJnRhIgkjf66FR10yurhIEJtPGr6VWXjXZQxuZU77ldYBoSxZKiYJA+EJGteBWcWbBouOV0TzZzdnVy3ADq3ZpcHiIYMgzOn/1Vr2B7sfdjXdAd4EHqeoio7l3Dr47lqecLFypfbHYzfLoTsMoF12otr8DZ5xVBtSDcg50= 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=aoY403BA; arc=none smtp.client-ip=209.85.210.176 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="aoY403BA" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-7176645e440so235192b3a.1; Tue, 03 Sep 2024 21:49:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725425364; x=1726030164; 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=etkHfoK3+2WQV2UCZXnu7S5CCvqcAYWO20wdxeW2yEo=; b=aoY403BAsrdIQv7m916P/LZEFVhlUR9FuPQswGpj6a3Hr0ac2uY/T/vT6oSwfNbaMi PlwG4g0ADEG/bQmJ3l4BtDK16urdJJFQ8DTJ1EBz3OJOclE705wGHS9M8NhGvgKrEMgy PS2um21Mdx/CljxNrQbokbHiAsUC1hXJwKRT5Lz4/NlasC0YHz1vRJArzNE12A+z9Xms UmouVVWislWzReGRvoCngNAqxbHyk2H3ZfKjj+CoQPm77cXZyR+M+j0Ou1JCDtCfCvNE X0yoGmYMCvUK5M/Sq8Cp5q0Xbm78qT9vQvzaHdWH2Zy3vqbCXLmUkhQVW1d8YBSk1PMB 19+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725425364; x=1726030164; 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=etkHfoK3+2WQV2UCZXnu7S5CCvqcAYWO20wdxeW2yEo=; b=NHGolFlbfJVFKxUwJKMcsGzdRc95mp20ICbf8JzL0xoECR+ECoeQeiY458Fe447lcN qzQUhPzbIdVr6gBDbyqO/MM+cl7RObpQaQx+BTTyg7gRhlMmgD+T4gUv7Kt8fGguXnwR yPafb1Tr8sU8UiwO5Xhxlf20Scj5nB2Xys/EsF2la0DD5Gn9NjqYMZ4My9u/myeE7P0o sshE3qR3SrYxmNJpDSUkjuZoAa1xXKtrS7hIi6QLZCZ47w/vmFw1UZsasblFp/5mAezm p8u5ot/Zs4GBa1FT1OFN3kFu1xdMMQn8uolI7WA1y7r2OYbzsTUzuyMoao4MJK47rppv P/9A== X-Forwarded-Encrypted: i=1; AJvYcCUiNKfOBp8O1fE7K/0VKDbnlf5gwrTb5sDrrMZBEuXNXLZ8rSgExTR+uYuPnEKfVNSmClTN+mQNoSR7KMI=@vger.kernel.org X-Gm-Message-State: AOJu0YwcGRsYOHuWGGxamZlihgJblxCGFSKOAxKmC87G3IVYDvScAJJ5 OzCbCwkk56r7Lxo0vT34EUy8O4qJQ1nN/RQlCvcroR4kCkpqUx9x4NpSWw== X-Google-Smtp-Source: AGHT+IHALpm45S59ySVq5byacFcop5zfDsgwFgYetsN9dEUYq0/2ufoexPczwK9EoCE/MgterT83mw== X-Received: by 2002:a05:6a00:2a6:b0:70d:2e89:de2b with SMTP id d2e1a72fcca58-7177a92b56emr1219734b3a.4.1725425363807; Tue, 03 Sep 2024 21:49:23 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71778521099sm718517b3a.6.2024.09.03.21.49.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:49:23 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 20/22] Input: regulator-haptic - use guard notation when acquiring mutex Date: Tue, 3 Sep 2024 21:49:21 -0700 Message-ID: <20240904044922.1049488-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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/misc/regulator-haptic.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/drivers/input/misc/regulator-haptic.c b/drivers/input/misc/regulator-haptic.c index 02f73b7c0462..41af6aefaa07 100644 --- a/drivers/input/misc/regulator-haptic.c +++ b/drivers/input/misc/regulator-haptic.c @@ -83,12 +83,10 @@ static void regulator_haptic_work(struct work_struct *work) struct regulator_haptic *haptic = container_of(work, struct regulator_haptic, work); - mutex_lock(&haptic->mutex); + guard(mutex)(&haptic->mutex); if (!haptic->suspended) regulator_haptic_set_voltage(haptic, haptic->magnitude); - - mutex_unlock(&haptic->mutex); } static int regulator_haptic_play_effect(struct input_dev *input, void *data, @@ -207,17 +205,14 @@ static int regulator_haptic_suspend(struct device *dev) struct regulator_haptic *haptic = platform_get_drvdata(pdev); int error; - error = mutex_lock_interruptible(&haptic->mutex); - if (error) - return error; - - regulator_haptic_set_voltage(haptic, 0); - - haptic->suspended = true; + scoped_guard(mutex_intr, &haptic->mutex) { + regulator_haptic_set_voltage(haptic, 0); + haptic->suspended = true; - mutex_unlock(&haptic->mutex); + return 0; + } - return 0; + return -EINTR; } static int regulator_haptic_resume(struct device *dev) @@ -226,7 +221,7 @@ static int regulator_haptic_resume(struct device *dev) struct regulator_haptic *haptic = platform_get_drvdata(pdev); unsigned int magnitude; - mutex_lock(&haptic->mutex); + guard(mutex)(&haptic->mutex); haptic->suspended = false; @@ -234,8 +229,6 @@ static int regulator_haptic_resume(struct device *dev) if (magnitude) regulator_haptic_set_voltage(haptic, magnitude); - mutex_unlock(&haptic->mutex); - return 0; } From patchwork Wed Sep 4 04:49:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789706 Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) (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 DC8CA82863; Wed, 4 Sep 2024 04:49:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425374; cv=none; b=cN0Vr+8wvP77wuuW9Ui3yhT/yGULQhP9HHyIsc2F4xpIJ/wpdwMNAP+bl7F9K9brQJ6I1m6inU8jwBHcWXQeZDi0g1ojgyV4wMSjordwU2SBMCSAWeQBTP8UhTrf1MGJ1wim/15IVytuT5hLurh9FT2kb87Cx5KKbivG5+1ez8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425374; c=relaxed/simple; bh=SQRFpRxySb02gVqyZ782C5GM1DtxFXd/MlnoQvm/3dY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M3p1ZmgqHxsC1eaN7BfbrT+1GcwdvOuKCt0PORKCQw6mvEyfP9o1gjAW7D+Z6yvjKRLxb6ntTZBO5m70Na74uH7XwL2uA8LYnv2D7WmmjFbG9Z9vApch4Tyj0GzDdd82bnJl8FH+Jrz2HA1IVB6sPwtFyUjbbf9ihWLHOGHcHFM= 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=YIjCz9mU; arc=none smtp.client-ip=209.85.210.54 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="YIjCz9mU" Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-7092dd03223so1990083a34.1; Tue, 03 Sep 2024 21:49:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725425372; x=1726030172; 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=dR9UU1kYO+J4sEnQlebP6OayNwvuBqZFhQRqEobtUCo=; b=YIjCz9mU9GzpjpVjrbRw2A+4HHn+Nzq31ZVjA5obVrUYNZLpu1CsvFAcJx1zANJzSe WjRiglEiLuZ2RswR2XXmRtwwsqm7ZJQJtrkQ8AT+Gz944IjunyvBlFH/uTDXW8tyhyNE 9y1M38uhAFtDwWKM7pFrJghIoGHiZ09y2pr67EvOpLOIT9wEXwGH5w1ToVFEiGE7dfwV snJZMbmjQKn3S4pakWugpJrdfIaLMEZ2v9gbjev7liKUXcF/D8N+/GYBqk58kedUX8Jh m+3WauSXIOUOkTShgtnY4F+BU4+jGB3wWeyM9U8Erj6avloBcgu5Cuy8j+F9cORA+U1J Y9+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725425372; x=1726030172; 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=dR9UU1kYO+J4sEnQlebP6OayNwvuBqZFhQRqEobtUCo=; b=e9h7yl4MXUmFbcvQaPgB81tHOwXCZNSh2FtqTkM+eV8VV1PJHUoobg+nE9B2V5wies m0IsHMGaTGJCezeMnbPcfi1XtmR02orxCkSkTWlqgu5TFirAOpr46OrYzFA+UIPvUZ2Q qLsGOEq0U2ceYWN5R5u9Tk9c3/myEMudA8bhcJ6CXAw0NX9ZXuVUE4RGswYo4lNuX2Ba F44xnnVtQr73o1xVwS/VrR5VzOJcN7+XQEURw8Nhd5ZmXMwPONN+NtJYvLA8SxV2G+73 3FhSD6GvlESGvMZ6AmeQToyPRZjn3bd2+0WFY/RzeoWDJXW4uzO0ggxqsrTQG6qVaMDO S1Mg== X-Forwarded-Encrypted: i=1; AJvYcCVgCqGVO1IQ3AFKlQx1BDVFo+9xJYOTgg250iok9Tfo5skl+bVml36PFUFWfN1LyImgGn1808W91M3Alo4=@vger.kernel.org X-Gm-Message-State: AOJu0YyA2I7gpKYiPb5kQHpipNZTAhfhqrXiq+1xzzPInXH2omyFS5B+ iIuiNQuttnMSC1FSY6vb88rv89uFaqNZRnusffr9JsVqJwdo3Lx9MXV6nQ== X-Google-Smtp-Source: AGHT+IGJMb5zmmPT7Snj4k4w9D6jZ1WLtYhHqNBtwVekeAJ1zWgrmZ6lTgUWxeZ4LbtYBxTd9O7Idw== X-Received: by 2002:a05:6830:621b:b0:709:3d2f:7b48 with SMTP id 46e09a7af769-70f7072eb57mr16296489a34.24.1725425371520; Tue, 03 Sep 2024 21:49:31 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-717785305fbsm718093b3a.45.2024.09.03.21.49.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:49:31 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 21/22] Input: rotary_encoder - use guard notation when acquiring mutex Date: Tue, 3 Sep 2024 21:49:29 -0700 Message-ID: <20240904044929.1049700-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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: Javier Carrasco --- drivers/input/misc/rotary_encoder.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c index 6628fe540834..52761da9f999 100644 --- a/drivers/input/misc/rotary_encoder.c +++ b/drivers/input/misc/rotary_encoder.c @@ -113,7 +113,7 @@ static irqreturn_t rotary_encoder_irq(int irq, void *dev_id) struct rotary_encoder *encoder = dev_id; unsigned int state; - mutex_lock(&encoder->access_mutex); + guard(mutex)(&encoder->access_mutex); state = rotary_encoder_get_state(encoder); @@ -136,8 +136,6 @@ static irqreturn_t rotary_encoder_irq(int irq, void *dev_id) break; } - mutex_unlock(&encoder->access_mutex); - return IRQ_HANDLED; } @@ -146,7 +144,7 @@ static irqreturn_t rotary_encoder_half_period_irq(int irq, void *dev_id) struct rotary_encoder *encoder = dev_id; unsigned int state; - mutex_lock(&encoder->access_mutex); + guard(mutex)(&encoder->access_mutex); state = rotary_encoder_get_state(encoder); @@ -159,8 +157,6 @@ static irqreturn_t rotary_encoder_half_period_irq(int irq, void *dev_id) } } - mutex_unlock(&encoder->access_mutex); - return IRQ_HANDLED; } @@ -169,22 +165,19 @@ static irqreturn_t rotary_encoder_quarter_period_irq(int irq, void *dev_id) struct rotary_encoder *encoder = dev_id; unsigned int state; - mutex_lock(&encoder->access_mutex); + guard(mutex)(&encoder->access_mutex); state = rotary_encoder_get_state(encoder); - if ((encoder->last_stable + 1) % 4 == state) + if ((encoder->last_stable + 1) % 4 == state) { encoder->dir = 1; - else if (encoder->last_stable == (state + 1) % 4) + rotary_encoder_report_event(encoder); + } else if (encoder->last_stable == (state + 1) % 4) { encoder->dir = -1; - else - goto out; - - rotary_encoder_report_event(encoder); + rotary_encoder_report_event(encoder); + } -out: encoder->last_stable = state; - mutex_unlock(&encoder->access_mutex); return IRQ_HANDLED; } From patchwork Wed Sep 4 04:49:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13789707 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 0C9F982866; Wed, 4 Sep 2024 04:49:40 +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=1725425383; cv=none; b=X9d4EeZt4uh5gOeDS21luF95mn5d+NTwUdO32MAaxe/PWsyZI5SgvExE/Z7Xt+ELd2yzY3M3VwlaK9nu2jBzdy2NdQnssL9tnd37OMe3sP4t3Y+tQjVuzDaJnQhcwUaqnbXjViv0L9FhUzyYzRru6y6COM8qYHz0O9MYO+be+68= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725425383; c=relaxed/simple; bh=244eaGPCLz6NFcuG6n2Qsu+nYop+aZf2tGJGUQkgkfg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q6jKyuMJN3w2LkYHm46vJyPiMp6OLRUoAPX28SeadivNIiudBcScpixVKLePPJ2pLM6an86H7VBPXcqKI0cmGXi2P1gh/J15MRLaq4XJpI0+nqPGlqRFVjaLrDqQpft9g+EBdlhkrGiFDGLMp/H0eFOOn3shZ0EIh+xfGHXCXyA= 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=Okw4Wswp; 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="Okw4Wswp" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-71744362c22so2750953b3a.2; Tue, 03 Sep 2024 21:49:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725425380; x=1726030180; 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=1NRWhO6LY9zWWiBrJwXb282nuYaIsKgNXPTyljvk7LI=; b=Okw4WswptM5CYlh+ktI9etXgAAxUX/99zq4GjsmPnkLpm/GS8BGGbg04JOOioo7w0p POpHINVF5XtkzDFruCMTGpYp6+i70amY2DUHMZqS3EqubJBL76H7OOkZ6hA13NhWZk5b WzoXc4w6/CuEICmpHdFcTWuofZcprHUl3QLZLSCUxAJjLeNCNk6g3heqVSwQVQAy3zNb 21yxWutwb/44/eZjT/31c54fXHxZ5U3BWJfx4l8BAgvIiP+7oe5A8odzU6WL+VVlC6lX tHRTbzU92ZcLzMRkeSfAQUWvMBjehYThXRM9HnpvV7jyIYEGKoKk4MjGKVc6I6G/8A/+ UnoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725425380; x=1726030180; 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=1NRWhO6LY9zWWiBrJwXb282nuYaIsKgNXPTyljvk7LI=; b=wNkE3uxRsuRkjEhlZHeVsQTX3Fxu6VonuqPVAfZAjMtbMSmQGxbU1cqA4ewS6H1PUX z3VPPGPnUA/hZOuxFHPUbMVzp39+sb8t43Btap42SHQGiMMafx6aAL3iBUa2sJS1PZnV oggw5FpP0ZNIY3QpzR6cTngaUeHWXUWTnzGaq7WTyrQWXTqwElwmcXe0jZowOYpY45JK reTGAEISDdcti89BEIs56+Uej6oD5Pxb39xNuXPp0b4AlopNSZ174+cGg/xea6Sf1i5F bT+rTHYfW9cAtwNq9vK+zmktfxV7D0+aGUcFBicvcQXEuO/tsIj6/rVZZb7Kxu1h/zJz ku8A== X-Forwarded-Encrypted: i=1; AJvYcCXUksL2rJNw7fZVhB3HLmWHX8/Rv0ckmqtL9EngJWZdZPUhNHAzFDQG+rfpnsZhLSYwf+cYFY76Kg8eneA=@vger.kernel.org X-Gm-Message-State: AOJu0YxSdwm/qA4px2creyQg1ker3+XICMHYzinNzdzCVV726kcvHO/X /KPC+lvx2WmRVmrVZPkEFedU3wh/T9cbG36upHrjmtx/jlrBOQv8A6VnQw== X-Google-Smtp-Source: AGHT+IF1qytLppvDchMO5lIenFDb6wH9CV0iotnj0pfq/GDgQCHL3wX2LPx9GUfLCY26Hw0i92GblA== X-Received: by 2002:a05:6a00:80f:b0:714:2d0d:8a90 with SMTP id d2e1a72fcca58-7174578b8f3mr10345475b3a.9.1725425379838; Tue, 03 Sep 2024 21:49:39 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e682:e3dc:908:eef0]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71778542183sm708581b3a.89.2024.09.03.21.49.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 21:49:39 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Javier Carrasco , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH 22/22] Input: sparcspkr - use guard notation when acquiring spinlock Date: Tue, 3 Sep 2024 21:49:37 -0700 Message-ID: <20240904044938.1049843-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> References: <20240904044244.1042174-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 Using guard notation 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 Reviewed-by: Javier Carrasco --- drivers/input/misc/sparcspkr.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c index 20020cbc0752..5de59ae90c67 100644 --- a/drivers/input/misc/sparcspkr.c +++ b/drivers/input/misc/sparcspkr.c @@ -69,7 +69,6 @@ static int bbc_spkr_event(struct input_dev *dev, unsigned int type, unsigned int struct sparcspkr_state *state = dev_get_drvdata(dev->dev.parent); struct bbc_beep_info *info = &state->u.bbc; unsigned int count = 0; - unsigned long flags; if (type != EV_SND) return -1; @@ -85,7 +84,7 @@ static int bbc_spkr_event(struct input_dev *dev, unsigned int type, unsigned int count = bbc_count_to_reg(info, count); - spin_lock_irqsave(&state->lock, flags); + guard(spinlock_irqsave)(&state->lock); if (count) { sbus_writeb(0x01, info->regs + 0); @@ -97,8 +96,6 @@ static int bbc_spkr_event(struct input_dev *dev, unsigned int type, unsigned int sbus_writeb(0x00, info->regs + 0); } - spin_unlock_irqrestore(&state->lock, flags); - return 0; } @@ -107,7 +104,6 @@ static int grover_spkr_event(struct input_dev *dev, unsigned int type, unsigned struct sparcspkr_state *state = dev_get_drvdata(dev->dev.parent); struct grover_beep_info *info = &state->u.grover; unsigned int count = 0; - unsigned long flags; if (type != EV_SND) return -1; @@ -121,7 +117,7 @@ static int grover_spkr_event(struct input_dev *dev, unsigned int type, unsigned if (value > 20 && value < 32767) count = 1193182 / value; - spin_lock_irqsave(&state->lock, flags); + guard(spinlock_irqsave)(&state->lock); if (count) { /* enable counter 2 */ @@ -136,8 +132,6 @@ static int grover_spkr_event(struct input_dev *dev, unsigned int type, unsigned sbus_writeb(sbus_readb(info->enable_reg) & 0xFC, info->enable_reg); } - spin_unlock_irqrestore(&state->lock, flags); - return 0; }