From patchwork Fri Feb 16 17:52:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13560417 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1346612F38D; Fri, 16 Feb 2024 17:52:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708105964; cv=none; b=WhRa6cTIqoFRbvooPBnbOtqqbsrvkcRF4GA/Ay+pXF9RKWfOlsPLnVhdl1g5MYTFf1wiJaVWXtpR4IPkh0UE2QqbT5c0EO8FHQ6QNIYEoee+Tn0wsRTGSfWR5UnmQgFcVakM2RdePnE9BjeESi0GJB2pDQjwgCiRzJTuRh2D6Es= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708105964; c=relaxed/simple; bh=gZcNKYyfXotLlrZugPfjZu+r2vzoJfxqVIW/Zvhx97Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FMTbpkgjHjB3sohuYaO7K1Jr6hb4bexEI0A0PVAwdMtJdPoeRUKHcIutsdpryMyGVEXSUYR2n3WIZzkaZ12zPNprLTL/cRadaVUHv9lkFW5ToM+cbIiJhifNt5mfa6K7CSPm/C1k6w/gWPAvEFYKUPMSHTAnjy7SFkZ9lUQPzn4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qF6oc5ct; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qF6oc5ct" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24AA1C43394; Fri, 16 Feb 2024 17:52:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708105963; bh=gZcNKYyfXotLlrZugPfjZu+r2vzoJfxqVIW/Zvhx97Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qF6oc5ctgliN//gOGRPP/Pmos7Z0LvcwsRNTds/TniRVMqS5t5jtHurxxQa0gZ3zV Wv2pJx9U1brdKepTOZ07JzjShn+Panido7fHLAJFiO6zitjEMGdIjrTDnvqXAL5aUx 41oQnNCx/v8jrXY8xuPiIpoAaVpCSqcE6JZTc947hU0i9PlgiDOu2ws0chs6d1APCa 2niY0FQLPCNHQ4u+N6H7ObPt8T8Ctlc7i0dFSW7TKsc0Qfw0Hbyq/TnnbLEgNIxZzc pHkVfulPayTtGnkOwwIrOHAuRTVHs3WwEkRA2ojWPbxyBBRdKK1+WtSiiZMdztCjfB i2oSkd3mhiA2Q== From: Jonathan Cameron To: linux-iio@vger.kernel.org, "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , Heikki Krogerus , Sakari Ailus , Julia Lawall Cc: =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Peter Zijlstra , Jonathan Cameron Subject: [PATCH v3 01/15] device property: Move fwnode_handle_put() into property.h Date: Fri, 16 Feb 2024 17:52:07 +0000 Message-ID: <20240216175221.900565-2-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216175221.900565-1-jic23@kernel.org> References: <20240216175221.900565-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron By having this function as static inline in the header, the compiler is able to see if can optimize the call out if (IS_ERR_OR_NULL(fwnode)) This will allow a simpler DEFINE_FREE() call in the following patch. Suggested-by: Sakari Ailus Signed-off-by: Jonathan Cameron --- drivers/base/property.c | 14 -------------- include/linux/property.h | 14 +++++++++++++- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index a1b01ab42052..53e42031c646 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -923,20 +923,6 @@ struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode) } EXPORT_SYMBOL_GPL(fwnode_handle_get); -/** - * fwnode_handle_put - Drop reference to a device node - * @fwnode: Pointer to the device node to drop the reference to. - * - * This has to be used when terminating device_for_each_child_node() iteration - * with break or return to prevent stale device node references from being left - * behind. - */ -void fwnode_handle_put(struct fwnode_handle *fwnode) -{ - fwnode_call_void_op(fwnode, put); -} -EXPORT_SYMBOL_GPL(fwnode_handle_put); - /** * fwnode_device_is_available - check if a device is available for use * @fwnode: Pointer to the fwnode of the device. diff --git a/include/linux/property.h b/include/linux/property.h index e6516d0b7d52..151bcab4f92a 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -187,7 +187,19 @@ struct fwnode_handle *device_get_named_child_node(const struct device *dev, const char *childname); struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode); -void fwnode_handle_put(struct fwnode_handle *fwnode); + +/** + * fwnode_handle_put - Drop reference to a device node + * @fwnode: Pointer to the device node to drop the reference to. + * + * This has to be used when terminating device_for_each_child_node() iteration + * with break or return to prevent stale device node references from being left + * behind. + */ +static inline void fwnode_handle_put(struct fwnode_handle *fwnode) +{ + fwnode_call_void_op(fwnode, put); +} int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index); int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name); From patchwork Fri Feb 16 17:52:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13560418 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8B8A812F38D; Fri, 16 Feb 2024 17:52:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708105970; cv=none; b=XvVeohppBkpgDBkK3akUskH8n12eHF6ZJ+HiKFGNLjrFlKB4HkFN4t2JpKKZuIfvhxq70STTPDzW9lGI2RWLddMBoQDP6vPmsTePRIXUTSNT8o77oiS/nJFX/jamOuq/iYsh7IsJm/teZiqXSnEmO68zEIomoyGL352lD/aJjCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708105970; c=relaxed/simple; bh=ooH3tVQ8RhEdYrJS+Vd+dsFlhzvCEObmeWM2dC5oN6E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h4OHXJlkVbQvzvWUJzmRWRi6XEhcFWEQckDzRo0T9JxO1onye6OJOLUuyQLfvdHdoJ7f6R+XAcNh4MfE+Xq6fhfGJA/vMiEjT8Ca8xs95eTKZF5S292uTF6fvFU3GutTyghEc+aQFZsWDsvJM/96y0vTf+QSe3aY37d1wxqsYk4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RQMr2kNI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RQMr2kNI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04299C433F1; Fri, 16 Feb 2024 17:52:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708105970; bh=ooH3tVQ8RhEdYrJS+Vd+dsFlhzvCEObmeWM2dC5oN6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RQMr2kNIKv9JO+vemAAOG8JYySOol6MLWIkaHRKyVby2H7S6SMaynLsGdo7yu+uVJ 899WJBVOTgy/a05jzF0BRU4WsC/ojl5DnyvBi9sBjY76ibULtb7W1RJuOS6thfcqyo y3FivUtfZNmVnNC8a7iLuvneheBCicG9DQmaeLGv1Kh4+cQAfTIsPHtN3cPmL03Xpj waRZn3KjkJf4fwbunwVdiCUUHr8tksy5aT2v2SAsioyi4b8klRjRigJ+nRnXYOcV3M BQTp753NzLtYvLXyGQC76KhGFAKsLt8PYdU9X4e2OsEV5vsufj64jgwJ89wkdY00Du NZWCgIMHxtE5Q== From: Jonathan Cameron To: linux-iio@vger.kernel.org, "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , Heikki Krogerus , Sakari Ailus , Julia Lawall Cc: =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Peter Zijlstra , Jonathan Cameron Subject: [PATCH v3 02/15] device property: Add cleanup.h based fwnode_handle_put() scope based cleanup. Date: Fri, 16 Feb 2024 17:52:08 +0000 Message-ID: <20240216175221.900565-3-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216175221.900565-1-jic23@kernel.org> References: <20240216175221.900565-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Useful where the fwnode_handle was obtained from a call such as fwnode_find_reference() as it will safely do nothing if IS_ERR() is true and will automatically release the reference on the variable leaving scope. Reviewed-by: Andy Shevchenko Signed-off-by: Jonathan Cameron --- include/linux/property.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/property.h b/include/linux/property.h index 151bcab4f92a..9e67c3c4df6e 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -201,6 +202,8 @@ static inline void fwnode_handle_put(struct fwnode_handle *fwnode) fwnode_call_void_op(fwnode, put); } +DEFINE_FREE(fwnode_handle, struct fwnode_handle *, fwnode_handle_put(_T)) + int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index); int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name); From patchwork Fri Feb 16 17:52:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13560419 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 95CA7132C1B; Fri, 16 Feb 2024 17:52:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708105978; cv=none; b=AelW+2YSHqmqkfp+Vz5BJp+4la5bSrQ81zI4s/VAsychwlcFwCM1upFzO4ieaROsIB2GtC9J7iA8XL7CfvyyHKmUzVRWe8EOzZLGNhJONsu4Xb1V9Yjoep8Lsd0fBkzTqtRxFen5ImEmDFQ11DzfkyL3rHM0k8xGCnzgpcFFRqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708105978; c=relaxed/simple; bh=u/kM9IeeMz28QJo6vL+8ec8i5DgcI3ZL6tvQUDPE70k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=po/9KVcxzxfe056mNllRTbgJ/Mnqn+lkTX2nmExf5lXjPINursBOWV7S6MNeN7XWcb/8w5JSL5zzzsG+LIo3BngUEyA3txbMJDopAF1l26j8FJSmFObuLkVdbbu9FxsGa0mSMvhZRU790X+zXG54BF4qCsy2THpj9Mc0/L9eEe4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZZwCRa0x; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZZwCRa0x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF84AC43394; Fri, 16 Feb 2024 17:52:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708105978; bh=u/kM9IeeMz28QJo6vL+8ec8i5DgcI3ZL6tvQUDPE70k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZZwCRa0x9GHIAy7EYezi6TcalXTCgD+zNEGY9MQ59WJpCHs+2/IKU6VduKrtktEwY tAMrJmKc46FdOpwDMmE+OQ6Uwb2OrzMpwJ7xlgmMVSKrRSm+sA+wazHOdpC4pubAC4 fIaxUYaxbpaAZ0ZWh5xxzoh9cvEZMU4Ofyi8c+EMa2yIUBctbu47ImGhfpoM3uwD7G DwAC9dBJzGLfs9woVR0WmVfcdthysln1T+i2HqrAjqW7HuAkRz9mXx7kN14/BxQGN6 /qUrAjz6kH8StnbIIxreBNr8An28nP1nT/pR65aP4P2Lzcrt5prFDa8fjRsWWJRL1t HtsmYIAL140Lg== From: Jonathan Cameron To: linux-iio@vger.kernel.org, "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , Heikki Krogerus , Sakari Ailus , Julia Lawall Cc: =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Peter Zijlstra , Jonathan Cameron Subject: [PATCH v3 03/15] iio: temp: ltc2983: Use __free(fwnode_handle) to replace fwnode_handle_put() calls Date: Fri, 16 Feb 2024 17:52:09 +0000 Message-ID: <20240216175221.900565-4-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216175221.900565-1-jic23@kernel.org> References: <20240216175221.900565-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron This use of the new cleanup.h scope based freeing infrastructure allows us to exit directly from error conditions and in the good path with the reference obtained from fwnode_find_reference() (which may be an error pointer) automatically released. Cc: Cosmin Tanislav Cc: Nuno Sá Signed-off-by: Jonathan Cameron --- v2: Move the declarations down to where they are assigned. This both clearly associates the cleanup with the action that it is cleaning up and avoid potential future missordering of cleanup. --- drivers/iio/temperature/ltc2983.c | 76 ++++++++++--------------------- 1 file changed, 24 insertions(+), 52 deletions(-) diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c index fcb96c44d954..47380d5e6b92 100644 --- a/drivers/iio/temperature/ltc2983.c +++ b/drivers/iio/temperature/ltc2983.c @@ -656,7 +656,6 @@ ltc2983_thermocouple_new(const struct fwnode_handle *child, struct ltc2983_data const struct ltc2983_sensor *sensor) { struct ltc2983_thermocouple *thermo; - struct fwnode_handle *ref; u32 oc_current; int ret; @@ -703,7 +702,8 @@ ltc2983_thermocouple_new(const struct fwnode_handle *child, struct ltc2983_data return ERR_PTR(-EINVAL); } - ref = fwnode_find_reference(child, "adi,cold-junction-handle", 0); + struct fwnode_handle *ref __free(fwnode_handle) = + fwnode_find_reference(child, "adi,cold-junction-handle", 0); if (IS_ERR(ref)) { ref = NULL; } else { @@ -714,7 +714,7 @@ ltc2983_thermocouple_new(const struct fwnode_handle *child, struct ltc2983_data * the error right away. */ dev_err(&st->spi->dev, "Property reg must be given\n"); - goto fail; + return ERR_PTR(ret); } } @@ -725,22 +725,15 @@ ltc2983_thermocouple_new(const struct fwnode_handle *child, struct ltc2983_data thermo->custom = __ltc2983_custom_sensor_new(st, child, propname, false, 16384, true); - if (IS_ERR(thermo->custom)) { - ret = PTR_ERR(thermo->custom); - goto fail; - } + if (IS_ERR(thermo->custom)) + return ERR_CAST(thermo->custom); } /* set common parameters */ thermo->sensor.fault_handler = ltc2983_thermocouple_fault_handler; thermo->sensor.assign_chan = ltc2983_thermocouple_assign_chan; - fwnode_handle_put(ref); return &thermo->sensor; - -fail: - fwnode_handle_put(ref); - return ERR_PTR(ret); } static struct ltc2983_sensor * @@ -750,14 +743,14 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, struct ltc2983_rtd *rtd; int ret = 0; struct device *dev = &st->spi->dev; - struct fwnode_handle *ref; u32 excitation_current = 0, n_wires = 0; rtd = devm_kzalloc(dev, sizeof(*rtd), GFP_KERNEL); if (!rtd) return ERR_PTR(-ENOMEM); - ref = fwnode_find_reference(child, "adi,rsense-handle", 0); + struct fwnode_handle *ref __free(fwnode_handle) = + fwnode_find_reference(child, "adi,rsense-handle", 0); if (IS_ERR(ref)) { dev_err(dev, "Property adi,rsense-handle missing or invalid"); return ERR_CAST(ref); @@ -766,7 +759,7 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, ret = fwnode_property_read_u32(ref, "reg", &rtd->r_sense_chan); if (ret) { dev_err(dev, "Property reg must be given\n"); - goto fail; + return ERR_PTR(ret); } ret = fwnode_property_read_u32(child, "adi,number-of-wires", &n_wires); @@ -787,8 +780,7 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, break; default: dev_err(dev, "Invalid number of wires:%u\n", n_wires); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } } @@ -798,8 +790,7 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, if (n_wires == 2 || n_wires == 3) { dev_err(dev, "Rotation not allowed for 2/3 Wire RTDs"); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } rtd->sensor_config |= LTC2983_RTD_C_ROTATE(1); } else { @@ -829,16 +820,14 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, "Invalid rsense chann:%d to use in kelvin rsense", rtd->r_sense_chan); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } if (sensor->chan < min || sensor->chan > max) { dev_err(dev, "Invalid chann:%d for the rtd config", sensor->chan); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } } else { /* same as differential case */ @@ -846,8 +835,7 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, dev_err(&st->spi->dev, "Invalid chann:%d for RTD", sensor->chan); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } } @@ -856,10 +844,8 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, rtd->custom = __ltc2983_custom_sensor_new(st, child, "adi,custom-rtd", false, 2048, false); - if (IS_ERR(rtd->custom)) { - ret = PTR_ERR(rtd->custom); - goto fail; - } + if (IS_ERR(rtd->custom)) + return ERR_CAST(rtd->custom); } /* set common parameters */ @@ -901,18 +887,13 @@ ltc2983_rtd_new(const struct fwnode_handle *child, struct ltc2983_data *st, dev_err(&st->spi->dev, "Invalid value for excitation current(%u)", excitation_current); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } } fwnode_property_read_u32(child, "adi,rtd-curve", &rtd->rtd_curve); - fwnode_handle_put(ref); return &rtd->sensor; -fail: - fwnode_handle_put(ref); - return ERR_PTR(ret); } static struct ltc2983_sensor * @@ -921,7 +902,6 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s { struct ltc2983_thermistor *thermistor; struct device *dev = &st->spi->dev; - struct fwnode_handle *ref; u32 excitation_current = 0; int ret = 0; @@ -929,7 +909,8 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s if (!thermistor) return ERR_PTR(-ENOMEM); - ref = fwnode_find_reference(child, "adi,rsense-handle", 0); + struct fwnode_handle *ref __free(fwnode_handle) = + fwnode_find_reference(child, "adi,rsense-handle", 0); if (IS_ERR(ref)) { dev_err(dev, "Property adi,rsense-handle missing or invalid"); return ERR_CAST(ref); @@ -938,7 +919,7 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s ret = fwnode_property_read_u32(ref, "reg", &thermistor->r_sense_chan); if (ret) { dev_err(dev, "rsense channel must be configured...\n"); - goto fail; + return ERR_PTR(ret); } if (fwnode_property_read_bool(child, "adi,single-ended")) { @@ -958,8 +939,7 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s dev_err(&st->spi->dev, "Invalid chann:%d for differential thermistor", sensor->chan); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } /* check custom sensor */ @@ -978,10 +958,8 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s propname, steinhart, 64, false); - if (IS_ERR(thermistor->custom)) { - ret = PTR_ERR(thermistor->custom); - goto fail; - } + if (IS_ERR(thermistor->custom)) + return ERR_CAST(thermistor->custom); } /* set common parameters */ thermistor->sensor.fault_handler = ltc2983_common_fault_handler; @@ -1005,8 +983,7 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s LTC2983_SENSOR_THERMISTOR_STEINHART) { dev_err(&st->spi->dev, "Auto Range not allowed for custom sensors\n"); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } thermistor->excitation_current = 0x0c; break; @@ -1047,16 +1024,11 @@ ltc2983_thermistor_new(const struct fwnode_handle *child, struct ltc2983_data *s dev_err(&st->spi->dev, "Invalid value for excitation current(%u)", excitation_current); - ret = -EINVAL; - goto fail; + return ERR_PTR(-EINVAL); } } - fwnode_handle_put(ref); return &thermistor->sensor; -fail: - fwnode_handle_put(ref); - return ERR_PTR(ret); } static struct ltc2983_sensor * From patchwork Fri Feb 16 17:52:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13560420 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 68E8413328F; Fri, 16 Feb 2024 17:53:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708105985; cv=none; b=FoaPWPLjzX7UTYTWFPmnbb4K4BBZH57f7zu4/ZuuUY2haxdxdHzlTC0aUWPRWDoxNnjvgy7SF5f1EJYaydVaafzHkU/gSCBcz1yN3FJVyoAFLVWaf6vkALL35yBC7yozATFVCbKOwBDFXHKDZPuqygECud/rsDNIgdwEwooPJag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708105985; c=relaxed/simple; bh=xoqaZeH+L6kiORxJxGHcYCa8+Q9swQYNI0S2PeIKwY4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KTWmDx1OKAf62/k+q0tsNAcPDsL7gqsZhijIjuZmSOP5dW5okHTKfc8z3jOpT4e1pFSQBR1d+5xDwLanUcLH2d1RhZ7l2px89vUtt0RvwrQQcE+BnBbVktjCL7HSOR1dcmGcpt/WhX9cRvgM3JWweOmWUJsrKDF4Xmb56oKDdqk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aOUu2QNx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aOUu2QNx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B33D4C433F1; Fri, 16 Feb 2024 17:52:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708105985; bh=xoqaZeH+L6kiORxJxGHcYCa8+Q9swQYNI0S2PeIKwY4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aOUu2QNx2TiY6AAFUXPBZj6/SCh15x/Clyi5xZ3EGSYIv5Zk7wH3Gsg8g4yUdVX4j LJSzBQiN59XK7CC6v7GfGfb+Bwq31Sa5dSIt2WxcLOQk4jOpZSIXWuLJCVOOnDnD7l zHFYo05vvVKs43tYYayoICPrn6t9xG1Sj5sEf6F9X5kBfGOqWPZQJ/4I35DYcHXBnU Gisg/I2Hm+Ux2Tm8aRcDgtWDJkwLzt0DxcXeCg95aOma77K+Nx/D9dEGmxjuPGfa48 SdhikAfweaKkCKtde2VDdQjYkkyDKhDgNMiZIvAT204++y2LYKiLtpxF9MCORl1Ua9 sIj3ue2TZDYcA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , Heikki Krogerus , Sakari Ailus , Julia Lawall Cc: =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Peter Zijlstra , Jonathan Cameron Subject: [PATCH v3 04/15] device property: Introduce device_for_each_child_node_scoped() Date: Fri, 16 Feb 2024 17:52:10 +0000 Message-ID: <20240216175221.900565-5-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216175221.900565-1-jic23@kernel.org> References: <20240216175221.900565-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Similar to recently propose for_each_child_of_node_scoped() this new version of the loop macro instantiates a new local struct fwnode_handle * that uses the __free(fwnode_handle) auto cleanup handling so that if a reference to a node is held on early exit from the loop the reference will be released. If the loop runs to completion, the child pointer will be NULL and no action will be taken. The reason this is useful is that it removes the need for fwnode_handle_put() on early loop exits. If there is a need to retain the reference, then return_ptr(child) or no_free_ptr(child) may be used to safely disable the auto cleanup. Signed-off-by: Jonathan Cameron --- include/linux/property.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/property.h b/include/linux/property.h index 9e67c3c4df6e..421ccfd43fb1 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -182,6 +182,11 @@ struct fwnode_handle *device_get_next_child_node(const struct device *dev, for (child = device_get_next_child_node(dev, NULL); child; \ child = device_get_next_child_node(dev, child)) +#define device_for_each_child_node_scoped(dev, child)\ + for (struct fwnode_handle *child __free(fwnode_handle) = \ + device_get_next_child_node(dev, NULL); child; \ + child = device_get_next_child_node(dev, child)) + struct fwnode_handle *fwnode_get_named_child_node(const struct fwnode_handle *fwnode, const char *childname); struct fwnode_handle *device_get_named_child_node(const struct device *dev, From patchwork Fri Feb 16 17:52:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13560421 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0A3E6132C35; Fri, 16 Feb 2024 17:53:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708105991; cv=none; b=I5HEYQ4Btnf0D1TT6vNPjugkrlaHMgISNpdSZ4kgd8NfBqqS0iXlX4uDoFDlNLmEbqRlIbKmp6h4hgA2+vSjXIbnBlmToZlzs2K5uheodPjxsyfrBFtdjPaRSHBgAg8QjopNoksoFAxyI6QtFjRwNy9QW1a0O2Ss6Cy+njU3l3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708105991; c=relaxed/simple; bh=iojKGFHS6Uwh1iJBxwwefEnfrUPfJjcrCNVF0odaKFQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rVdAdBht/9YMhhyVQHLee4FaM6JFryv1ODvAxxJxF4uaZ2wyeaOejUhCBWJz8kbMW1WUEzsjxJrKkk55WsMaNNAAqp0v014lfAe7eM7PMVqxF2Qvxq9YmoNBY0EJM+LGHSy+e9D698apCYhXMOcY3pZDXbvB9x2QwlgOBcQrXaI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cQUuGSZ8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cQUuGSZ8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA640C43399; Fri, 16 Feb 2024 17:53:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708105990; bh=iojKGFHS6Uwh1iJBxwwefEnfrUPfJjcrCNVF0odaKFQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cQUuGSZ8oks7AHEPa4tQfCJKOQEvROEWT6rZrI1bxkAYmIBELVt2ijrnrPTWFlOCy J5svY63Q4aND3zg6dFemt8WkB0SXj+J73M8C1+p6+cRBQI2lFEzq1Uh5m4vFYtxgex bGKuEKc64XTAp4pXOiD0sgJ0Gzk/6864+cxfNdxPzArBSBbfSYd/vxcQGSzBrDGWBg oY5PlKpayqmckGWX1H9LeVFaowq+sDPh697gJlU47ndw3l8NJOO0T+8Xl6Nd+z2iNX /Ej57VCUMxMsfb6cuGIULUORi+6f7bSV4XylYsQVBjlWrSts5C/D2J128AIH7lTyru VAoJmwhfrHJSg== From: Jonathan Cameron To: linux-iio@vger.kernel.org, "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , Heikki Krogerus , Sakari Ailus , Julia Lawall Cc: =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Peter Zijlstra , Jonathan Cameron Subject: [PATCH v3 05/15] iio: adc: max11410: Use device_for_each_child_node_scoped() Date: Fri, 16 Feb 2024 17:52:11 +0000 Message-ID: <20240216175221.900565-6-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216175221.900565-1-jic23@kernel.org> References: <20240216175221.900565-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Switching to the _scoped() version removes the need for manual calling of fwnode_handle_put() in the paths where the code exits the loop early. In this case that's all in error paths. Cc: Nuno Sá Cc: Ibrahim Tilki Signed-off-by: Jonathan Cameron --- drivers/iio/adc/max11410.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/drivers/iio/adc/max11410.c b/drivers/iio/adc/max11410.c index 6af829349b4e..45368850b220 100644 --- a/drivers/iio/adc/max11410.c +++ b/drivers/iio/adc/max11410.c @@ -696,7 +696,6 @@ static int max11410_parse_channels(struct max11410_state *st, struct device *dev = &st->spi_dev->dev; struct max11410_channel_config *cfg; struct iio_chan_spec *channels; - struct fwnode_handle *child; u32 reference, sig_path; const char *node_name; u32 inputs[2], scale; @@ -720,7 +719,7 @@ static int max11410_parse_channels(struct max11410_state *st, if (!st->channels) return -ENOMEM; - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { node_name = fwnode_get_name(child); if (fwnode_property_present(child, "diff-channels")) { ret = fwnode_property_read_u32_array(child, @@ -735,47 +734,37 @@ static int max11410_parse_channels(struct max11410_state *st, inputs[1] = 0; chanspec.differential = 0; } - if (ret) { - fwnode_handle_put(child); + if (ret) return ret; - } if (inputs[0] > MAX11410_CHANNEL_INDEX_MAX || - inputs[1] > MAX11410_CHANNEL_INDEX_MAX) { - fwnode_handle_put(child); + inputs[1] > MAX11410_CHANNEL_INDEX_MAX) return dev_err_probe(&indio_dev->dev, -EINVAL, "Invalid channel index for %s, should be less than %d\n", node_name, MAX11410_CHANNEL_INDEX_MAX + 1); - } cfg = &st->channels[chan_idx]; reference = MAX11410_REFSEL_AVDD_AGND; fwnode_property_read_u32(child, "adi,reference", &reference); - if (reference > MAX11410_REFSEL_MAX) { - fwnode_handle_put(child); + if (reference > MAX11410_REFSEL_MAX) return dev_err_probe(&indio_dev->dev, -EINVAL, "Invalid adi,reference value for %s, should be less than %d.\n", node_name, MAX11410_REFSEL_MAX + 1); - } if (!max11410_get_vrefp(st, reference) || - (!max11410_get_vrefn(st, reference) && reference <= 2)) { - fwnode_handle_put(child); + (!max11410_get_vrefn(st, reference) && reference <= 2)) return dev_err_probe(&indio_dev->dev, -EINVAL, "Invalid VREF configuration for %s, either specify corresponding VREF regulators or change adi,reference property.\n", node_name); - } sig_path = MAX11410_PGA_SIG_PATH_BUFFERED; fwnode_property_read_u32(child, "adi,input-mode", &sig_path); - if (sig_path > MAX11410_SIG_PATH_MAX) { - fwnode_handle_put(child); + if (sig_path > MAX11410_SIG_PATH_MAX) return dev_err_probe(&indio_dev->dev, -EINVAL, "Invalid adi,input-mode value for %s, should be less than %d.\n", node_name, MAX11410_SIG_PATH_MAX + 1); - } fwnode_property_read_u32(child, "settling-time-us", &cfg->settling_time_us); @@ -793,10 +782,8 @@ static int max11410_parse_channels(struct max11410_state *st, cfg->scale_avail = devm_kcalloc(dev, MAX11410_SCALE_AVAIL_SIZE * 2, sizeof(*cfg->scale_avail), GFP_KERNEL); - if (!cfg->scale_avail) { - fwnode_handle_put(child); + if (!cfg->scale_avail) return -ENOMEM; - } scale = max11410_get_scale(st, *cfg); for (i = 0; i < MAX11410_SCALE_AVAIL_SIZE; i++) { From patchwork Fri Feb 16 17:52:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13560422 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 56D12132C35; Fri, 16 Feb 2024 17:53:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708105996; cv=none; b=ErNtSMTj2fEjMskJ58UdowJ1qrqxr3xP0bWcHx+dD99zjOEDXqSFzuAixnRA38rlBd0ysXxVizKh2vx7oZHA3yVF6b2LSAOBmozSaWIX6c5ZvaPhMuNwk9bxAthUVAxlmbj+SamDcjs+qoF5BskZjLVCmdcxNYEf14JlUvN/sAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708105996; c=relaxed/simple; bh=aVEHVNZLRW+7hOZXFm1bFqSgnqdVSQ6FtHIyAf/1FKo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QEEgxBN9rige0On0AGnjqCTnQBD3th3HxEbUlUbfXmrLZtftZQjmON1IJze01VSlzYWhBjzaKTf9jEnP+PQ2AJQnEyDK0+B/9Q4BrhLrD3vH2M1j4dHLxbhO1H8skWN8B16yGDcPJM5rB1Xr4ktMaxtJM7/tPorHVxldSxGM9FI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jhSRBsmG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jhSRBsmG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5982C43390; Fri, 16 Feb 2024 17:53:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708105995; bh=aVEHVNZLRW+7hOZXFm1bFqSgnqdVSQ6FtHIyAf/1FKo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jhSRBsmGMLfCkNxhEPI4VtSVRyvNSCuxxrN3AM4rW8Pgs8TDRflv/XhD4+wxQ9Qwq QBpousA2fbSfxf3GCzSk/mKamt8TuXnZ7++kMGwc1ex27ss1ANLA6qtdDIQ9kpNIab BSIw9+bUZPpYhe6w7R78PKzTed6sHbfj7EbLRgdZwV3Jq6+W+Jc4HRMH3pGYngUaPR wZUhfiyl7y0YFqSJ1eWBI0Sg87zvjl/8oI3fqUNGOX1j4TfWgeXRdi+6r7wjMyUnfI hRFpobgsLvy3GGFQhXD1puivbZ60Wp16IaVr5aw55FkrCVKrqvR+iXxAOIuClHSNuw NwdHFrzCu1Eng== From: Jonathan Cameron To: linux-iio@vger.kernel.org, "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , Heikki Krogerus , Sakari Ailus , Julia Lawall Cc: =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Peter Zijlstra , Jonathan Cameron Subject: [PATCH v3 06/15] iio: adc: mcp3564: Use device_for_each_child_node_scoped() Date: Fri, 16 Feb 2024 17:52:12 +0000 Message-ID: <20240216175221.900565-7-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216175221.900565-1-jic23@kernel.org> References: <20240216175221.900565-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Switching to the _scoped() version removes the need for manual calling of fwnode_handle_put() in the paths where the code exits the loop early. In this case that's all in error paths. Cc: Marius Cristea Signed-off-by: Jonathan Cameron --- drivers/iio/adc/mcp3564.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/iio/adc/mcp3564.c b/drivers/iio/adc/mcp3564.c index 311b613b6057..e2ae13f1e842 100644 --- a/drivers/iio/adc/mcp3564.c +++ b/drivers/iio/adc/mcp3564.c @@ -998,7 +998,6 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev) struct mcp3564_state *adc = iio_priv(indio_dev); struct device *dev = &adc->spi->dev; struct iio_chan_spec *channels; - struct fwnode_handle *child; struct iio_chan_spec chanspec = mcp3564_channel_template; struct iio_chan_spec temp_chanspec = mcp3564_temp_channel_template; struct iio_chan_spec burnout_chanspec = mcp3564_burnout_channel_template; @@ -1025,7 +1024,7 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev) if (!channels) return dev_err_probe(dev, -ENOMEM, "Can't allocate memory\n"); - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { node_name = fwnode_get_name(child); if (fwnode_property_present(child, "diff-channels")) { @@ -1033,26 +1032,25 @@ static int mcp3564_parse_fw_children(struct iio_dev *indio_dev) "diff-channels", inputs, ARRAY_SIZE(inputs)); + if (ret) + return ret; + chanspec.differential = 1; } else { ret = fwnode_property_read_u32(child, "reg", &inputs[0]); + if (ret) + return ret; chanspec.differential = 0; inputs[1] = MCP3564_AGND; } - if (ret) { - fwnode_handle_put(child); - return ret; - } if (inputs[0] > MCP3564_INTERNAL_VCM || - inputs[1] > MCP3564_INTERNAL_VCM) { - fwnode_handle_put(child); + inputs[1] > MCP3564_INTERNAL_VCM) return dev_err_probe(&indio_dev->dev, -EINVAL, "Channel index > %d, for %s\n", MCP3564_INTERNAL_VCM + 1, node_name); - } chanspec.address = (inputs[0] << 4) | inputs[1]; chanspec.channel = inputs[0]; From patchwork Fri Feb 16 17:52:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13560423 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 74AA6132C0F; Fri, 16 Feb 2024 17:53:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106002; cv=none; b=gqJnB8bQMzTm/AgKRkyhdppWnqMuO/XIwmfVfKTD4+DjBSj1r54DgcACkgKFMdwqyFKAJC0I+XwwB9nJ+zW7aGr5SNhRqcx3D/GUUKajZPdUL5lOFBaOHzg+rGeBaPNNdskhY5B9NvHIxPqaT0TjlPeVDtPwyfpcmXwN/v4Y9yY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106002; c=relaxed/simple; bh=2mqddr2vk1tIUyCyEYFgQRTgvjJnligNLqFwI5ekcbQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nyxfOsEEEToj1Uh9oREUSq2Gs5IFw0PfJZPMKM3T4RVydYdxKbOE7SolhSsrNXioyBPI+wXLsmqpmEP/32C/xI2RaA5/pspR/s45cL05qQe2JBJZkN1SS93Id4jTENvYhcYS2Mwxm7lm5Xcszj1/yX0MHvoP1P1+8HirymgRpqk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=R5Yhg0nq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="R5Yhg0nq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E178C43394; Fri, 16 Feb 2024 17:53:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708106002; bh=2mqddr2vk1tIUyCyEYFgQRTgvjJnligNLqFwI5ekcbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R5Yhg0nqNKjYX21fB8wUKnj4CFIpeWMDoChM0ATV7ueCTwVQw91ilucEvE9ftDnZc UXeVEL1/X7jFH7TdFopddAC9YXaMF15vNCVxiXev1Qv5cy3oLsOq75tBRzjrxHLFTA zd1jASjqeHWTYwlOhUrThqJgf6y+fmiGIp+Joau6KR1VC6uwyl4Yd47f2p9Zk2aCt9 CWEfoOsmxALatGJ7qbmrSHDi0p3/O2DU+u12DKUqVDihfJGKt3DHc5sYN+05Lgio5f KK+MTo6VKK6mQ4F527cSb+lwGE2ED8iG5GXQ///Z0n6N43UbF7bLSpLR0fV8Auphgt Co8sJ83DYfhHA== From: Jonathan Cameron To: linux-iio@vger.kernel.org, "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , Heikki Krogerus , Sakari Ailus , Julia Lawall Cc: =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Peter Zijlstra , Jonathan Cameron Subject: [PATCH v3 07/15] iio: adc: qcom-spmi-adc5: Use device_for_each_child_node_scoped() Date: Fri, 16 Feb 2024 17:52:13 +0000 Message-ID: <20240216175221.900565-8-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216175221.900565-1-jic23@kernel.org> References: <20240216175221.900565-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Switching to the _scoped() version removes the need for manual calling of fwnode_handle_put() in the paths where the code exits the loop early. In this case that's all in error paths. A slightly less convincing usecase than many as all the failure paths are wrapped up in a call to a per fwnode_handle utility function. The complexity in that function is sufficient that it makes sense to factor it out even if it this new auto cleanup would enable simpler returns if the code was inline at the call site. Hence I've left it alone. Cc: Marijn Suijten Reviewed-by: Dmitry Baryshkov Signed-off-by: Jonathan Cameron --- drivers/iio/adc/qcom-spmi-adc5.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c index b6b612d733ff..9b69f40beed8 100644 --- a/drivers/iio/adc/qcom-spmi-adc5.c +++ b/drivers/iio/adc/qcom-spmi-adc5.c @@ -825,7 +825,6 @@ static int adc5_get_fw_data(struct adc5_chip *adc) const struct adc5_channels *adc_chan; struct iio_chan_spec *iio_chan; struct adc5_channel_prop prop, *chan_props; - struct fwnode_handle *child; unsigned int index = 0; int ret; @@ -849,12 +848,10 @@ static int adc5_get_fw_data(struct adc5_chip *adc) if (!adc->data) adc->data = &adc5_data_pmic; - device_for_each_child_node(adc->dev, child) { + device_for_each_child_node_scoped(adc->dev, child) { ret = adc5_get_fw_channel_data(adc, &prop, child, adc->data); - if (ret) { - fwnode_handle_put(child); + if (ret) return ret; - } prop.scale_fn_type = adc->data->adc_chans[prop.channel].scale_fn_type; From patchwork Fri Feb 16 17:52:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13560424 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B2696132C0F; Fri, 16 Feb 2024 17:53:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106008; cv=none; b=sWvs/+hFd5CpEQ8GVDM7shKA0Vn+6brP1qLv8Pv32BgB/N+qbEvGzjhH0Vj8qdFdPwITjS/sbtejCpL8R917eHtUkSz4ZOaX/UsnZTsNLgduQRq1H3FoCGw/RQP2GSkOkEumQE5q3uKWddICN36vbWxnY1I8Ml/PYKXiKQ0YwkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106008; c=relaxed/simple; bh=QrHoWfZbRHMq4P70zGYxGeka18F/ERWgdcsa9lr19q4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ki27AchaSJV+crYd0hZ4aG+O9YCgnPQj+6aCgaTp3KE4R1dFQsUKopl4X9Cign1Cgon8eSUpiLKRC+04B/MW5IcdERdz2SCedCXzZOKWRSMjDWDr3lOxnsx6+67hhsuVBOitQx6cmAw9ki/OvbsqRkntQktSRHEUE8ieNW0gWqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fYKPTIRA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fYKPTIRA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3197C43390; Fri, 16 Feb 2024 17:53:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708106008; bh=QrHoWfZbRHMq4P70zGYxGeka18F/ERWgdcsa9lr19q4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fYKPTIRAmh3TjzAwG6dVCT4pk5tWiZLy7NER9iV3LUfsIkFDuaGh+eNz/xIZzjt4G 8OIG978NUzQrQarInv+yX12BssldtO+ZKj1dTyotR0jWDbt9xhl8hKsxSYWZpx84J5 CrcDwi2wpoCuAkujjEHiNGQgFDO336OQw6CtmU4JBZSRE80L4wXErpzuVoP7S/SQXp zOj7+gYJTj64Ji7Q3ymgM/We4v+8FHCsu853xl6ygJvirNtwYpqWDrreTJxliSOKlD Wfiqc740u0SzR1GSi0euIczwSaDkPUdMBQYYoUzJ5GuI7ewnoibMA+O12ls31ir/1V 2+QkWhLDDWlUw== From: Jonathan Cameron To: linux-iio@vger.kernel.org, "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , Heikki Krogerus , Sakari Ailus , Julia Lawall Cc: =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Peter Zijlstra , Jonathan Cameron Subject: [PATCH v3 08/15] iio: adc: rzg2l_adc: Use device_for_each_child_node_scoped() Date: Fri, 16 Feb 2024 17:52:14 +0000 Message-ID: <20240216175221.900565-9-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216175221.900565-1-jic23@kernel.org> References: <20240216175221.900565-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Switching to the _scoped() version removes the need for manual calling of fwnode_handle_put() in the paths where the code exits the loop early. In this case that's all in error paths. Cc: Lad Prabhakar Signed-off-by: Jonathan Cameron --- drivers/iio/adc/rzg2l_adc.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/iio/adc/rzg2l_adc.c b/drivers/iio/adc/rzg2l_adc.c index 0921ff2d9b3a..cd3a7e46ea53 100644 --- a/drivers/iio/adc/rzg2l_adc.c +++ b/drivers/iio/adc/rzg2l_adc.c @@ -302,7 +302,6 @@ static irqreturn_t rzg2l_adc_isr(int irq, void *dev_id) static int rzg2l_adc_parse_properties(struct platform_device *pdev, struct rzg2l_adc *adc) { struct iio_chan_spec *chan_array; - struct fwnode_handle *fwnode; struct rzg2l_adc_data *data; unsigned int channel; int num_channels; @@ -330,17 +329,13 @@ static int rzg2l_adc_parse_properties(struct platform_device *pdev, struct rzg2l return -ENOMEM; i = 0; - device_for_each_child_node(&pdev->dev, fwnode) { + device_for_each_child_node_scoped(&pdev->dev, fwnode) { ret = fwnode_property_read_u32(fwnode, "reg", &channel); - if (ret) { - fwnode_handle_put(fwnode); + if (ret) return ret; - } - if (channel >= RZG2L_ADC_MAX_CHANNELS) { - fwnode_handle_put(fwnode); + if (channel >= RZG2L_ADC_MAX_CHANNELS) return -EINVAL; - } chan_array[i].type = IIO_VOLTAGE; chan_array[i].indexed = 1; From patchwork Fri Feb 16 17:52:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13560425 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5E5EA13328F; Fri, 16 Feb 2024 17:53:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106014; cv=none; b=Zj8S18YsUhuY+fRdAC45puJyEipaLKjTqtUTkLQlLVaByHAQ3hTanedY1MYLOD4ytT/MPM/qw79wsDvIDC1SekoiG8vKA10WX1tJp7N20IDDcKe8+12usCOBhZ0P+Dt8YX7GzvutMW1ahIC3XdGytdsWvwL7JF3B7z/Tt4KYSjc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106014; c=relaxed/simple; bh=L/DROO4YPVYunSdXLSEqe6Sr2aGPuWHRhNS+WcDI2Ik=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UL9HiqCqEtNJAFn5kOYX8gd997x13C53RAjSM1i9pgvYmbLLwpKseP1EFvvSLPu51zWdIy90Rou8POgTcs3HvgjmQ0RwaR52Bpm91ewo98udilJ/IGd7JyGptEh9VJfyRU7us8RzYyOFOZmkyU2vp1TewjROGync7FAPrVLIYV4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hFWtEGUj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hFWtEGUj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B4FAC433F1; Fri, 16 Feb 2024 17:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708106013; bh=L/DROO4YPVYunSdXLSEqe6Sr2aGPuWHRhNS+WcDI2Ik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hFWtEGUjuAQEzN2TjfPkGSniLd+VYSGkIhBmZiD/F2SV9q/JB7mcblF2Uxm3yXtbV 6p1+TpY4CUVzIN+Sd9wgUlAO1EAGw6nBrd4p8GUST40C9upbPUIYcL9fUyQtUgPhZP rnVEsNmlnCpb/VRhRVfCbunnrUbESMTyDoxO1nNyTNRwvXPemE6rfWSMUXj3qJtXan WM+h26+fGZjZVEQ+YBMMXgiEUDT6n7Oj7nE8TLzfp8wLN5vtYL9dhwCKRcguIz5hZd PJYTiq4fHyJmOBIV29t5982AtWPRWBSddvbeeFu2t01sP/8hn5BOMzDofH4C77LOCU IqFxXGuY/cPAQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org, "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , Heikki Krogerus , Sakari Ailus , Julia Lawall Cc: =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Peter Zijlstra , Jonathan Cameron Subject: [PATCH v3 09/15] iio: adc: stm32: Use device_for_each_child_node_scoped() Date: Fri, 16 Feb 2024 17:52:15 +0000 Message-ID: <20240216175221.900565-10-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216175221.900565-1-jic23@kernel.org> References: <20240216175221.900565-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Switching to the _scoped() version removes the need for manual calling of fwnode_handle_put() in the paths where the code exits the loop early. In this case that's all in error paths. Note this includes a probable fix as in one path an error message was printed with ret == 0. Took advantage of dev_err_probe() to futher simplify things given no longer a need for the goto err. Cc: Olivier Moysan Cc: Fabrice Gasnier Signed-off-by: Jonathan Cameron --- drivers/iio/adc/stm32-adc.c | 63 ++++++++++++++----------------------- 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c index b5d3c9cea5c4..9fd94a792f42 100644 --- a/drivers/iio/adc/stm32-adc.c +++ b/drivers/iio/adc/stm32-adc.c @@ -2187,58 +2187,50 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev, struct iio_chan_spec *channels) { const struct stm32_adc_info *adc_info = adc->cfg->adc_info; - struct fwnode_handle *child; const char *name; int val, scan_index = 0, ret; bool differential; u32 vin[2]; - device_for_each_child_node(&indio_dev->dev, child) { + device_for_each_child_node_scoped(&indio_dev->dev, child) { ret = fwnode_property_read_u32(child, "reg", &val); - if (ret) { - dev_err(&indio_dev->dev, "Missing channel index %d\n", ret); - goto err; - } + if (ret) + return dev_err_probe(&indio_dev->dev, ret, + "Missing channel index\n"); ret = fwnode_property_read_string(child, "label", &name); /* label is optional */ if (!ret) { - if (strlen(name) >= STM32_ADC_CH_SZ) { - dev_err(&indio_dev->dev, "Label %s exceeds %d characters\n", - name, STM32_ADC_CH_SZ); - ret = -EINVAL; - goto err; - } + if (strlen(name) >= STM32_ADC_CH_SZ) + return dev_err_probe(&indio_dev->dev, -EINVAL, + "Label %s exceeds %d characters\n", + name, STM32_ADC_CH_SZ); + strscpy(adc->chan_name[val], name, STM32_ADC_CH_SZ); ret = stm32_adc_populate_int_ch(indio_dev, name, val); if (ret == -ENOENT) continue; else if (ret) - goto err; - } else if (ret != -EINVAL) { - dev_err(&indio_dev->dev, "Invalid label %d\n", ret); - goto err; - } + return ret; + } else if (ret != -EINVAL) + return dev_err_probe(&indio_dev->dev, ret, "Invalid label\n"); - if (val >= adc_info->max_channels) { - dev_err(&indio_dev->dev, "Invalid channel %d\n", val); - ret = -EINVAL; - goto err; - } + if (val >= adc_info->max_channels) + return dev_err_probe(&indio_dev->dev, -EINVAL, + "Invalid channel %d\n", val); differential = false; ret = fwnode_property_read_u32_array(child, "diff-channels", vin, 2); /* diff-channels is optional */ if (!ret) { differential = true; - if (vin[0] != val || vin[1] >= adc_info->max_channels) { - dev_err(&indio_dev->dev, "Invalid channel in%d-in%d\n", - vin[0], vin[1]); - goto err; - } + if (vin[0] != val || vin[1] >= adc_info->max_channels) + return dev_err_probe(&indio_dev->dev, -EINVAL, + "Invalid channel in%d-in%d\n", + vin[0], vin[1]); } else if (ret != -EINVAL) { - dev_err(&indio_dev->dev, "Invalid diff-channels property %d\n", ret); - goto err; + return dev_err_probe(&indio_dev->dev, ret, + "Invalid diff-channels property\n"); } stm32_adc_chan_init_one(indio_dev, &channels[scan_index], val, @@ -2247,11 +2239,9 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev, val = 0; ret = fwnode_property_read_u32(child, "st,min-sample-time-ns", &val); /* st,min-sample-time-ns is optional */ - if (ret && ret != -EINVAL) { - dev_err(&indio_dev->dev, "Invalid st,min-sample-time-ns property %d\n", - ret); - goto err; - } + if (ret && ret != -EINVAL) + return dev_err_probe(&indio_dev->dev, ret, + "Invalid st,min-sample-time-ns property\n"); stm32_adc_smpr_init(adc, channels[scan_index].channel, val); if (differential) @@ -2261,11 +2251,6 @@ static int stm32_adc_generic_chan_init(struct iio_dev *indio_dev, } return scan_index; - -err: - fwnode_handle_put(child); - - return ret; } static int stm32_adc_chan_fw_init(struct iio_dev *indio_dev, bool timestamping) From patchwork Fri Feb 16 17:52:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13560426 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C99771332A0; Fri, 16 Feb 2024 17:53:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106019; cv=none; b=VN2u450ifWgBBO2jf6m0jhSyaUt/1OPxAaJqNEsrTA1/sEv7ulXunFvOz03u2aQtquPW03X1D9YU62ujI5VI/gGwruWdCboHEIr2Mb1Xm3IfT+A62ymzmNRCMiAZHycVVbOTvKakC4qXD/6BhqIOvWlBX1+Fu8S08+dDngAsAMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106019; c=relaxed/simple; bh=Ds74Qrbcn3I42aYg16TeBAqLINL89sm7BvmJAC5S5nc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gRKnVoho9xaLtbYmPsz2Nk8d/t7oOZAT3kZBNblDYyICfa+yMgCKXYpwrg+7/ctDdYyiIr0BuQ7nKZSTc9udqo361N53Oc5oZY+rqUeWtZGo4usZvyElQzDtJcsslEuVc6O85YfaZQJHkaIlpSfikbt4ARD86znFGrEYuEOGInM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t8vx6R9s; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="t8vx6R9s" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A139C43394; Fri, 16 Feb 2024 17:53:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708106019; bh=Ds74Qrbcn3I42aYg16TeBAqLINL89sm7BvmJAC5S5nc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t8vx6R9s2ybzlSVLB6QoCkZItvF0rR21gmxvRPQW9/wOpWbeGRQK9G4yEMJSR/cZS CBDWUp+183qCQ52RODgNIpBhzlsod2i6IXYLzEmhfw+g7qVug+YSg8/5k4dluAxbZN KlMvmdH3JRubXRgpyfeiGy8BMmiq5G+QexUC5uKEsar+WL3ZRgmNbBiJNHjkksh8Kd olGwaJL2r7Zi396H0IMOmdUtKUKilQcDgYHpdSf4EsONWEr4jegBUj4rExXXxrqUIh A1bJnzvW67/feg/aGoTq3LiuLTaJCSotKJpSElbQ55uC+i3apBfWF6DWlkKs6n1dBW G3rK4ALkatQzQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org, "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , Heikki Krogerus , Sakari Ailus , Julia Lawall Cc: =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Peter Zijlstra , Jonathan Cameron Subject: [PATCH v3 10/15] iio: adc: ti-ads1015: Use device_for_each_child_node_scoped() Date: Fri, 16 Feb 2024 17:52:16 +0000 Message-ID: <20240216175221.900565-11-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216175221.900565-1-jic23@kernel.org> References: <20240216175221.900565-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Switching to the _scoped() version removes the need for manual calling of fwnode_handle_put() in the paths where the code exits the loop early. In this case that's all in error paths. Cc: Marek Vasut Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ti-ads1015.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c index 6ae967e4d8fa..d3363d02f292 100644 --- a/drivers/iio/adc/ti-ads1015.c +++ b/drivers/iio/adc/ti-ads1015.c @@ -902,10 +902,9 @@ static int ads1015_client_get_channels_config(struct i2c_client *client) struct iio_dev *indio_dev = i2c_get_clientdata(client); struct ads1015_data *data = iio_priv(indio_dev); struct device *dev = &client->dev; - struct fwnode_handle *node; int i = -1; - device_for_each_child_node(dev, node) { + device_for_each_child_node_scoped(dev, node) { u32 pval; unsigned int channel; unsigned int pga = ADS1015_DEFAULT_PGA; @@ -927,7 +926,6 @@ static int ads1015_client_get_channels_config(struct i2c_client *client) pga = pval; if (pga > 5) { dev_err(dev, "invalid gain on %pfw\n", node); - fwnode_handle_put(node); return -EINVAL; } } @@ -936,7 +934,6 @@ static int ads1015_client_get_channels_config(struct i2c_client *client) data_rate = pval; if (data_rate > 7) { dev_err(dev, "invalid data_rate on %pfw\n", node); - fwnode_handle_put(node); return -EINVAL; } } From patchwork Fri Feb 16 17:52:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13560432 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E9AAD133425; Fri, 16 Feb 2024 17:53:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106026; cv=none; b=SbEvfFvl0kCltsSRljV2bYXIVDXj+NbARQe8PtiyE/cHS3CpMfZzg9jcAYFxYIQ0KEr2XWsZ7nnmk5q6qOBWlhPTfJMwd2NBpxpS0VHqnbR3VIhsDaEddwJmzuAFG4AyG06oEb12hALDippp3hVeBd+V1K5QR9E3Zkbkc8tYknA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106026; c=relaxed/simple; bh=Nl9qYxjXOLsowWrciGmKveA07CHxDugmQszc3tjdG3Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QdsHQq+pIxDSH3CUZ0YZulB/XuTHhoNeA+zBqcXgdi0NfYHuhCtlH7mcfX1Cja2Jd0Z+r28FyK8F0kAYtUvg793CxAf1oSLMJ4PtBbx3n43+/uJwdeIPlU/H0/XpbYsQ72V3n9oeKMiwGqU7OOuT1o+0oXfYPuIqdorKFbkA2XI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WYDsDmcG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WYDsDmcG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 195CFC433C7; Fri, 16 Feb 2024 17:53:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708106025; bh=Nl9qYxjXOLsowWrciGmKveA07CHxDugmQszc3tjdG3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WYDsDmcGRYMtOz94xtttoLsdj4qcVSwBs/M9EXRyOaU14K2StiH+mo5jtU8cmr22F g+BiETG1TwQmVJyKHFEbFdqYVcYwDRLpD7/J7PoAn3tJFpoQDurIjDZYhZ6dyPXcLg ZnYquV5xlv/znIPq8TUrg32FY0QQ9hIJsrvWwnI7QdEbK1ojhvBjUB3n+wh4bY3fFN EMoNGNjjpPh0AjGasS9oP44Au5NoBv7PTMUc6n9xIKYq1OpSAChb0ADMpnY5/oaR3C wa9Dz32U5hf9lYL0wZ37reumk5Yu8y7GXTeUfH4As7702mu5ZqN+fVal6eX13km/+V TaX6MaHMZGZVg== From: Jonathan Cameron To: linux-iio@vger.kernel.org, "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , Heikki Krogerus , Sakari Ailus , Julia Lawall Cc: =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Peter Zijlstra , Jonathan Cameron Subject: [PATCH v3 11/15] iio: adc: ti-ads131e08: Use device_for_each_child_node_scoped() Date: Fri, 16 Feb 2024 17:52:17 +0000 Message-ID: <20240216175221.900565-12-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216175221.900565-1-jic23@kernel.org> References: <20240216175221.900565-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Switching to the _scoped() version removes the need for manual calling of fwnode_handle_put() in the paths where the code exits the loop early. In this case that's all in error paths. Cc: Tomislav Denis Signed-off-by: Jonathan Cameron --- drivers/iio/adc/ti-ads131e08.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/iio/adc/ti-ads131e08.c b/drivers/iio/adc/ti-ads131e08.c index fcfc46254313..f653654f7c5d 100644 --- a/drivers/iio/adc/ti-ads131e08.c +++ b/drivers/iio/adc/ti-ads131e08.c @@ -694,7 +694,6 @@ static int ads131e08_alloc_channels(struct iio_dev *indio_dev) struct ads131e08_channel_config *channel_config; struct device *dev = &st->spi->dev; struct iio_chan_spec *channels; - struct fwnode_handle *node; unsigned int channel, tmp; int num_channels, i, ret; @@ -736,10 +735,10 @@ static int ads131e08_alloc_channels(struct iio_dev *indio_dev) return -ENOMEM; i = 0; - device_for_each_child_node(dev, node) { + device_for_each_child_node_scoped(dev, node) { ret = fwnode_property_read_u32(node, "reg", &channel); if (ret) - goto err_child_out; + return ret; ret = fwnode_property_read_u32(node, "ti,gain", &tmp); if (ret) { @@ -747,7 +746,7 @@ static int ads131e08_alloc_channels(struct iio_dev *indio_dev) } else { ret = ads131e08_pga_gain_to_field_value(st, tmp); if (ret < 0) - goto err_child_out; + return ret; channel_config[i].pga_gain = tmp; } @@ -758,7 +757,7 @@ static int ads131e08_alloc_channels(struct iio_dev *indio_dev) } else { ret = ads131e08_validate_channel_mux(st, tmp); if (ret) - goto err_child_out; + return ret; channel_config[i].mux = tmp; } @@ -784,10 +783,6 @@ static int ads131e08_alloc_channels(struct iio_dev *indio_dev) st->channel_config = channel_config; return 0; - -err_child_out: - fwnode_handle_put(node); - return ret; } static void ads131e08_regulator_disable(void *data) From patchwork Fri Feb 16 17:52:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13560433 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 165C3132C0F; Fri, 16 Feb 2024 17:53:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106032; cv=none; b=bmDfebM8jAhQvvElPVmnN5str9Xnl2Hz97R7W+vzt3XYseEDKpaEA3hr+3GCrzgFJEgAhwcsvacrLjJZGXt+pVmiNnakXmVkpAgqeM4zCJ/lABzrqu0DKH/cCyyWp7Tz4EvoxZhqYZkQiPPc9EZK6S4OvpWM32Z5MhX8r2IyTIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106032; c=relaxed/simple; bh=ifyuF7O6U49FsljCYijSHs8mI+SpSplxdf47Gah2dqE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hKNyMvmDmVO+dPYozl2YHgLFJAJ+tuS9zWHUCvptp3ytNRLCO6Pk5sWRmtpy/00kTf3kvEzIL7SdN6X+K7KxGdgxZfmeGVL8VH+0VntTODQhiYI7gzlqwNxZv4/x4Go8j4BgHXFWxw+wdv6tRDP1bwMQ28L4UezqOtBdonQKwNk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=saT03Gkt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="saT03Gkt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AB4FC43394; Fri, 16 Feb 2024 17:53:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708106031; bh=ifyuF7O6U49FsljCYijSHs8mI+SpSplxdf47Gah2dqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=saT03Gkt2X9XfajdcPKa9TMr1M+Zunpgq9ljpGZ30O6G0zuGeCEHT1ZEnMviJ3EI3 6uaEwKv7VcbUb1T+Eisj18ME3ByBBPWSYZ3Rp9AfIe0L0y3PFTfgb7bvEkyz/TZaP+ CMxvtEziGjW51I0w4ctE3YJwf7jfjM72ezA/w9Iv0IQZ6RRM2ZZgviMKGc3+HTbSwn f2XiZu9F4YBgeCTzeZoznyXzGp+DrXdv0yY+1aZorxHiM1hFW1QQbaqQMBi17BQdre X6VBnSysE5xw8Uut8B4ldbJ3XjjXIZ3spNjFr+EtLN90jcb4/vJ3klMAzMXxdSiYON 8SaN8gOF03A1A== From: Jonathan Cameron To: linux-iio@vger.kernel.org, "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , Heikki Krogerus , Sakari Ailus , Julia Lawall Cc: =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Peter Zijlstra , Jonathan Cameron Subject: [PATCH v3 12/15] iio: addac: ad74413r: Use device_for_each_child_node_scoped() Date: Fri, 16 Feb 2024 17:52:18 +0000 Message-ID: <20240216175221.900565-13-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216175221.900565-1-jic23@kernel.org> References: <20240216175221.900565-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Switching to the _scoped() version removes the need for manual calling of fwnode_handle_put() in the paths where the code exits the loop early. In this case that's all in error paths. The use of fwnode_for_each_available_child_node() here is assumed to have been down to a false assumption that device_for_each_child_node() doesn't check avaialble - so this transition to the scoped device_for_each_child_node_scoped() is equivalent. Cc: Rasmus Villemoes Signed-off-by: Jonathan Cameron --- drivers/iio/addac/ad74413r.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/iio/addac/ad74413r.c b/drivers/iio/addac/ad74413r.c index 7af3e4b8fe3b..cd26a16dc0ff 100644 --- a/drivers/iio/addac/ad74413r.c +++ b/drivers/iio/addac/ad74413r.c @@ -1255,21 +1255,15 @@ static int ad74413r_parse_channel_config(struct iio_dev *indio_dev, static int ad74413r_parse_channel_configs(struct iio_dev *indio_dev) { struct ad74413r_state *st = iio_priv(indio_dev); - struct fwnode_handle *channel_node = NULL; int ret; - fwnode_for_each_available_child_node(dev_fwnode(st->dev), channel_node) { + device_for_each_child_node_scoped(st->dev, channel_node) { ret = ad74413r_parse_channel_config(indio_dev, channel_node); if (ret) - goto put_channel_node; + return ret; } return 0; - -put_channel_node: - fwnode_handle_put(channel_node); - - return ret; } static int ad74413r_setup_channels(struct iio_dev *indio_dev) From patchwork Fri Feb 16 17:52:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13560434 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 254DE1332B6; Fri, 16 Feb 2024 17:53:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106038; cv=none; b=d8siM3lu8W67mUO14oeF/Llvn2PQ1HoXfau6WCfKQjt6G8COpXRZSBU1mDQMAl2PBURt/sIK96oUahS4vGb/qEitbYnSO+7OHNGIFKfvXjY6K90jjSoCyw/AeValU9Hl5sYN7BN3/RS6qKbYk0QFz/ejl2qxxAFb/Xq0GDBqoys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106038; c=relaxed/simple; bh=qJ6hucCm0b/moPq3jjlQ5H1GFMO0uvJDXAqN+WPZ58Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZOZl50XSMGzOgxBjik6GUHSqmo3zNgw+/eWyeCSVfp8IHeS/dql+7Y7ogQU+tYQemAY03u+xJ3EiWHZkNAkYgq4VoeYVUJN/yQEFhwceanSh7yLJZ8Dnk/1xrY5pYDfeevOONStbh3t7gMC0y7QEsWydp0ZoNuPuHn5Ek1VOfDk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HWgg31dk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HWgg31dk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4772EC433F1; Fri, 16 Feb 2024 17:53:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708106038; bh=qJ6hucCm0b/moPq3jjlQ5H1GFMO0uvJDXAqN+WPZ58Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HWgg31dkEMbasvk1jCrt7o9iqjeDTgyY8XbgC51tAPJq1jDCHmm/nA6ruZvz4DjBq 2g9xSRLqoI1uXHeDFxBlo1+JI342BqVwrEfEKXN1WAiULeBh7KDTqsWANyGRQbrdOf iAJd6H8YDTPDzxD5/qxVp9LFz1QXWTkzrsoRzfso6gFe2YyMgAQX/Tu+mCdzqMnPfS k4G/q45c/LEeCTM+M3CEtlkRfLh0pkwYoCnuAreAkEWcxVup3Fl+vkxTnvmC6uFGxt 5FG4AYwNdAXEPwR0u4y6c8Gzuw+dXiBQKcZ8zDpKQ/uEeaO6ZA4t6XhCyU3bWmpqdk cR1wx8jpv+yrQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org, "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , Heikki Krogerus , Sakari Ailus , Julia Lawall Cc: =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Peter Zijlstra , Jonathan Cameron Subject: [PATCH v3 13/15] iio: dac: ad3552r: Use device_for_each_child_node_scoped() Date: Fri, 16 Feb 2024 17:52:19 +0000 Message-ID: <20240216175221.900565-14-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216175221.900565-1-jic23@kernel.org> References: <20240216175221.900565-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Switching to the _scoped() version removes the need for manual calling of fwnode_handle_put() in the paths where the code exits the loop early. In this case that's all in error paths. Removing the goto err; statements also allows more extensive use of dev_err_probe() further simplifying the code. Cc: Mihail Chindris Signed-off-by: Jonathan Cameron --- drivers/iio/dac/ad3552r.c | 51 +++++++++++++++------------------------ 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/drivers/iio/dac/ad3552r.c b/drivers/iio/dac/ad3552r.c index a492e8f2fc0f..e14a065b29ca 100644 --- a/drivers/iio/dac/ad3552r.c +++ b/drivers/iio/dac/ad3552r.c @@ -880,7 +880,6 @@ static void ad3552r_reg_disable(void *reg) static int ad3552r_configure_device(struct ad3552r_desc *dac) { struct device *dev = &dac->spi->dev; - struct fwnode_handle *child; struct regulator *vref; int err, cnt = 0, voltage, delta = 100000; u32 vals[2], val, ch; @@ -949,53 +948,45 @@ static int ad3552r_configure_device(struct ad3552r_desc *dac) return -ENODEV; } - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { err = fwnode_property_read_u32(child, "reg", &ch); - if (err) { - dev_err(dev, "mandatory reg property missing\n"); - goto put_child; - } - if (ch >= AD3552R_NUM_CH) { - dev_err(dev, "reg must be less than %d\n", - AD3552R_NUM_CH); - err = -EINVAL; - goto put_child; - } + if (err) + return dev_err_probe(dev, err, + "mandatory reg property missing\n"); + if (ch >= AD3552R_NUM_CH) + return dev_err_probe(dev, -EINVAL, + "reg must be less than %d\n", + AD3552R_NUM_CH); if (fwnode_property_present(child, "adi,output-range-microvolt")) { err = fwnode_property_read_u32_array(child, "adi,output-range-microvolt", vals, 2); - if (err) { - dev_err(dev, + if (err) + return dev_err_probe(dev, err, "adi,output-range-microvolt property could not be parsed\n"); - goto put_child; - } err = ad3552r_find_range(dac->chip_id, vals); - if (err < 0) { - dev_err(dev, - "Invalid adi,output-range-microvolt value\n"); - goto put_child; - } + if (err < 0) + return dev_err_probe(dev, err, + "Invalid adi,output-range-microvolt value\n"); + val = err; err = ad3552r_set_ch_value(dac, AD3552R_CH_OUTPUT_RANGE_SEL, ch, val); if (err) - goto put_child; + return err; dac->ch_data[ch].range = val; } else if (dac->chip_id == AD3542R_ID) { - dev_err(dev, - "adi,output-range-microvolt is required for ad3542r\n"); - err = -EINVAL; - goto put_child; + return dev_err_probe(dev, -EINVAL, + "adi,output-range-microvolt is required for ad3542r\n"); } else { err = ad3552r_configure_custom_gain(dac, child, ch); if (err) - goto put_child; + return err; } ad3552r_calc_gain_and_offset(dac, ch); @@ -1003,7 +994,7 @@ static int ad3552r_configure_device(struct ad3552r_desc *dac) err = ad3552r_set_ch_value(dac, AD3552R_CH_SELECT, ch, 1); if (err < 0) - goto put_child; + return err; dac->channels[cnt] = AD3552R_CH_DAC(ch); ++cnt; @@ -1021,10 +1012,6 @@ static int ad3552r_configure_device(struct ad3552r_desc *dac) dac->num_ch = cnt; return 0; -put_child: - fwnode_handle_put(child); - - return err; } static int ad3552r_init(struct ad3552r_desc *dac) From patchwork Fri Feb 16 17:52:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13560435 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 AA3791332A7; Fri, 16 Feb 2024 17:54:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106044; cv=none; b=hCt8XBvmk4sxvEPNWBCiCRShf7qP5zNyAy4jkxe9lrc4lyPYDasESKy723cnGJN59NWq/VxJuET8Mov8MWBCboZTWsdXeEQVrcuudCtbrnQvhNGL4dWo+U3QhKkvtAjYPMVjJcBmSvJQIrn6Uy13y7ob7bSWaLPKck01mYAcjKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106044; c=relaxed/simple; bh=35QYOXLq4zAytbJTMQEpTX7uMMdXMhvlvDV0Wbcyp70=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=a8ugUr/8APjhkCxL78vo+e5T0tXmnvj+RzKC+/+cjMbHwqbrKd2xdrXU9ff7Z+y028VCZ/2x1oDKGC25A/ajrDHoV8FkcemTrQQdgOWUp+r4swJ2iZjszOhCE3g177FTwfHOCZdUn7B4LeC8t09J5EEjAgw0Ych+zfluRYJp8HY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XpQ894DB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XpQ894DB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82FDEC43390; Fri, 16 Feb 2024 17:53:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708106044; bh=35QYOXLq4zAytbJTMQEpTX7uMMdXMhvlvDV0Wbcyp70=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XpQ894DBsCMf1HDHgK5xNKJBsFAMRZOJOBNORGN8qFG/ubPmHA0yd+zZIEhrzF/HQ o3R6FhDwPsI11fc+fiFkmRs5saZ0nsZNCpPxhjKYbJTrSYIA1eRJgh7AKzqkXVO8zY Wklq18PgYNkBofJZERy9sHbz2Lv94Y2PHp2b40nV3rAcs64bxDFcRZ5E5ukXNplUYv YcCiPylOMuM45uzv9Z4SNNANsUYWjNo9V6pyXaaLhIEWWt7vDAln0j0Mbw0ya0lw6j r0ic3dbd+pCMl++zmiBco2wog1T8MzVvbyoDFQLGtoTzU1GV09JhkUhJdOHroQJDOX +os8eRz2mFptg== From: Jonathan Cameron To: linux-iio@vger.kernel.org, "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , Heikki Krogerus , Sakari Ailus , Julia Lawall Cc: =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Peter Zijlstra , Jonathan Cameron Subject: [PATCH v3 14/15] iio: dac: ad5770r: Use device_for_each_child_node_scoped() Date: Fri, 16 Feb 2024 17:52:20 +0000 Message-ID: <20240216175221.900565-15-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216175221.900565-1-jic23@kernel.org> References: <20240216175221.900565-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Switching to the _scoped() version removes the need for manual calling of fwnode_handle_put() in the paths where the code exits the loop early. In this case that's all in error paths. Cc: Nuno Sá Signed-off-by: Jonathan Cameron --- drivers/iio/dac/ad5770r.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/drivers/iio/dac/ad5770r.c b/drivers/iio/dac/ad5770r.c index f66d67402e43..c360ebf5297a 100644 --- a/drivers/iio/dac/ad5770r.c +++ b/drivers/iio/dac/ad5770r.c @@ -515,39 +515,32 @@ static int ad5770r_channel_config(struct ad5770r_state *st) { int ret, tmp[2], min, max; unsigned int num; - struct fwnode_handle *child; num = device_get_child_node_count(&st->spi->dev); if (num != AD5770R_MAX_CHANNELS) return -EINVAL; - device_for_each_child_node(&st->spi->dev, child) { + device_for_each_child_node_scoped(&st->spi->dev, child) { ret = fwnode_property_read_u32(child, "reg", &num); if (ret) - goto err_child_out; - if (num >= AD5770R_MAX_CHANNELS) { - ret = -EINVAL; - goto err_child_out; - } + return ret; + if (num >= AD5770R_MAX_CHANNELS) + return -EINVAL; ret = fwnode_property_read_u32_array(child, "adi,range-microamp", tmp, 2); if (ret) - goto err_child_out; + return ret; min = tmp[0] / 1000; max = tmp[1] / 1000; ret = ad5770r_store_output_range(st, min, max, num); if (ret) - goto err_child_out; + return ret; } return 0; - -err_child_out: - fwnode_handle_put(child); - return ret; } static int ad5770r_init(struct ad5770r_state *st) From patchwork Fri Feb 16 17:52:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13560436 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 4CDFA13174F; Fri, 16 Feb 2024 17:54:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106053; cv=none; b=eEdT2cXRQwDJWF8BZWtgcJlDR6Qo6h4GG6b6q2GFTuRSGBd/Pm56vntj0fouCvKd2FAr4IgraPmMt0w/g/8cR4tiwd1PPvNTpCyUfBWKI7uQ47GokNEwhfEmR3NUkUr3Kb0ClBXbwuwgvber2sB6A0HCpQeXzSWTg/NDrO+Y2OM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708106053; c=relaxed/simple; bh=EfkH807/eaVFKqbyI8JzEQiNG2vd/Mt7Rvy6pBl8J9Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LxFIBq+wy9GDvEuE9C6DTnQbpcbnSMamdrFzBuPUEslYAzfqoL9Eo1G6Kas5TjL1Pm6Ya8gzMmDUxW7+o/sQuWQUq/JNt+gInkG9ZYqDacdKZ0f09NIXumT97yLXY2XVs8B6Uys7K8SiV2zWqBxMCNNuImxSpG97reUMHMgH2c4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n1F1pqyj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="n1F1pqyj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF279C433F1; Fri, 16 Feb 2024 17:54:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708106051; bh=EfkH807/eaVFKqbyI8JzEQiNG2vd/Mt7Rvy6pBl8J9Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n1F1pqyj2NnDZagKQprFkPm8Q65Zvzq5YleuPNecSjUsBZw+LAQYGm8dBtt7ty6DV Etbu8gcq9V6zgxEs3xlWL7mRa+8guhwVh8e/jcrtT3zlNmRLfWvrYKq+9wqkNtSwBf 5sITLqmyleOj+GgQwhW7JJGFQhoiJl4a5CGc4hxXIYj2Pi7ZWvQ+F3W18OMozTkSZ4 cHPUeM/r1MWOgnPsdqWsBAt+RZsYsnKBvnBBH23ObozETjLQVtdBtO5Pie04gSIrz1 ZGKNqmXZGOo5AJIsQ4Lhvy33282mDlHGSevc3pQNLy6Q1hRS4iVbw2dJrn8AiHwuW5 W1k04qHC+oZrQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org, "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, Andy Shevchenko , Greg Kroah-Hartman , Daniel Scally , Heikki Krogerus , Sakari Ailus , Julia Lawall Cc: =?utf-8?q?Nuno_S=C3=A1?= , Cosmin Tanislav , Mihail Chindris , Rasmus Villemoes , Tomislav Denis , Marek Vasut , Olivier Moysan , Fabrice Gasnier , Lad Prabhakar , Dmitry Baryshkov , Marijn Suijten , Marius Cristea , Ibrahim Tilki , Peter Zijlstra , Jonathan Cameron Subject: [PATCH v3 15/15] iio: dac: ltc2688: Use device_for_each_child_node_scoped() Date: Fri, 16 Feb 2024 17:52:21 +0000 Message-ID: <20240216175221.900565-16-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240216175221.900565-1-jic23@kernel.org> References: <20240216175221.900565-1-jic23@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Jonathan Cameron Switching to the _scoped() version removes the need for manual calling of fwnode_handle_put() in the paths where the code exits the loop early. In this case that's all in error paths. Cc: Nuno Sá Reviewed-by: Andy Shevchenko Signed-off-by: Jonathan Cameron --- v2: Tweaked the alignment after comments from Andy. --- drivers/iio/dac/ltc2688.c | 24 ++++++------------------ include/linux/property.h | 6 +++--- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/drivers/iio/dac/ltc2688.c b/drivers/iio/dac/ltc2688.c index fc8eb53c65be..b71df03fc13b 100644 --- a/drivers/iio/dac/ltc2688.c +++ b/drivers/iio/dac/ltc2688.c @@ -746,26 +746,21 @@ static int ltc2688_span_lookup(const struct ltc2688_state *st, int min, int max) static int ltc2688_channel_config(struct ltc2688_state *st) { struct device *dev = &st->spi->dev; - struct fwnode_handle *child; u32 reg, clk_input, val, tmp[2]; int ret, span; - device_for_each_child_node(dev, child) { + device_for_each_child_node_scoped(dev, child) { struct ltc2688_chan *chan; ret = fwnode_property_read_u32(child, "reg", ®); - if (ret) { - fwnode_handle_put(child); + if (ret) return dev_err_probe(dev, ret, "Failed to get reg property\n"); - } - if (reg >= LTC2688_DAC_CHANNELS) { - fwnode_handle_put(child); + if (reg >= LTC2688_DAC_CHANNELS) return dev_err_probe(dev, -EINVAL, "reg bigger than: %d\n", LTC2688_DAC_CHANNELS); - } val = 0; chan = &st->channels[reg]; @@ -786,12 +781,10 @@ static int ltc2688_channel_config(struct ltc2688_state *st) if (!ret) { span = ltc2688_span_lookup(st, (int)tmp[0] / 1000, tmp[1] / 1000); - if (span < 0) { - fwnode_handle_put(child); + if (span < 0) return dev_err_probe(dev, -EINVAL, "output range not valid:[%d %d]\n", tmp[0], tmp[1]); - } val |= FIELD_PREP(LTC2688_CH_SPAN_MSK, span); } @@ -800,17 +793,14 @@ static int ltc2688_channel_config(struct ltc2688_state *st) &clk_input); if (!ret) { if (clk_input >= LTC2688_CH_TGP_MAX) { - fwnode_handle_put(child); return dev_err_probe(dev, -EINVAL, "toggle-dither-input inv value(%d)\n", clk_input); } ret = ltc2688_tgp_clk_setup(st, chan, child, clk_input); - if (ret) { - fwnode_handle_put(child); + if (ret) return ret; - } /* * 0 means software toggle which is the default mode. @@ -844,11 +834,9 @@ static int ltc2688_channel_config(struct ltc2688_state *st) ret = regmap_write(st->regmap, LTC2688_CMD_CH_SETTING(reg), val); - if (ret) { - fwnode_handle_put(child); + if (ret) return dev_err_probe(dev, -EINVAL, "failed to set chan settings\n"); - } } return 0; diff --git a/include/linux/property.h b/include/linux/property.h index 421ccfd43fb1..4d3fc4edabbc 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -183,9 +183,9 @@ struct fwnode_handle *device_get_next_child_node(const struct device *dev, child = device_get_next_child_node(dev, child)) #define device_for_each_child_node_scoped(dev, child)\ - for (struct fwnode_handle *child __free(fwnode_handle) = \ - device_get_next_child_node(dev, NULL); child; \ - child = device_get_next_child_node(dev, child)) + for (struct fwnode_handle *child __free(fwnode_handle) = \ + device_get_next_child_node(dev, NULL); \ + child; child = device_get_next_child_node(dev, child)) struct fwnode_handle *fwnode_get_named_child_node(const struct fwnode_handle *fwnode, const char *childname);