From nobody Fri Oct 3 00:00:53 2025 Received: from mail-244108.protonmail.ch (mail-244108.protonmail.ch [109.224.244.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB18C306B3D for ; Tue, 9 Sep 2025 07:11:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.224.244.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757401897; cv=none; b=D1vIalA3xQhGpljgFWNQgA0fr3g3jbnLK9dTega8ph0s5ZLIVSA09+TETrglNi0J0TsPPwmbxQl0THGGYRmk5y8V0Vasc+96UfmRMHfi1LeMAq/u8sIauWdPNP813z5v6FZ4tkbQwbab+z+fF/2tg+Pq8VsPntgXXRNU1Nbhu68= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757401897; c=relaxed/simple; bh=6oRmmzziaTgPC0bksMOkEHu7AoqHaS3P3gyUbOWU46A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MwTlq+Dbjmkrnb7qDVulZXZzvz3XDGZkTUk631IgMi7a8bXRmyTtq64iMHN5+mnAOnDWnLOtMqeyNyWfr5E8yn76UxwQwmZiQhq50svYn2vZSYZZiiGp8mJKx8GMO7giGVUYb+CeajB8XA4yb2MSeuNOsw9HZNJlt40IECeP1dg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com; spf=pass smtp.mailfrom=geanix.com; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b=CJkMNrQP; arc=none smtp.client-ip=109.224.244.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=geanix.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b="CJkMNrQP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=geanix.com; s=protonmail2; t=1757401887; x=1757661087; bh=vFveFwTnn7yrm9XsyVQ58MSODxhrcS6ozaHd9fgq5VU=; h=From:Date:Subject:Message-Id:References:In-Reply-To:To:Cc:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=CJkMNrQPRmqsxEv9QMxZ0du5R3y5BmhwKt1wcQsygRgrs6WlKeBSjdvwzglonSQG4 +JnNs84IC8JcLmQq/w4/Z0oU2J7UM5GIFAuFsfm8jjYvxjNn//kbnul45Acl0AIU9E 43Qkp+6KxtaJWxVbUclTPLFz01wd+vh8bfVx7ndF9/Mv73xgM6IP7KKfiGmcF5mWgU Q79MB88qlwAqY9dMc+R+/YzBzdcWb3QdW62QyNiOexiqopj+bgGlAicEAq8rdb0RsA 7s5GTdVdsfYaUovlhk2yVKJqhz8eS5p3iRg9AeWYyPbZNzQV51EHHQMXai3Kzofukx 3HCVgTBzz1fkg== X-Pm-Submission-Id: 4cLZk556T1z1DDs2 From: Sean Nyekjaer Date: Tue, 09 Sep 2025 09:11:07 +0200 Subject: [PATCH v4 1/5] iio: imu: inv_icm42600: Simplify pm_runtime setup Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250909-icm42pmreg-v4-1-2bf763662c5c@geanix.com> References: <20250909-icm42pmreg-v4-0-2bf763662c5c@geanix.com> In-Reply-To: <20250909-icm42pmreg-v4-0-2bf763662c5c@geanix.com> To: Jean-Baptiste Maneyrol , rafael@kernel.org, Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Jean-Baptiste Maneyrol , Jonathan Cameron , Sean Nyekjaer X-Mailer: b4 0.14.2 Rework the power management in inv_icm42600_core_probe() to use devm_pm_runtime_set_active_enabled(), which simplifies the runtime PM setup by handling activation and enabling in one step. Remove the separate inv_icm42600_disable_pm callback, as it's no longer needed with the devm-managed approach. Using devm_pm_runtime_enable() also fixes the missing disable of autosuspend. Update inv_icm42600_disable_vddio_reg() to only disable the regulator if the device is not suspended i.e. powered-down, preventing unbalanced disables. Also remove redundant error msg on regulator_disable(), the regulator framework already emits an error message when regulator_disable() fails. This simplifies the PM setup and avoids manipulating the usage counter unnecessarily. Fixes: 31c24c1e93c3 ("iio: imu: inv_icm42600: add core of new inv_icm42600 = driver") Signed-off-by: Sean Nyekjaer --- drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 24 +++++++-------------= ---- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio= /imu/inv_icm42600/inv_icm42600_core.c index a4d42e7e21807f7954def431e9cf03dffaa5bd5e..76d8e4f14d87a552a35d7a9e0cb= 3305781d85ca9 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c @@ -711,20 +711,12 @@ static void inv_icm42600_disable_vdd_reg(void *_data) static void inv_icm42600_disable_vddio_reg(void *_data) { struct inv_icm42600_state *st =3D _data; - const struct device *dev =3D regmap_get_device(st->map); - int ret; - - ret =3D regulator_disable(st->vddio_supply); - if (ret) - dev_err(dev, "failed to disable vddio error %d\n", ret); -} + struct device *dev =3D regmap_get_device(st->map); =20 -static void inv_icm42600_disable_pm(void *_data) -{ - struct device *dev =3D _data; + if (pm_runtime_status_suspended(dev)) + return; =20 - pm_runtime_put_sync(dev); - pm_runtime_disable(dev); + regulator_disable(st->vddio_supply); } =20 int inv_icm42600_core_probe(struct regmap *regmap, int chip, @@ -824,16 +816,14 @@ int inv_icm42600_core_probe(struct regmap *regmap, in= t chip, return ret; =20 /* setup runtime power management */ - ret =3D pm_runtime_set_active(dev); + ret =3D devm_pm_runtime_set_active_enabled(dev); if (ret) return ret; - pm_runtime_get_noresume(dev); - pm_runtime_enable(dev); + pm_runtime_set_autosuspend_delay(dev, INV_ICM42600_SUSPEND_DELAY_MS); pm_runtime_use_autosuspend(dev); - pm_runtime_put(dev); =20 - return devm_add_action_or_reset(dev, inv_icm42600_disable_pm, dev); + return ret; } EXPORT_SYMBOL_NS_GPL(inv_icm42600_core_probe, "IIO_ICM42600"); =20 --=20 2.50.1 From nobody Fri Oct 3 00:00:53 2025 Received: from mail-244107.protonmail.ch (mail-244107.protonmail.ch [109.224.244.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBB282EB856 for ; Tue, 9 Sep 2025 07:11:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.224.244.107 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757401898; cv=none; b=uFYghZDbcx43ef1Dj6re3WLm4L6cD4ED4OBPjQVbWRNOca45j/xe7w7arZj611e4NdeZhcqjvknFslC+e6AOEmMuJQtGjGT9BKdEUmEG8x/n1+Gk/t/4GaCGd/9bk2clwgDTFOLmLPnRfDv8YtAfsU9re8EMumBNvHcQYKZz1/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757401898; c=relaxed/simple; bh=k5EcpY+/DFBwpLrWYB9YJb0ZadsqeSt/t/hsL/nFUQ4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VXCcITCHnpXMZ0OOpTsWlgZ0nlfvJYqv7a5nmQskzK6U6MaYJXDBigBp17tqU6CEHBswL2l6zek6c0j9si68S5HB421fD1tudn2W5lYDwbaaAHCjQTQaEwBVu0krvqkABh4eePzyR07Pby0NoC1AiyCeRlmhNct17BLXYFHcxtY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com; spf=pass smtp.mailfrom=geanix.com; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b=aJI/skLO; arc=none smtp.client-ip=109.224.244.107 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=geanix.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b="aJI/skLO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=geanix.com; s=protonmail2; t=1757401888; x=1757661088; bh=xYd9qNsZ4IIvksv/lLIifpsYugqw4UBhFpRtcHQXVY0=; h=From:Date:Subject:Message-Id:References:In-Reply-To:To:Cc:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=aJI/skLO3BcYBxWUSeNwpQXxvYVk3KauAeZ+GynyGb1A+fbcs3dphXM/WyQrG3Y27 jPftyb6CZFRsnZJsaAR2uSOaUyOc1gDxD2x0we9xZLuI12l1FnHMURNx6uXi69/S3q PSew3fn/pVuEqUgY8k35/KOqMzPwIeS1CkY3LEYyPjdkx4EVl2dWKlDp805tS+ypdy yxTgjZxw/+mBr356yj1CCz92dy54EQVwIKC6+1Y241Lbot9NmTiczo3boLDxkEPv/v OOOf4ZwaCRmne8V72qUJMYYr+2HTD2ZE8qgzkdBCH0bhthnE7TrBItSMa0e0eTPWTe /0BIx5NgL5TCg== X-Pm-Submission-Id: 4cLZk71ZMNz1DF4G From: Sean Nyekjaer Date: Tue, 09 Sep 2025 09:11:08 +0200 Subject: [PATCH v4 2/5] iio: imu: inv_icm42600: Drop redundant pm_runtime reinitialization in resume Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250909-icm42pmreg-v4-2-2bf763662c5c@geanix.com> References: <20250909-icm42pmreg-v4-0-2bf763662c5c@geanix.com> In-Reply-To: <20250909-icm42pmreg-v4-0-2bf763662c5c@geanix.com> To: Jean-Baptiste Maneyrol , rafael@kernel.org, Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Jean-Baptiste Maneyrol , Jonathan Cameron , Sean Nyekjaer X-Mailer: b4 0.14.2 Remove unnecessary calls to pm_runtime_disable(), pm_runtime_set_active(), and pm_runtime_enable() from the resume path. These operations are not required here and can interfere with proper pm_runtime state handling, especially when resuming from a pm_runtime suspended state. Fixes: 31c24c1e93c3 ("iio: imu: inv_icm42600: add core of new inv_icm42600 = driver") Signed-off-by: Sean Nyekjaer --- drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio= /imu/inv_icm42600/inv_icm42600_core.c index 76d8e4f14d87a552a35d7a9e0cb3305781d85ca9..41b275ecc7e25ea0b8cdf59be51= 4cdf8a4957ab4 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c @@ -917,10 +917,6 @@ static int inv_icm42600_resume(struct device *dev) goto out_unlock; } =20 - pm_runtime_disable(dev); - pm_runtime_set_active(dev); - pm_runtime_enable(dev); - /* restore sensors state */ ret =3D inv_icm42600_set_pwr_mgmt0(st, st->suspended.gyro, st->suspended.accel, --=20 2.50.1 From nobody Fri Oct 3 00:00:53 2025 Received: from mail-43172.protonmail.ch (mail-43172.protonmail.ch [185.70.43.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 431B13081A1 for ; Tue, 9 Sep 2025 07:11:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757401899; cv=none; b=nn2hQGiC6YSRUN4T41zcOywvPMRpP0+xEFWqGHKl+skaVzSoELfMCI99dDic3HzEaw5h2D/1YPchizacuhYX8FYBVaR+qAnQh1IWz9fKkrVolmisPKTxJG+mPZHWd3jr8tLXCCc0ZLxFMNYwdzb/Sdk4pgaFKHEs9RDMZa/tLoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757401899; c=relaxed/simple; bh=OL3zTc++fWocVV76N9Qrx3mPmqq+2NTo3NP+aQUzDpI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CQ2N/ZuakWAYr7iUUv6Wlc7q8vROLyCDLmDw+1Kdg3xeIrTUuaV5WdMl9VeLhNF0X0ELCKRMUbRfLURUpdmyPkGyjyFuk+06D/qFRP+MX6l4qW+soFplWk+VbHUpCWBgdo4GmxTpSM1bQaCkPc0C75PTHocXoMsps3pr5mgCLG8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com; spf=pass smtp.mailfrom=geanix.com; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b=iFDQVoRg; arc=none smtp.client-ip=185.70.43.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=geanix.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b="iFDQVoRg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=geanix.com; s=protonmail2; t=1757401891; x=1757661091; bh=tceitGNVxLxyezCWiChxK4zQKtJl6rtYJ4s3FymhP8g=; h=From:Date:Subject:Message-Id:References:In-Reply-To:To:Cc:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=iFDQVoRgFHYP2++0Dl2aN7UgDIawbjp7S9qyyqgZF5NsFyPgI6vaYgFKr4QeVaMI1 H/HcOBRsrEV1fYfOP8AQOI8xU8z2QBWZNkWhR/IDUbfM0mqdLO7ZIXLD2+iuCwp0UL penLtq0sZpeqHv5C//KrVtQ7Yubt9X1JoFiJ+0gbHew+gXg4rIn+eH2gNNNVQMNjF2 qV3Yeqqo5TkwfsKQaLoawidO1793XoxZz4DsuuUNlEraza4MDw368n4hfRznOpTD4d DaKk/rA07sXT26YbDXaa4mJg92/87aMXJvDGeoHas9DEKxBJxJ+zj9fLwLw70TwXRX U3WdJ0NGCG/eA== X-Pm-Submission-Id: 4cLZk85pLMz1DDs1 From: Sean Nyekjaer Date: Tue, 09 Sep 2025 09:11:09 +0200 Subject: [PATCH v4 3/5] iio: imu: inv_icm42600: Avoid configuring if already pm_runtime suspended Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250909-icm42pmreg-v4-3-2bf763662c5c@geanix.com> References: <20250909-icm42pmreg-v4-0-2bf763662c5c@geanix.com> In-Reply-To: <20250909-icm42pmreg-v4-0-2bf763662c5c@geanix.com> To: Jean-Baptiste Maneyrol , rafael@kernel.org, Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Jean-Baptiste Maneyrol , Jonathan Cameron , Sean Nyekjaer X-Mailer: b4 0.14.2 Do as in suspend, skip resume configuration steps if the device is already pm_runtime suspended. This avoids reconfiguring a device that is already in the correct low-power state and ensures that pm_runtime handles the power state transitions properly. Fixes: 31c24c1e93c3 ("iio: imu: inv_icm42600: add core of new inv_icm42600 = driver") Signed-off-by: Sean Nyekjaer --- drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio= /imu/inv_icm42600/inv_icm42600_core.c index 41b275ecc7e25ea0b8cdf59be514cdf8a4957ab4..ee780f530dc8612cd25dc2216b1= 53ef4e8c32b7b 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c @@ -837,17 +837,15 @@ static int inv_icm42600_suspend(struct device *dev) struct device *accel_dev; bool wakeup; int accel_conf; - int ret; + int ret =3D 0; =20 mutex_lock(&st->lock); =20 st->suspended.gyro =3D st->conf.gyro.mode; st->suspended.accel =3D st->conf.accel.mode; st->suspended.temp =3D st->conf.temp_en; - if (pm_runtime_suspended(dev)) { - ret =3D 0; + if (pm_runtime_suspended(dev)) goto out_unlock; - } =20 /* disable FIFO data streaming */ if (st->fifo.on) { @@ -900,10 +898,13 @@ static int inv_icm42600_resume(struct device *dev) struct inv_icm42600_sensor_state *accel_st =3D iio_priv(st->indio_accel); struct device *accel_dev; bool wakeup; - int ret; + int ret =3D 0; =20 mutex_lock(&st->lock); =20 + if (pm_runtime_suspended(dev)) + goto out_unlock; + /* check wakeup capability */ accel_dev =3D &st->indio_accel->dev; wakeup =3D st->apex.on && device_may_wakeup(accel_dev); --=20 2.50.1 From nobody Fri Oct 3 00:00:53 2025 Received: from mail-106112.protonmail.ch (mail-106112.protonmail.ch [79.135.106.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 616123081A5; Tue, 9 Sep 2025 07:11:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.135.106.112 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757401902; cv=none; b=msJcIxrfgDMEPBc3qTD/5ejuAVE6Cxyyq3D4JQ7ghIwtJYXbbCzG+1iCPGMAZxKdi2Hl3NR2MHUAVnNlyIVk0W80QoCap+5kh7+S726WXji8n19CsXipCbgWWtr+7OQh8OuBQsbyT+Yeoqjt1Gw2QVd3Q5E0yTwI6Mk51m5nIa8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757401902; c=relaxed/simple; bh=gAaZ1TanExUpKz8pHuUzLT9Wce3FYd1z99y3OHAO5jE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eUAtheQoDZezVGaMc32oRS83P1aUMtn8u/AQaFKhTpGIMF8xRzRJ46icr47Q8XdC5caBs7E2m8Nz5H3f04HY+gRm0Eljcd0s6GcCDuYRGTIrsL82+1pvZYMZTiFewBO1izzUx4AGM5VKZYmLxX6njbE+I1QRCa7hD5OG1FxOK2s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com; spf=pass smtp.mailfrom=geanix.com; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b=nsR9hqY2; arc=none smtp.client-ip=79.135.106.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=geanix.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b="nsR9hqY2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=geanix.com; s=protonmail2; t=1757401892; x=1757661092; bh=O7HQJC6D4zuz6nZXJL5xFKWOz3c9FOfKqraNYIM6U/4=; h=From:Date:Subject:Message-Id:References:In-Reply-To:To:Cc:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=nsR9hqY2cLbqQQvCPJfUeZ7AjiFsDIXQyRr2wiw9yPP0slzq3gc7gTdPyIYm3+Ptn TupKxhQjvo8wUWzAhcOSTCZ0hriUKmlL+3UlCbW/owItPR5GvTD69szc8glWe5jAvO bRKAs4jaIb3pxgkXDKd8NfvfKtj8uSMV560BVam9vO8Mj3c+BknNWBdzU+/M/9AtOs /6LOAgZGx6jGE7fVoZm0c3j1wgUPBnOLv/F6Lc4fYYUl0z5HB6YSF0XD+a06g/PWuR ozmm2V/dYqaY/h4d3x+U4PmLg84FgvG+R+S6k9/ve8+OPEV1RF9zF9tkdQTpo9fsRY S9jiY5GNNm1ow== X-Pm-Submission-Id: 4cLZkB6BL6z1DDrw From: Sean Nyekjaer Date: Tue, 09 Sep 2025 09:11:10 +0200 Subject: [PATCH v4 4/5] iio: imu: inv_icm42600: Use devm_regulator_get_enable() for vdd regulator Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250909-icm42pmreg-v4-4-2bf763662c5c@geanix.com> References: <20250909-icm42pmreg-v4-0-2bf763662c5c@geanix.com> In-Reply-To: <20250909-icm42pmreg-v4-0-2bf763662c5c@geanix.com> To: Jean-Baptiste Maneyrol , rafael@kernel.org, Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Jean-Baptiste Maneyrol , Jonathan Cameron , Sean Nyekjaer X-Mailer: b4 0.14.2 The vdd regulator is not used for runtime power management, so it does not need explicit enable/disable handling. Use devm_regulator_get_enable() to let the regulator be managed automatically by devm. This simplifies the code by removing the manual enable and cleanup logic. Reviewed-by: David Lechner Signed-off-by: Sean Nyekjaer --- drivers/iio/imu/inv_icm42600/inv_icm42600.h | 1 - drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 29 +++++---------------= ---- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600.h b/drivers/iio/imu/= inv_icm42600/inv_icm42600.h index 1430ab4f1dea5d5ba6277d74275fc44a6cd30eb8..c8b48a5c5ed0677bb35201d3293= 4936faaf7a1a6 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600.h +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600.h @@ -167,7 +167,6 @@ struct inv_icm42600_state { enum inv_icm42600_chip chip; const char *name; struct regmap *map; - struct regulator *vdd_supply; struct regulator *vddio_supply; int irq; struct iio_mount_matrix orientation; diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio= /imu/inv_icm42600/inv_icm42600_core.c index ee780f530dc8612cd25dc2216b153ef4e8c32b7b..4bf436c46f1cfd7e7e1bb911d94= a0a566d63e791 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c @@ -697,17 +697,6 @@ static int inv_icm42600_enable_regulator_vddio(struct = inv_icm42600_state *st) return 0; } =20 -static void inv_icm42600_disable_vdd_reg(void *_data) -{ - struct inv_icm42600_state *st =3D _data; - const struct device *dev =3D regmap_get_device(st->map); - int ret; - - ret =3D regulator_disable(st->vdd_supply); - if (ret) - dev_err(dev, "failed to disable vdd error %d\n", ret); -} - static void inv_icm42600_disable_vddio_reg(void *_data) { struct inv_icm42600_state *st =3D _data; @@ -765,23 +754,17 @@ int inv_icm42600_core_probe(struct regmap *regmap, in= t chip, return ret; } =20 - st->vdd_supply =3D devm_regulator_get(dev, "vdd"); - if (IS_ERR(st->vdd_supply)) - return PTR_ERR(st->vdd_supply); + ret =3D devm_regulator_get_enable(dev, "vdd"); + if (ret) + return dev_err_probe(dev, ret, + "Failed to get vdd regulator\n"); + + msleep(INV_ICM42600_POWER_UP_TIME_MS); =20 st->vddio_supply =3D devm_regulator_get(dev, "vddio"); if (IS_ERR(st->vddio_supply)) return PTR_ERR(st->vddio_supply); =20 - ret =3D regulator_enable(st->vdd_supply); - if (ret) - return ret; - msleep(INV_ICM42600_POWER_UP_TIME_MS); - - ret =3D devm_add_action_or_reset(dev, inv_icm42600_disable_vdd_reg, st); - if (ret) - return ret; - ret =3D inv_icm42600_enable_regulator_vddio(st); if (ret) return ret; --=20 2.50.1 From nobody Fri Oct 3 00:00:53 2025 Received: from mail-244107.protonmail.ch (mail-244107.protonmail.ch [109.224.244.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1D42306B3A for ; Tue, 9 Sep 2025 07:11:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.224.244.107 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757401897; cv=none; b=i2CpkDbnNAhQWUM31kzKO8T1Gjw3cSq22pSesFhNV3MoCi4rzHJTboarJkFt8bUFs3x7yhEt8hVOXXC/dNGysr7hH2q3Gn/clAfqMe/MSVaEf+q8EGo9RUY0hex7BSFHfTBEvVlDIAz31aqzK/XsS/oEjZRIj1nSyyFWxCPA0vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757401897; c=relaxed/simple; bh=kwPFMrvsrvxGJoMPBNRqFrLMPWy0KJlrs95GAQwLEoI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iDPUt9m+CGEn2nA5gvgwfon/XEB+ElwdDhhbaQ/u4wCqLCao+G5ICii2woKGSwQbqxuR62xRa79CSZjN+erPBz2nrw3k6aY3i9bJYJmaLp47TVySTLT/keBGoVl9J6vAbEOlMkfDLL5zFX72/yezhzrf/IIqcTbY0vkAyAZyfr8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com; spf=pass smtp.mailfrom=geanix.com; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b=IxtAm7jh; arc=none smtp.client-ip=109.224.244.107 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=geanix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=geanix.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=geanix.com header.i=@geanix.com header.b="IxtAm7jh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=geanix.com; s=protonmail2; t=1757401893; x=1757661093; bh=ZefN41xCKapumVdX8IL4cdw/ebKKLgmrR7MeEiZJn6E=; h=From:Date:Subject:Message-Id:References:In-Reply-To:To:Cc:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=IxtAm7jhtARTP3kSkxV1aWQ93Ba964KgGuxAvbwxpGueWS/ezTHe8CEXJUF7MFzqk qCoZseHxT9j/7pXvu1ge/wD/BtbzZXz3MJP21uWxrHeZ/YyJUhViQsDRtykwa8aqGE b+/Po5mutxdw5h4GTFGzHCbCMCEOx5461DIh0SJ8+h9G+qhTORZIyoLHeyUj95UugZ ICNB7+kTSLgqmZrbrPcb+Co7IYDogVaACEQ/5y+yGp4+3NQ/SCqH8C7dTGYzuq32Ev IADtJvFJO9n9TtGoUvHrFlsZdAcUOsmLIvRWU7ZX+84gn2tgFp91YpgL+vdwzrm8Vy 0Uib4mCvBi+MQ== X-Pm-Submission-Id: 4cLZkD2fXwz1DDs2 From: Sean Nyekjaer Date: Tue, 09 Sep 2025 09:11:11 +0200 Subject: [PATCH v4 5/5] iio: imu: inv_icm42600: use guard() to release mutexes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250909-icm42pmreg-v4-5-2bf763662c5c@geanix.com> References: <20250909-icm42pmreg-v4-0-2bf763662c5c@geanix.com> In-Reply-To: <20250909-icm42pmreg-v4-0-2bf763662c5c@geanix.com> To: Jean-Baptiste Maneyrol , rafael@kernel.org, Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Jean-Baptiste Maneyrol , Jonathan Cameron , Sean Nyekjaer X-Mailer: b4 0.14.2 Replace explicit mutex_lock() and mutex_unlock() with the guard() macro for cleaner and safer mutex handling. Signed-off-by: Sean Nyekjaer Reviewed-by: David Lechner --- drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c | 24 +++------ drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c | 41 +++++++-------- drivers/iio/imu/inv_icm42600/inv_icm42600_core.c | 59 ++++++++----------= ---- drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c | 24 +++------ 4 files changed, 56 insertions(+), 92 deletions(-) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c b/drivers/ii= o/imu/inv_icm42600/inv_icm42600_accel.c index 48014b61ced335eb2c8549cfc2e79ccde1934308..54760d8f92a279334338fd09e3a= b74b2d939a46d 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c @@ -561,11 +561,10 @@ static int inv_icm42600_accel_write_scale(struct iio_= dev *indio_dev, conf.fs =3D idx / 2; =20 pm_runtime_get_sync(dev); - mutex_lock(&st->lock); =20 - ret =3D inv_icm42600_set_accel_conf(st, &conf, NULL); + scoped_guard(mutex, &st->lock) + ret =3D inv_icm42600_set_accel_conf(st, &conf, NULL); =20 - mutex_unlock(&st->lock); pm_runtime_put_autosuspend(dev); =20 return ret; @@ -986,16 +985,11 @@ static int inv_icm42600_accel_hwfifo_set_watermark(st= ruct iio_dev *indio_dev, unsigned int val) { struct inv_icm42600_state *st =3D iio_device_get_drvdata(indio_dev); - int ret; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 st->fifo.watermark.accel =3D val; - ret =3D inv_icm42600_buffer_update_watermark(st); - - mutex_unlock(&st->lock); - - return ret; + return inv_icm42600_buffer_update_watermark(st); } =20 static int inv_icm42600_accel_hwfifo_flush(struct iio_dev *indio_dev, @@ -1007,15 +1001,13 @@ static int inv_icm42600_accel_hwfifo_flush(struct i= io_dev *indio_dev, if (count =3D=3D 0) return 0; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 ret =3D inv_icm42600_buffer_hwfifo_flush(st, count); - if (!ret) - ret =3D st->fifo.nb.accel; - - mutex_unlock(&st->lock); + if (ret) + return ret; =20 - return ret; + return st->fifo.nb.accel; } =20 static int inv_icm42600_accel_read_event_config(struct iio_dev *indio_dev, diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c b/drivers/i= io/imu/inv_icm42600/inv_icm42600_buffer.c index 36d69a0face655bf2dc9229c52d07448e9b2ca02..15391961bf969237acf67e328e9= 2c2911c77924f 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_buffer.c @@ -283,9 +283,8 @@ static int inv_icm42600_buffer_preenable(struct iio_dev= *indio_dev) =20 pm_runtime_get_sync(dev); =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); inv_sensors_timestamp_reset(ts); - mutex_unlock(&st->lock); =20 return 0; } @@ -299,43 +298,41 @@ static int inv_icm42600_buffer_postenable(struct iio_= dev *indio_dev) struct inv_icm42600_state *st =3D iio_device_get_drvdata(indio_dev); int ret; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 /* exit if FIFO is already on */ if (st->fifo.on) { - ret =3D 0; - goto out_on; + st->fifo.on++; + return 0; } =20 /* set FIFO threshold interrupt */ ret =3D regmap_set_bits(st->map, INV_ICM42600_REG_INT_SOURCE0, INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN); if (ret) - goto out_unlock; + return ret; =20 /* flush FIFO data */ ret =3D regmap_write(st->map, INV_ICM42600_REG_SIGNAL_PATH_RESET, INV_ICM42600_SIGNAL_PATH_RESET_FIFO_FLUSH); if (ret) - goto out_unlock; + return ret; =20 /* set FIFO in streaming mode */ ret =3D regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG, INV_ICM42600_FIFO_CONFIG_STREAM); if (ret) - goto out_unlock; + return ret; =20 /* workaround: first read of FIFO count after reset is always 0 */ ret =3D regmap_bulk_read(st->map, INV_ICM42600_REG_FIFO_COUNT, st->buffer= , 2); if (ret) - goto out_unlock; + return ret; =20 -out_on: /* increase FIFO on counter */ st->fifo.on++; -out_unlock: - mutex_unlock(&st->lock); - return ret; + + return 0; } =20 static int inv_icm42600_buffer_predisable(struct iio_dev *indio_dev) @@ -343,38 +340,36 @@ static int inv_icm42600_buffer_predisable(struct iio_= dev *indio_dev) struct inv_icm42600_state *st =3D iio_device_get_drvdata(indio_dev); int ret; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 /* exit if there are several sensors using the FIFO */ if (st->fifo.on > 1) { - ret =3D 0; - goto out_off; + st->fifo.on--; + return 0; } =20 /* set FIFO in bypass mode */ ret =3D regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG, INV_ICM42600_FIFO_CONFIG_BYPASS); if (ret) - goto out_unlock; + return ret; =20 /* flush FIFO data */ ret =3D regmap_write(st->map, INV_ICM42600_REG_SIGNAL_PATH_RESET, INV_ICM42600_SIGNAL_PATH_RESET_FIFO_FLUSH); if (ret) - goto out_unlock; + return ret; =20 /* disable FIFO threshold interrupt */ ret =3D regmap_clear_bits(st->map, INV_ICM42600_REG_INT_SOURCE0, INV_ICM42600_INT_SOURCE0_FIFO_THS_INT1_EN); if (ret) - goto out_unlock; + return ret; =20 -out_off: /* decrease FIFO on counter */ st->fifo.on--; -out_unlock: - mutex_unlock(&st->lock); - return ret; + + return 0; } =20 static int inv_icm42600_buffer_postdisable(struct iio_dev *indio_dev) diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c b/drivers/iio= /imu/inv_icm42600/inv_icm42600_core.c index 4bf436c46f1cfd7e7e1bb911d94a0a566d63e791..76eb22488e5f31623a0f93d856f= b4d10182f1ac2 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_core.c @@ -439,18 +439,13 @@ int inv_icm42600_debugfs_reg(struct iio_dev *indio_de= v, unsigned int reg, unsigned int writeval, unsigned int *readval) { struct inv_icm42600_state *st =3D iio_device_get_drvdata(indio_dev); - int ret; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 if (readval) - ret =3D regmap_read(st->map, reg, readval); - else - ret =3D regmap_write(st->map, reg, writeval); - - mutex_unlock(&st->lock); + return regmap_read(st->map, reg, readval); =20 - return ret; + return regmap_write(st->map, reg, writeval); } =20 static int inv_icm42600_set_conf(struct inv_icm42600_state *st, @@ -820,22 +815,22 @@ static int inv_icm42600_suspend(struct device *dev) struct device *accel_dev; bool wakeup; int accel_conf; - int ret =3D 0; + int ret; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 st->suspended.gyro =3D st->conf.gyro.mode; st->suspended.accel =3D st->conf.accel.mode; st->suspended.temp =3D st->conf.temp_en; if (pm_runtime_suspended(dev)) - goto out_unlock; + return 0; =20 /* disable FIFO data streaming */ if (st->fifo.on) { ret =3D regmap_write(st->map, INV_ICM42600_REG_FIFO_CONFIG, INV_ICM42600_FIFO_CONFIG_BYPASS); if (ret) - goto out_unlock; + return ret; } =20 /* keep chip on and wake-up capable if APEX and wakeup on */ @@ -851,7 +846,7 @@ static int inv_icm42600_suspend(struct device *dev) if (st->apex.wom.enable) { ret =3D inv_icm42600_disable_wom(st); if (ret) - goto out_unlock; + return ret; } accel_conf =3D INV_ICM42600_SENSOR_MODE_OFF; } @@ -859,15 +854,13 @@ static int inv_icm42600_suspend(struct device *dev) ret =3D inv_icm42600_set_pwr_mgmt0(st, INV_ICM42600_SENSOR_MODE_OFF, accel_conf, false, NULL); if (ret) - goto out_unlock; + return ret; =20 /* disable vddio regulator if chip is sleeping */ if (!wakeup) regulator_disable(st->vddio_supply); =20 -out_unlock: - mutex_unlock(&st->lock); - return ret; + return 0; } =20 /* @@ -881,12 +874,12 @@ static int inv_icm42600_resume(struct device *dev) struct inv_icm42600_sensor_state *accel_st =3D iio_priv(st->indio_accel); struct device *accel_dev; bool wakeup; - int ret =3D 0; + int ret; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 if (pm_runtime_suspended(dev)) - goto out_unlock; + return 0; =20 /* check wakeup capability */ accel_dev =3D &st->indio_accel->dev; @@ -898,7 +891,7 @@ static int inv_icm42600_resume(struct device *dev) } else { ret =3D inv_icm42600_enable_regulator_vddio(st); if (ret) - goto out_unlock; + return ret; } =20 /* restore sensors state */ @@ -906,13 +899,13 @@ static int inv_icm42600_resume(struct device *dev) st->suspended.accel, st->suspended.temp, NULL); if (ret) - goto out_unlock; + return ret; =20 /* restore APEX features if disabled */ if (!wakeup && st->apex.wom.enable) { ret =3D inv_icm42600_enable_wom(st); if (ret) - goto out_unlock; + return ret; } =20 /* restore FIFO data streaming */ @@ -923,9 +916,7 @@ static int inv_icm42600_resume(struct device *dev) INV_ICM42600_FIFO_CONFIG_STREAM); } =20 -out_unlock: - mutex_unlock(&st->lock); - return ret; + return 0; } =20 /* Runtime suspend will turn off sensors that are enabled by iio devices. = */ @@ -934,34 +925,28 @@ static int inv_icm42600_runtime_suspend(struct device= *dev) struct inv_icm42600_state *st =3D dev_get_drvdata(dev); int ret; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 /* disable all sensors */ ret =3D inv_icm42600_set_pwr_mgmt0(st, INV_ICM42600_SENSOR_MODE_OFF, INV_ICM42600_SENSOR_MODE_OFF, false, NULL); if (ret) - goto error_unlock; + return ret; =20 regulator_disable(st->vddio_supply); =20 -error_unlock: - mutex_unlock(&st->lock); - return ret; + return 0; } =20 /* Sensors are enabled by iio devices, no need to turn them back on here. = */ static int inv_icm42600_runtime_resume(struct device *dev) { struct inv_icm42600_state *st =3D dev_get_drvdata(dev); - int ret; =20 - mutex_lock(&st->lock); - - ret =3D inv_icm42600_enable_regulator_vddio(st); + guard(mutex)(&st->lock); =20 - mutex_unlock(&st->lock); - return ret; + return inv_icm42600_enable_regulator_vddio(st); } =20 EXPORT_NS_GPL_DEV_PM_OPS(inv_icm42600_pm_ops, IIO_ICM42600) =3D { diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c b/drivers/iio= /imu/inv_icm42600/inv_icm42600_gyro.c index 8a7cc91276319f0b1714ad11d46e409688b258c4..7ef0a25ec74f6b005ca6e86058d= 67d0be67327df 100644 --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c @@ -277,11 +277,10 @@ static int inv_icm42600_gyro_write_scale(struct iio_d= ev *indio_dev, conf.fs =3D idx / 2; =20 pm_runtime_get_sync(dev); - mutex_lock(&st->lock); =20 - ret =3D inv_icm42600_set_gyro_conf(st, &conf, NULL); + scoped_guard(mutex, &st->lock) + ret =3D inv_icm42600_set_gyro_conf(st, &conf, NULL); =20 - mutex_unlock(&st->lock); pm_runtime_put_autosuspend(dev); =20 return ret; @@ -688,16 +687,11 @@ static int inv_icm42600_gyro_hwfifo_set_watermark(str= uct iio_dev *indio_dev, unsigned int val) { struct inv_icm42600_state *st =3D iio_device_get_drvdata(indio_dev); - int ret; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 st->fifo.watermark.gyro =3D val; - ret =3D inv_icm42600_buffer_update_watermark(st); - - mutex_unlock(&st->lock); - - return ret; + return inv_icm42600_buffer_update_watermark(st); } =20 static int inv_icm42600_gyro_hwfifo_flush(struct iio_dev *indio_dev, @@ -709,15 +703,13 @@ static int inv_icm42600_gyro_hwfifo_flush(struct iio_= dev *indio_dev, if (count =3D=3D 0) return 0; =20 - mutex_lock(&st->lock); + guard(mutex)(&st->lock); =20 ret =3D inv_icm42600_buffer_hwfifo_flush(st, count); - if (!ret) - ret =3D st->fifo.nb.gyro; - - mutex_unlock(&st->lock); + if (ret) + return ret; =20 - return ret; + return st->fifo.nb.gyro; } =20 static const struct iio_info inv_icm42600_gyro_info =3D { --=20 2.50.1