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: 825433 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 --- 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: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: 825432 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 --- 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: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: 825431 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 --- 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: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: 825430 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 --- 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: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: 825429 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 --- 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: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: 825428 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: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: 825427 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: 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: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: 825426 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 --- 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: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: 825425 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 --- 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 20:55:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 825412 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 C424AD530; Wed, 4 Sep 2024 20:55: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=1725483313; cv=none; b=nwDuJedh++bQ6nofkrTa7aVT4C6NCEgdpWFnLV7fD/UjWQyg6LfoAowpVj2epUKdOQxdHJN4RJshQkD53l4E8KN1Qlru1HZpcwKTiOG0hNwQN5HSFT5svSXQR0CqwUXSxGSlx4rkvqfz3LoUNV1d3+iYvb2KTQSFCQ4OJN6ESGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725483313; c=relaxed/simple; bh=LQTu8sC/kulEKMETw8TubpnUEdoK4OUoYt2IduwMQPQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fy0RwCqHIwJB9d6l2RNxUdxnvTD17Ap9nA+d3y9UsrJQLR9yyS7BtG/+0WUZOGFWJoLceP6rVi3xzfhOOZ71gigKkPPfxRD8WN911mMH81JJ6J8QfRLMJX/6glCPhqC3L9hphKVPKq6udY/sjXF8drOCXQGnFzw5orhfpIa4Gs8= 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=O2UdEHPK; 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="O2UdEHPK" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2059204f448so801735ad.0; Wed, 04 Sep 2024 13:55:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725483311; x=1726088111; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=sqrX7xKRsiUs8X7rmIdaWp7SWBsLihp3vVeII2DVLXw=; b=O2UdEHPKqCtVktDRPJSxt52yZ3idu0nFQh3dxueapYBL7pNo0Eki6clUfkBaVwaqFN k4dbDrVh9GsSC8GngoOn+t6OJErBFGmUdd8ngNQVEKcyVROjZD5VJ9cA4rbR8AXse7GB dNX44joj7Q4qYo9E5rhTn5t5TU7WRn6eCCwbPVTjpR1BElI7N69X8e/+qlu+Tgy9VZAO E8Bfrg4GNggAMEaZioBrSUiVR8NlWfAAfI9RzF2MQ3ya+a8g0ofQeShz452F0a9iTkwM TWO0WAITbsrpo+QnVGY1OVkFammlfGGeRFvP4qhP7/71lpQwREPGmzbU3NHp398JsbOW Vutg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725483311; x=1726088111; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=sqrX7xKRsiUs8X7rmIdaWp7SWBsLihp3vVeII2DVLXw=; b=qQS6d0TGjBDxqTmkRl9kOzCfWT95z4sZLkUpmsQXVAPFJXRDqDTquLirJZ3jur9P57 MyCCsGSJvUM/noBj/kuy6XfnNpmSvIU5HicR0H+VSmQFOFz3c1DIra3poNvzKDuD4cvq K1yvlUnUbMJ4FbtYxLq9No7AjYWhlbETrsRc4x1o8IRYZnjxRF+BhwNBOlFqbHue9aMN Z8SzyItPaPMNH9owXo3AfSByJHeJIqqP2cdhJiLVboHtYHOtrqaMUkf7s6Z/sFeiFDAZ 4UcEfIoid/e/Tt5weBuoJtFSDvR6uZj6VlCl/CiLh/VzIWMnByYKP6k8mACSdCywvmEU NQYA== X-Forwarded-Encrypted: i=1; AJvYcCXE+4G1/rkhAGCazTL5jU96yrRvu25wJjVCnsFx2e0bhlMA5OzcHIvfoYydhVF5W/9VTuGD1lyXxvqWsio=@vger.kernel.org X-Gm-Message-State: AOJu0YyxDoDkzm1JTNjLjCvzaE2L2LMqpvmpHGsU0rsxRp6W3+voEmHz odLHMJ3XuVRfTVljI0v197U/chRdXLdafJ0zySvvDVZB1fpBDTcX X-Google-Smtp-Source: AGHT+IFN1IwonS31KRPHw1fKgP9hulUMBQG6IxgViZqWb3/daMJFpYfffDJkEKkxZZyCCacv3nOxtw== X-Received: by 2002:a17:902:c949:b0:205:5dfe:7be with SMTP id d9443c01a7336-2055dfe179fmr126258775ad.26.1725483310546; Wed, 04 Sep 2024 13:55:10 -0700 (PDT) Received: from google.com ([2620:15c:9d:2:13bd:b4e:4c0f:4c37]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae9525d6sm17598355ad.111.2024.09.04.13.55.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 13:55:10 -0700 (PDT) Date: Wed, 4 Sep 2024 13:55:07 -0700 From: Dmitry Torokhov To: Javier Carrasco Cc: linux-input@vger.kernel.org, Michael Hennerich , Ville Syrjala , Support Opensource , Eddie James , Andrey Moiseev , Hans de Goede , Jeff LaBundy , linux-kernel@vger.kernel.org Subject: [PATCH v2 20/22] Input: regulator-haptic - use guard notation when acquiring mutex Message-ID: References: <20240904044244.1042174-1-dmitry.torokhov@gmail.com> <20240904044922.1049488-1-dmitry.torokhov@gmail.com> <3ff97fb3-27e0-496e-a8b0-0c2d69deeff2@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <3ff97fb3-27e0-496e-a8b0-0c2d69deeff2@gmail.com> 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 --- v2: drop no linger used "error" variable in regulator_haptic_suspend() drivers/input/misc/regulator-haptic.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/drivers/input/misc/regulator-haptic.c b/drivers/input/misc/regulator-haptic.c index 02f73b7c0462..3666ba6d1f30 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, @@ -205,19 +203,15 @@ static int regulator_haptic_suspend(struct device *dev) { struct platform_device *pdev = to_platform_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); + scoped_guard(mutex_intr, &haptic->mutex) { + regulator_haptic_set_voltage(haptic, 0); + haptic->suspended = true; - haptic->suspended = true; - - mutex_unlock(&haptic->mutex); + return 0; + } - return 0; + return -EINTR; } static int regulator_haptic_resume(struct device *dev) @@ -226,7 +220,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 +228,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: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: 825423 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 --- 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; }