From patchwork Sat Feb 17 16:42:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 773961 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 697FD1CD1F; Sat, 17 Feb 2024 16:43:12 +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=1708188192; cv=none; b=j0Bg/nZeAFs3ZPrmQGM8BBKYebpW2fVrqBzUHpbhhlX1UI1DfWRJaoupVST7V4LsYQtMJgzcF5B6kbjT0JBr7gq2E3BJ4gcv7ZSWWqw2GpqB5gRmpRr0JQ5Z4t2vC+WpKSoMMvHO+sLT5YX8kED458TP54c8GOErZCRZFWXUSLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708188192; c=relaxed/simple; bh=ocjL6LwQJYb/J/bnzmlHaMaUJjymU749SiDawf6541M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cuXcaTOi+GIE1lFV43+JqoARX7O1IaH/+bqa/h1olW7NWfH9POVsQl93bp2VPe4UIMCapShPR5GvDX8d289QlilhWztcyeEZ95/2LxBG4cVhlDr8c2CeVBlrPLbzl/qcO0kFzi8hkw2K/cP3o5CmgsDaYiM+9ovJgW7J0P71p98= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Io8Y9oAH; 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="Io8Y9oAH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0C0AC433C7; Sat, 17 Feb 2024 16:43:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708188191; bh=ocjL6LwQJYb/J/bnzmlHaMaUJjymU749SiDawf6541M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Io8Y9oAHV1bEALJQMpytnSR6TCz9ymDbaiCGIgKauOJYMKEc4/4lkSG6pdbk7SV1k LUXP8AY7ctgcKTrwCHm/QS9CC7piGmlZdyhVjZ0ZS7DbyOnbObI5wRabCcqAYQNME/ 45at0ZqZ6OGYYg3/YCea4AdjM5rsUHU6gD66Wdp18t7y3eZVjaSth1T/S5zZkeJs4z NVDFf2gX0PdY/HqJRNSBGplZwmDLKNzliC2O6fX321x9/DDOV738DesOX5d7SCddWn 8E5l3YOQqm46989nt55+XYs6YSxDCNyKEFnswabw1RcfTcnOqaNvtI3J/lub0PnSbY DP+OfraH8ZDcA== 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 v4 01/15] device property: Move fwnode_handle_put() into property.h Date: Sat, 17 Feb 2024 16:42:35 +0000 Message-ID: <20240217164249.921878-2-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217164249.921878-1-jic23@kernel.org> References: <20240217164249.921878-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 optmize 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 Acked-by: Greg Kroah-Hartman Reviewed-by: Sakari Ailus --- 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 Sat Feb 17 16:42:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 773769 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 BF6121CD1F; Sat, 17 Feb 2024 16:43:17 +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=1708188197; cv=none; b=DnfU9KFQvDU3+QM8tn7/NRWpiy5dAsUMoJdRWnsGSSiqzcYUwba0zbxj+D+WXKuqQznj4AiIr03wTgdKDRkivhD837bXE6NQsp6q6Ide1q1v6jZs/9nEPA4gCxerFL8++pt33SqsenSL2hJjDZyOblFxfy+QYuH/w816UTNd45E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708188197; c=relaxed/simple; bh=ooH3tVQ8RhEdYrJS+Vd+dsFlhzvCEObmeWM2dC5oN6E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HGBJfgNygHx8+NfaJ2NUW4+o+4qdXhGu31VVPs9lEHraLotVJm/sctiZpwz7P3BBtL9hOBseoynKZCuV+8fc469WGcIETtKpiXfNh1uvx/4V1zuSPIqeXqUKt36uRzGeM/LZ8RRSpmaJjW+oEoU2VM+KLPnKHtz/6IUZZukiR/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uSY94x0X; 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="uSY94x0X" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A2AAC43390; Sat, 17 Feb 2024 16:43:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708188197; bh=ooH3tVQ8RhEdYrJS+Vd+dsFlhzvCEObmeWM2dC5oN6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uSY94x0XaOQQtXNPAGaCbycdnINGUhe2kjmUcsffUkuLQXn6xGcGsVr5ba8jL3B8o GVPTNMJGWQU/CE8y05qC+0whpQkNclHXH919zD1UdNf4D9IjrpyDAz4ej8g8ubdEXX fbZmjXbxiTaUjLQdE4bKieW4mtvye6fez2iNCFI6SdokrC1oEBH9Y2J4TfIZmQze3D cKpu/VMrafWDjjRWH8dOOVAcG/wgs+gCbAvitEaYZ11Ky0XXzRzVfdYJ9vPVWSp5GU vm4vWTnG8RPacRiW3I0wN+ynz2SZ4e1SfnhTCEuahsg8+U7IyzPzaeoj6WoEJKMwyt J7SSbayjypevA== 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 v4 02/15] device property: Add cleanup.h based fwnode_handle_put() scope based cleanup. Date: Sat, 17 Feb 2024 16:42:36 +0000 Message-ID: <20240217164249.921878-3-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217164249.921878-1-jic23@kernel.org> References: <20240217164249.921878-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 Acked-by: Greg Kroah-Hartman Reviewed-by: Sakari Ailus --- 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 Sat Feb 17 16:42:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 773960 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 99E361CD1F; Sat, 17 Feb 2024 16:43:24 +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=1708188204; cv=none; b=rnABm05fQo+SSmFbJVrzFxppeHrHxuQZpcYWrhPGqQGl+MkawWAI+Fvc/HUesBfGL+W8U2DlYJjTJ+SykPgYWnL49aJ5TlIYnN683hIDv98HCciyM7lgKIe/z8eG0b/Y6Gy4C2HEod7chw0J00jOx45FgWZC9VqT+Hd9s2FXlvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708188204; c=relaxed/simple; bh=u/kM9IeeMz28QJo6vL+8ec8i5DgcI3ZL6tvQUDPE70k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eqw8sQhoYvoDQxWrA+1p659nMCt+f+WaVNFFBcG2m5gqgVXckbghqOHroOx64xKXuWB+7kL4Ml28YnDq6hUJ8++ZA4MUlS0qiRJZfJiEd0Qx+L9GJvz45MRt+bLPfU/mLrcCf2Xg0wGCT/yclw9/JMO+6LZexrdT75qN9l5and4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UKlIqImO; 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="UKlIqImO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE690C43394; Sat, 17 Feb 2024 16:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708188204; bh=u/kM9IeeMz28QJo6vL+8ec8i5DgcI3ZL6tvQUDPE70k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UKlIqImOii84D6o4P2Yqf48xlew6qY1E7fk64GA6gtyGg1LEg9Ra1jQ6ygXhiJdt1 Cj2VD+30gYKT8ChAkakW/b6o8i5zTdaq5Hn+pwI6ZL8GBjkUpQAZsRHrCP8/2Jlf+8 5qW1+knVoJId0M+siCkbh1YA5nJepJab3mFY9CgbvhOZeYajb5fRVSLazDjxreFnAE kwOsHT7OFFJbCsZDKUsamG7bHjWg0Y9kBaifLH+ToCb5aI/UuPPND8v9pX8FBR6oTX 5A9AgdOT/O3acuwHaJyDYsnzJbx6AfkAWoCpufliA+0y2WNaXJaImKr737G79Mh33y 60LxJZMFtd62A== 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 v4 03/15] iio: temp: ltc2983: Use __free(fwnode_handle) to replace fwnode_handle_put() calls Date: Sat, 17 Feb 2024 16:42:37 +0000 Message-ID: <20240217164249.921878-4-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217164249.921878-1-jic23@kernel.org> References: <20240217164249.921878-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 Sat Feb 17 16:42:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 773768 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 9519F1CD1F; Sat, 17 Feb 2024 16:43:30 +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=1708188210; cv=none; b=UxJax9vSOzFW79nGbbXrZFsccHgtHMIzNEY9maaxTNEIqLEL1cvmYkDfTTCC8QG5tFvws5EZKh06f+N56Z280kx9j4wy9RbqNHzgVCpvMcS9mRDzmOC+bgHYRZ5R0iyCXWsG1As/669pz3pS3eLVpSxZteY9rN1w6c/DUdq329o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708188210; c=relaxed/simple; bh=ftsl0GWv7l+uVhUJMImD4iqguDNAhLTZlsSgDMYqxPw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PaTOoOHraxFtaSTvfgavubYl35wm6K1j6I8HbPnxjRZEh6aLzGSmc0U9XiSL8IdXbSus0QcPDhfdEXRinSVbwMyxQu2C8ZrGj/Ncy4Cg9Y4YpJPfaQUWRv4tb/Rh09CDgdduw6tqPainrlo1FVYZzoAPdSEe+zu+MSSdb9NlCE8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eLP6zvCy; 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="eLP6zvCy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87C2DC433C7; Sat, 17 Feb 2024 16:43:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708188210; bh=ftsl0GWv7l+uVhUJMImD4iqguDNAhLTZlsSgDMYqxPw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eLP6zvCytfjLOb5dLWYtLb/xpGpI7Bybyho0KzH2BGb3A3vFWphNxdIHDHlyU7/dl AFx3Ld146rZmJgMa7Qod66QZmybwEhuUtA4rWo649KrwCE4v1Jih/hhyLlvzBpS+8G YIEFRofHPrxwWWuPKr3bQ/MGfKVHshBnb8Zn+4xPMMXyeMjR+KERdysgm0SuF1dggB PKtcsHVn9IH8yrVcWOxtINLLSHwkY3MjD9/dsAsEYq0b7loK1AkNXrHcTaIEDrqIR+ O7lvclSv9wYYoljm3SbIPJj4FOYfn/e276vnIZKCelJhKUJwm4YcSCZ3LJGXfDi5An HIWJ6/ZQW69qg== 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 v4 04/15] device property: Introduce device_for_each_child_node_scoped() Date: Sat, 17 Feb 2024 16:42:38 +0000 Message-ID: <20240217164249.921878-5-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217164249.921878-1-jic23@kernel.org> References: <20240217164249.921878-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 Acked-by: Greg Kroah-Hartman Reviewed-by: Sakari Ailus --- v4: Include the alignement changes that were in patch 15 of v3 with a tweak as I missed the first line. Thanks Andy! include/linux/property.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/property.h b/include/linux/property.h index 9e67c3c4df6e..eefd662a2f9d 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 Sat Feb 17 16:42:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 773959 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 5DD8C1CD1F; Sat, 17 Feb 2024 16:43:36 +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=1708188216; cv=none; b=qZXQHEQheRZKpOdWhmtKJAqIbFHhcOm+eCjsTNnXtRdUSJtCMn7T8+SGmsKbZKqGsnuyPr4W2AA10uq+HeZmwLGV4cJEN6tamKjB5mctEUdpmHAm+J0Vm2RgSvg4hKfOOXLAb3W/tLjiBaTZ0r6vDB/AMKxwg1MzgMnn9NzSDwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708188216; c=relaxed/simple; bh=iojKGFHS6Uwh1iJBxwwefEnfrUPfJjcrCNVF0odaKFQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ryjn1IlonIs4SMklPJSTijMkPvSVg+1ZfWYWMJDey+KssKQ5jz1JDk1HAXIPXNCuqNJOaWK6xcCYRrOh661aNLK+7UOJmelMyXnnpkt9aPuC/rmklA7m2ipOtujHMta4/x3kzC6+ySe5To1757l2np2pfgjlNFMIXU+NIWTESrc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ng3Jz6dI; 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="ng3Jz6dI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94AACC43399; Sat, 17 Feb 2024 16:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708188216; bh=iojKGFHS6Uwh1iJBxwwefEnfrUPfJjcrCNVF0odaKFQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ng3Jz6dIOng6XO1FBtPiLw1al7zpWtmbwP9mi7PuVWxYwGZniPCFluybCZGURoiyA w8DtbnlHMAYQPjA85slJiVvgotT4iK6MgKLj6efYs4UbmwusDoovvCUVTyUBPwAKzq 7m0ddebd38ZtyjfpcadMDaJoyxvd52FyWeEKnMJ4b4wyehOIBa1gRktu6xM95ah+QN 2ib43+ekDcA5uRAB8el03hwtyI43V9GfbV+b4eX7wVPwyZxKrVCOOoZ2z8XnxLLn4t xfJYu9GpgOBx6frOjAiUWCBrqLpHC/TJ1d0Hf1ZBqLmgrEFoSximiQL9V86rFM0qGk PECqPlfI+j43A== 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 v4 05/15] iio: adc: max11410: Use device_for_each_child_node_scoped() Date: Sat, 17 Feb 2024 16:42:39 +0000 Message-ID: <20240217164249.921878-6-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217164249.921878-1-jic23@kernel.org> References: <20240217164249.921878-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 Reviewed-by: Nuno Sa --- 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 Sat Feb 17 16:42:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 773767 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 10A4B1CD1F; Sat, 17 Feb 2024 16:43:42 +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=1708188222; cv=none; b=rU/Gpl99CBgKq8mIBab5+jC8xmhXXctc7uE5ob8M9RUOb61X4SecsBpZBywqp/yoEQhpSoCNNfXPJLos6VmV6hmwIk0WwxZh8mAfvDrqpa0Ic1DS10H/Kp0YyK709NPDm9oYKMEwEG9gTpiSsaGCQWrZ9A9T8PSgPRJskBRiNLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708188222; c=relaxed/simple; bh=aVEHVNZLRW+7hOZXFm1bFqSgnqdVSQ6FtHIyAf/1FKo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kq8jBGZTLzNMKWnRBHsJ8GzU9ANv10CwRLheiORoiP0onZdI0y9n+uKsEUNP4b/4dQwmuZkfCKLFHqxHdlRNQLg2Yet/PE1yD9HamcCvzwRYicu6+iWjEu9qQpghV1NpvmkqbJFH0A0vxNQoJvYnTk3l1jUbrTtYvQmIWL5wjUg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KZj0BnmG; 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="KZj0BnmG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8627EC433F1; Sat, 17 Feb 2024 16:43:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708188221; bh=aVEHVNZLRW+7hOZXFm1bFqSgnqdVSQ6FtHIyAf/1FKo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KZj0BnmGL2G6nZrNf6fB/W/AjEKuMj9Lt6bQYTVbQUm6r1Sp+WLqDHOR7dsLp9sX3 GBOC+KgPuc2CcDH2h8Voaf3VvK6+7/8N02xgRrLZdlCwd12QLSGVSCwOHKetzQKFX7 5V0TccoqbAfY4pJ7B6V4lE3yTby9Xyg3UONCqIsrlAnDnq+szsngyB9rLPOeHyX/Kc 0lFy5aN9ZxK+QZLXxKEDf+Mbf96cwv8htMula2P8DlD3rqg5fUAogqTDkms+Sj4T9w cNEfofUmKuyKlZTPdJa7OVEBts5ilg7FcF7EZp4uhNAOeYWk+xiGBqPx3scpYKI45M +homzZ+uaEAKA== 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 v4 06/15] iio: adc: mcp3564: Use device_for_each_child_node_scoped() Date: Sat, 17 Feb 2024 16:42:40 +0000 Message-ID: <20240217164249.921878-7-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217164249.921878-1-jic23@kernel.org> References: <20240217164249.921878-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 Sat Feb 17 16:42:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 773958 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 26F597CF3F; Sat, 17 Feb 2024 16:43:48 +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=1708188228; cv=none; b=f/Q22ys9utaXm5VbqDntNFxog/M/m+ymS5O/4LeGtLqmfEDboqSeXDN1cGuJYkJVL1GTf3qicv13uccyj7xRzljF7+qlgkJJ5ePnRmiXbGptqDF5Bte2iBAEXSvOBsmB3oeWovbCN7RYm6Wiq2taMrGkXk05jJXORcydZooXX4A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708188228; c=relaxed/simple; bh=2mqddr2vk1tIUyCyEYFgQRTgvjJnligNLqFwI5ekcbQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JNtZ3pAQ+rXUAwDM8mU5SLCc2CEzCnZsAJrkwtDndI5N3XxhH1slgPsPleKG9uN+5dRFgmE0EUlz2qTXUx2JROirK6t0d9yoqB1sGnwjQWFSnNg8lFAH3kIQ3PQylq4l3c2tBY4+kKEBLVf0qTJbLNQS/upmJerjgJTdx7EAXNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Zn7z+Gsm; 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="Zn7z+Gsm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77295C43390; Sat, 17 Feb 2024 16:43:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708188228; bh=2mqddr2vk1tIUyCyEYFgQRTgvjJnligNLqFwI5ekcbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zn7z+Gsm26wo1s4HpGolYGv8RCewXgYaxaMT7EGxngx3lm7UfGI0XuqS7SNrYpSBO 9p7jKMWuU2HCuILA2V+9/YNkSZFqhdC6zZnVwaUOK6ebLafFiRqDLVsWc7+ufAVUjk Nb/PfduUU2jpBF70DDr5ilPZiPxWc+WrpbFOHUN8Sk8CwLSKhaJ1NoMbiIsT2dMLB8 wOnWGSM4+rfTY6WIlrzYDPZAsyvXxixu5ERccC10YRO5wub/ZTEho1GyT1We5Ihxhd glldlNEVV5Pl4SVlE1/moFmMy/vpcSmbG2orFX2d6vRu4YWWMN/ExpBzo5+7Q6gKNg ucM8dXZYozp8Q== 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 v4 07/15] iio: adc: qcom-spmi-adc5: Use device_for_each_child_node_scoped() Date: Sat, 17 Feb 2024 16:42:41 +0000 Message-ID: <20240217164249.921878-8-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217164249.921878-1-jic23@kernel.org> References: <20240217164249.921878-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 Sat Feb 17 16:42:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 773766 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 5E0CE1CD1F; Sat, 17 Feb 2024 16:43:55 +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=1708188235; cv=none; b=dsUKBRTw6vBfNulz0SNUdGiFjNVzxZ9j1AMLOe6XxSpRATUDraTd+LR2A0Udja5ULUV9xi8Z+c7rWkhZGIqsaAXwI0QIDnyqkUPmYR32FObp9uXUoX+kYya3WgpZeU3Cx1HRuLC8Y/utoitZALwU0+RSq2WgwrVlDG494fpSEDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708188235; c=relaxed/simple; bh=QrHoWfZbRHMq4P70zGYxGeka18F/ERWgdcsa9lr19q4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=id0W8T1r89UkdTG3zFatiDaajbAZu7GUVnuhnmhP6nNtZ89ytg0mHobLCAPeo/e3H9W46dFgSn6R1l+1f461a6hucBNnfPU2xDL3m2oxn6MryogegUzDBianrgG7xS5Okb9dadgArbok8U7e8k07om1UafCxpGsIXSu38s8bBUg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KviDyznt; 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="KviDyznt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80CAAC433C7; Sat, 17 Feb 2024 16:43:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708188235; bh=QrHoWfZbRHMq4P70zGYxGeka18F/ERWgdcsa9lr19q4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KviDyzntTMWqfml6AyUnyUImc/FFb8emara+J8z5R45nk5lZBbQMTpOYND+6Sy+lo 9EpVBKpy3/RZ4JcR72Kml1Li365Ny/qACqfcfKkAKDeFt3EyKncfVsq/zCRn3Fw8eW GP9tjE2YoWWROkFBKZIp3j9BFMpD4+HJP7jdl3NZwjleccowCWpbB7IH4RFO9jcbWh aRKGBFQXRdyTy0FJeQcitkNPehrJOHqLBItzfVn15VrvrAd+7AZ5Kdmsu66zc0Av9q BHA9BOGkyT3XuuLzbf/3KxKN8y/7euxZnVj+Sqr0n5iZGg1RqBT55+kXsfEapU5OBl C1ahWFtLd1N5g== 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 v4 08/15] iio: adc: rzg2l_adc: Use device_for_each_child_node_scoped() Date: Sat, 17 Feb 2024 16:42:42 +0000 Message-ID: <20240217164249.921878-9-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217164249.921878-1-jic23@kernel.org> References: <20240217164249.921878-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 Sat Feb 17 16:42:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 773957 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 019C71CD1F; Sat, 17 Feb 2024 16:44:00 +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=1708188241; cv=none; b=ICG6rQTNIQxlqZRhymLt/jv2Wwevrd/D5A/bKfGRKooV/1Tuu9+GyfajUKjr4zK0ZlGiSl80UnD3lu5HW/3z7WDzXWX/KMTuJGlBpV3MB0Y+1SFXxDEGFmGElU/ACa1f6u+OhTVlOdu92JZ1m51j2XNrk3CpChxDntgKiHZzbsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708188241; c=relaxed/simple; bh=L/DROO4YPVYunSdXLSEqe6Sr2aGPuWHRhNS+WcDI2Ik=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qb4Z/Ris9eQjn+0o/1Tz7IjAR8kvwFrhbKcUyBlB5cjfDAIKoRB8PBtUH09eyO58ol33mwRqSFvrioj/qiA698SzXO0rn6ZfGSB+IQXU1rsIc8+uezn+yJOqi6OyeinWX+/LPDW8neSxT791wquMK8EWaMC8RMmAukqt3nlfVPs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=isWrmeZI; 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="isWrmeZI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C33FCC43399; Sat, 17 Feb 2024 16:43:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708188240; bh=L/DROO4YPVYunSdXLSEqe6Sr2aGPuWHRhNS+WcDI2Ik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=isWrmeZIpq3u4jOz7xYvi0NesDe8CUklbppGCJP2NdNLETfkBjQnVWfrMDZOrC6Pz ejhDkG/wRzQHc0DSNSN280bA9fXYS/XSfgYIC2QrV7YJllygRLOHgrdFZEACJ1HHSl ZbPzxFxVN3+/0mmnR1UcLg6WYmmyGSI/S56YE+k6PUP7pCZO8uy97GfmJ87bGau6x8 EhHM318sgLgpkaCNi1wMiVAcqkMCDu1KisXBtcpF0pOD18BOzW8JMvnQTVz+OePDya HaJesrHpcQfXJA6IL7sJW1vgR685hF9Xiw8JQYnHqp6oa3mfeITbFGqCelAze3VL4p D35xnNzmxkj+Q== 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 v4 09/15] iio: adc: stm32: Use device_for_each_child_node_scoped() Date: Sat, 17 Feb 2024 16:42:43 +0000 Message-ID: <20240217164249.921878-10-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217164249.921878-1-jic23@kernel.org> References: <20240217164249.921878-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 Sat Feb 17 16:42:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 773765 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 ED4DF7D3EC; Sat, 17 Feb 2024 16:44:06 +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=1708188247; cv=none; b=j7dR8RIZI+eCIDqlOwOftzZC8G0R2rG/mj/DUzdCrfwFJTTYABn0jfbpTNiOsSRVIbkiJiidrfxAZWcZxgfQAVcpVnQl/zGp7a5pda/G3EXwn8Ab5FSbuD9+eGzxtvgURZdNQ0y5by8dy16SwC3yxZl2iWaONEd7z4WQrsP3GdY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708188247; c=relaxed/simple; bh=Ds74Qrbcn3I42aYg16TeBAqLINL89sm7BvmJAC5S5nc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ncHJ1dz/g5WcYndEPqD8uPgYQNZHa9rnWQEKmnR2fv6glg826GdJub22CnlZWd7g9cH+1EU+7vpewBk2FHa4JaJ5Ajh0WEDmoAzJbK4Nu2CEkWz/vSeJDnP4OkWSLDEk7n/BEWYRvPv+qez7lDulaU3Uvr3ithecf4l6E/jTy4M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mhZrY0Yp; 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="mhZrY0Yp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 505A9C433F1; Sat, 17 Feb 2024 16:44:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708188246; bh=Ds74Qrbcn3I42aYg16TeBAqLINL89sm7BvmJAC5S5nc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mhZrY0YphxOePIFolDO2R/9Qr7oV6yp/hdN5OLaYrG/aMQLYdWuENssQlLQ+ejzQd Sjg3xRN1IZU1RFmqKleX/YfDBYBXqeoqguWxEwDARMFGKUa6MqG6PTYtmarfCDEG73 ZKc6qNJ7rpL3lqp5u65OjgbFFJhk07lOH89GvZdkFfigbFsuheuZfvNSa/N5hC17WT P0uuDjy9IEtLArQQI14kvpXeHglHmg94kVEyAwU420bScq6agqYN3tUnwScwEYuF7e oaIPB4vnEGr18pgIrfLCtEmSYTCpNBUHBNv2oLX1/KBGVa9KOsj2z2dnr6xjiQiAWc fipNvri1SBFcA== 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 v4 10/15] iio: adc: ti-ads1015: Use device_for_each_child_node_scoped() Date: Sat, 17 Feb 2024 16:42:44 +0000 Message-ID: <20240217164249.921878-11-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217164249.921878-1-jic23@kernel.org> References: <20240217164249.921878-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 Sat Feb 17 16:42:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 773956 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 C773F7D402; Sat, 17 Feb 2024 16:44:12 +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=1708188252; cv=none; b=Q4Hz2RvVAyyvqZL226tCUxVtXg7bRxUCqN+9q5fHy+3lMArcX6KdYTq8aD0k5e8M5MlZvr9b/SBIFmBtGUUYIaYM/ELwesgYP+LHUGMIknUPoKBK1jef/7T/e6mpNlAh+MPaty2M/o4EZyXBLPgqHlXYhQL296GTRnqUMdfprCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708188252; c=relaxed/simple; bh=Nl9qYxjXOLsowWrciGmKveA07CHxDugmQszc3tjdG3Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lzE4P8vo3wg52c7viy7ZwVxgc8j48dUMsd84aiwiN5JbkRFuxWrr8kfcVisSm0lyI01Wy/eEbtI6+y/yW/TJvscio/u3hg7jdoCmKbAbghi3k7RHy65Sh0tueGBov57lw2xGxmBy3S9pUituEs1OBcaYSifcBDOYE+blcC4AZtw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AYctr/8o; 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="AYctr/8o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D16F7C43399; Sat, 17 Feb 2024 16:44:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708188251; bh=Nl9qYxjXOLsowWrciGmKveA07CHxDugmQszc3tjdG3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AYctr/8oA3qLGO8TJuzzwXVBOvh2W6MzSttM4W1awpEuemzgZ0RhhxXA43RTFoghl L0tkNSYRvLcuBm7OyNpU95blNJZegPqvHunoLkg7qlzV7pvviBTY1zlXx96di4SM8T 83zjUIbj+wZrKxCDJudtmFaM+g5zVIvkRCMtIEQ2gbfXlSjTZveZnMPkqrL4XQmZTr NleA2Un/MgSV/+SdZn4b2vL3KlfKZkjh/jQL+zDh5+HI47yWOZt4Kp5uK+Ebb9uQtG HKiBPW7QvI0Ekf7BZqN0u9Dei0qM+azKEV73vClKeIq9tA4YOkZ8vCr9AqnmQj1JuR +dEQJzJUrH51g== 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 v4 11/15] iio: adc: ti-ads131e08: Use device_for_each_child_node_scoped() Date: Sat, 17 Feb 2024 16:42:45 +0000 Message-ID: <20240217164249.921878-12-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217164249.921878-1-jic23@kernel.org> References: <20240217164249.921878-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 Sat Feb 17 16:42:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 773764 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 1B17E7D3FA; Sat, 17 Feb 2024 16:44:17 +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=1708188258; cv=none; b=oDiTpET2qpmEIBfzNPaGPBIOVV6Okw+p14EHH7xuXxL+tD7CMyNyjldfD2IgKuHhcY/uM2rjxlkFm3z8EYEHXRwWBjmsvkbaZF4RuWNml/Sz98AKVbfYxmlzmE8XBh/F2A+HROJ77olPcDnoLpHKEe5hQw+GaEPW+x/Y87QM87g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708188258; c=relaxed/simple; bh=ifyuF7O6U49FsljCYijSHs8mI+SpSplxdf47Gah2dqE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dj9HWMMU2uOSlJWWLyFO4ZSwRlvYz0gbC4fOIuUk+Ak6Pl7ybdTHcIsvifiXpSByh3ba/K8YJzN6uevNgYDd6BSBTiivRM3LItmRvjfThhOxvbCJBgG8dE0qIBeVDAlo0/a6BqndPbE/Lg5lqIfefbFGmqDc7ia3cfLJqdYCb90= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DWszuDo3; 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="DWszuDo3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 779F6C433C7; Sat, 17 Feb 2024 16:44:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708188257; bh=ifyuF7O6U49FsljCYijSHs8mI+SpSplxdf47Gah2dqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DWszuDo3Ww4N/WTNDl8bsY5ekgQa3qCGREL+KVQ9SVEVxjNLYZohGn3oEcdS3+7me gWpoGoIuwndbCwiulGpdeMeUDXgJWc6UEMNBcifS6XciIEoN8te/o9wj0CaeofwMsQ Z4hOpcrGkPUZcfXLIDNWowZki7oY+NPTjPB9bwppGGwS5HbTklKbpzuHUkQtqDZfZ1 6z7BRC7GQvxbhkjrHMqGRW6Kwrn6bF2D2S/VHb0ZpIpt3617NQdE1ZMLlRGEyHIQZW XxMKHUUwU9u8yBVk6LDQWPylXzbh9I4kSk5ofkuuk2G29a3Q3CV69PoiPRjqcOUtNY WR7tsjkC02ZRA== 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 v4 12/15] iio: addac: ad74413r: Use device_for_each_child_node_scoped() Date: Sat, 17 Feb 2024 16:42:46 +0000 Message-ID: <20240217164249.921878-13-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217164249.921878-1-jic23@kernel.org> References: <20240217164249.921878-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 Reviewed-by: Nuno Sa --- 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 Sat Feb 17 16:42:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 773955 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 282037D3E6; Sat, 17 Feb 2024 16:44:24 +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=1708188264; cv=none; b=VMxzxRGOtuqHqT0A4MyJlkD2I7M21Ns6J2xo8Z0OIcxs7/yGG7DeR3wmOEuWrGnunKWllQ1KmZ1u2rtgJrgeN0V24eSDJ9HIOBLpMOOyPH3NAhQvaCI7bf9sPfzexypn2t7wUZkraloyw3Al7/NtsUvwib+ETCiadKafWYYpgJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708188264; c=relaxed/simple; bh=qJ6hucCm0b/moPq3jjlQ5H1GFMO0uvJDXAqN+WPZ58Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GTo+trGEMkBUxM/Wsc257grAfwK7whsWbqFyWo1BrAaiJ69P/fwacnjJtLrVAA4wNWo8orXja1+SGF3pP6HrUB/d5Svazhg4ON6L7XLE6NEFdZIXW+sA7d7iZm769VCf/T81Lia1YiEEtc9Gyqodz9RGC/NCvaoImgbJ8mCJ2Yw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PhRjTLth; 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="PhRjTLth" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 372DFC433F1; Sat, 17 Feb 2024 16:44:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708188264; bh=qJ6hucCm0b/moPq3jjlQ5H1GFMO0uvJDXAqN+WPZ58Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PhRjTLthodEA3krPOq/Col/SfgvBrKh7t/mM5NDTSNpg1QSfAW3+SEdPztOUx67U+ PcGsH1m93T5PS3ybxImh3RfxeVA3iRo6vMKh85wld+mVOPDtZrH7OxgwwKIvF218wX WC35HjZXVw8czjmO2i+X996MzFkQPrSaEfZ0LygelAmSNSPoV0Dqbd0rhfdGeOXAiQ QrHkTRjEHHbPLqURWxK4NF1lq54+0TnGVZst+plDvMhNiKlEBdZ/BO9VEfbaqoH+/2 Zg4cWbVaGEVAOtaQB0xA7wZw+hKLkn8eXye4UIP9kUsS5o0G9S/6uqX6R7kcNDqOQv p8lFcu94TzSCw== 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 v4 13/15] iio: dac: ad3552r: Use device_for_each_child_node_scoped() Date: Sat, 17 Feb 2024 16:42:47 +0000 Message-ID: <20240217164249.921878-14-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217164249.921878-1-jic23@kernel.org> References: <20240217164249.921878-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 Sat Feb 17 16:42:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 773763 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 205F57D3E6; Sat, 17 Feb 2024 16:44:29 +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=1708188270; cv=none; b=qWW+6j0qvtdE9ByabmXNGRjOqLwBLyd55Lh0srH7WgPdq6aOyUODZnsYYHqTObIaPCIHsN/q+dDjzQ9jT0j+/tjQq1+iDP5ROzXQy+gg8gTIlugZOFdH/Vo73RvpqchRQUW/3+AqUeENUyeBjvdflhpXgaLBeCyQ1QpI9Jjf4e8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708188270; c=relaxed/simple; bh=35QYOXLq4zAytbJTMQEpTX7uMMdXMhvlvDV0Wbcyp70=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j4ggNH1myAhkFpaS7rB4ZPaWwYD2z0CjULhmZ6mBJZg6myfkJIeTfqwjn7xocwbeVQe1ewrRvPuymaGYjXAdDL09IsiguETPHdsXIdkXTbxmrcwiV9sXkKf38QUlUuLsZ7KnhsnDQ8OEt814oLReaAzuMoRiH5aleD8YBMrudt4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vHr0COqg; 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="vHr0COqg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C158C433C7; Sat, 17 Feb 2024 16:44:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708188269; bh=35QYOXLq4zAytbJTMQEpTX7uMMdXMhvlvDV0Wbcyp70=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vHr0COqgDkW/q5zxC2BrNG1FpCAovCsy1jBkU/FiZnXcJ5THp1Z/cVWvbU5BvWYYI ME4o98hmsNy884IUh0ihFLVqMXHauOeumaDJQiHSVgIzvGW9sDQnQi/W95Wru8ENvz /UKqm5QGmI+nXgU0Ck1V8bTc/PDespxCBGSgWwFgIwdinOeB6UpfsSKHNc6qqT0aP4 2LaJlPAI5ReVAKYXjZ6nwHJ49PumRnKO7FMBGnWs41GWdZXju9axKCJejB+QT2ZU0f kPAcPUwjnRd32DzEPECLbSACIexARkIrRClo3wVyrq2MTwdjsaNfunmKSBE5eX2Wtc oUlMOrejgcTJw== 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 v4 14/15] iio: dac: ad5770r: Use device_for_each_child_node_scoped() Date: Sat, 17 Feb 2024 16:42:48 +0000 Message-ID: <20240217164249.921878-15-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217164249.921878-1-jic23@kernel.org> References: <20240217164249.921878-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 Sat Feb 17 16:42:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 773954 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 E1CCE7D403; Sat, 17 Feb 2024 16:44:35 +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=1708188276; cv=none; b=DN5hJpeWtlRhwNmyz9dNG/CP5Cf9ew0LPRvV7S2aGA5o0t1G7aeOTLtCe6esf+/5KhonBMiOhnE43k3sGsZpzo3jrU0dxJLV5SyHszo651b3OVO/eArmn6d19HOeTONl0pX/tdknT+jU8LdgBKGjuLgykgLFxA8a0kexT7USFsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708188276; c=relaxed/simple; bh=79c8DCrGZAScdvyIHMIvQJjPXB+eFzdJE93eK/ZtP+w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Drd+5t7L4aCRqe19yLs+prp0HKdCWIdJnp46F45yRzd5suRDj8RbXjv2CYEFkqns0u40ldkgYRjz+3mf8enX6EdvCdmuHkByOj6JWfqqN9//ToUhOlJAx5fTu4KB48V5M3tD4dW09gKY1mH3Cxl7HWOJ5N76XUmNjHjiZNG2+DY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ued95WNs; 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="Ued95WNs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B63EC43390; Sat, 17 Feb 2024 16:44:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708188275; bh=79c8DCrGZAScdvyIHMIvQJjPXB+eFzdJE93eK/ZtP+w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ued95WNsy1SeM7nuVo8E9EIVN+vMLCvjAC5TeM1nIjFmIwKXRmx2r9HlTZG5RNXma 6JcHTm7BncwGuCsrW8hrJEuWUfWBjoP50qQIPUBw7zQ+jpf/MU6wBLIElrIn4WQETB 33CQsG8IvmndEXgTncNJyzK1tYfu95BWLXpK2YHESn1Q5iEkrdOXtOIw56o4ELGoUk 4LZlriMolC1YQViJLhCRfa+NvKvMsj0EY3cy66BNuyvj8tKVAni9+giosYLjhneBM5 vO6M8rYB/pvvRa0RBrXQhlKYlgHz9DnNAt8I8YaWbkQ1Qa9llMs0TUjW+Ja3CgPYwN kJ/cXK/a0jGUA== 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 v4 15/15] iio: dac: ltc2688: Use device_for_each_child_node_scoped() Date: Sat, 17 Feb 2024 16:42:49 +0000 Message-ID: <20240217164249.921878-16-jic23@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240217164249.921878-1-jic23@kernel.org> References: <20240217164249.921878-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 Tested-by: Nuno Sa Reviewed-by: Nuno Sa --- v4: Moved alignment changes back to patch 4. v3: Tweaked the alignment after comments from Andy. drivers/iio/dac/ltc2688.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 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;