From patchwork Sun Feb 11 19:25:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13552588 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 5050C5D73A; Sun, 11 Feb 2024 19:26:33 +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=1707679594; cv=none; b=kH9U2BukyNCx3eTs06eCEFf+QOYCr499oVHAZPyoORYBz76K7NEBKJbcwBJueiEgB/5u0OzzvI9C4bozOLmtS+w3d7/nfmZyTVBY8Hh7ec74j74F8yCAEgu4IntvqjcQMBlIqxZR0OKspC5a0aLTzqCrZksaLj8kR9zEqc9Bg/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707679594; c=relaxed/simple; bh=5BKBVxpx4qstzc7Dy13OyBJbrkG74U7h3TrTUSitCsc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F8esYrSXMDzdOVRgvt93JDDCsULhN/WEuLdooH2ak8Krq3Bda76uP61pE03ma7iasZJBoEZDvLFZXb9M7omDVe3N1ARSEqPz7FvtNB5YPUZMEGDyT/0RvJ7ivwPPKpKp/L2Ed0wl7zJv8tOfGQm8vao/zT7eWoVzg8/lLPF/1+k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZapYHsWb; 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="ZapYHsWb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3059C43390; Sun, 11 Feb 2024 19:26:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707679593; bh=5BKBVxpx4qstzc7Dy13OyBJbrkG74U7h3TrTUSitCsc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZapYHsWbFynFnItbU4COXZOxEHrq8zsYUum2h58zqy/ijFZi3ZQjeR85BziLCxCga ECFdotlGWVV3ndxAULB7exNmfwdWau2cQdKkE7Uh2jj1VIbI7voGU4tp8JArPbPTkP 7b0Rntnf+Lgb64nvDQ8G5LgSsjBTj+u3Do5pKNXNqN9Q+lQCFOy1CBQ3AZXoslcTby y5P4B1UHwDXQh2n0R6Cu2P86ed6gEIxoS66197uLR+Hf3/zF9lkNo4Rg1qKCiZYxOd irjKY8ZM9yR+TnnB2bQJdYeULuWSVQCwXiW86CHDxUGo9Mu4l4mUUznwGyAdo9wYC8 kAvt4/6o17DTA== 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 v2 01/14] device property: Add cleanup.h based fwnode_handle_put() scope based cleanup. Date: Sun, 11 Feb 2024 19:25:27 +0000 Message-ID: <20240211192540.340682-2-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211192540.340682-1-jic23@kernel.org> References: <20240211192540.340682-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 e6516d0b7d52..bcda028f1a33 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -188,6 +189,8 @@ struct fwnode_handle *device_get_named_child_node(const struct device *dev, struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode); void fwnode_handle_put(struct fwnode_handle *fwnode); +DEFINE_FREE(fwnode_handle, struct fwnode_handle *, + if (!IS_ERR_OR_NULL(_T)) 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 Sun Feb 11 19:25:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13552589 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 5BB505D498; Sun, 11 Feb 2024 19:26:40 +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=1707679600; cv=none; b=pbcXyTv54oA1SFEf3CoKbkh4l0KNKwjdAy3jS3G/G1mm2nGZT0VZLKJ+fkk+6xr7TSFNy42QeeBf48x6JvQYhTljcJuq38P+3CbCksdfayGup4MT1TXCLNCI6c0hVRieJHFIPGq4YfInpvl6zSrwj5BxQOjR8YAFaUqhABeHx/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707679600; c=relaxed/simple; bh=VP9OVvrt+mDvEXoRKqg9vyewTIy5m8BSV12Q9IQuAI0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fyq1FeAacG+l9oOdk++0IHYT0ed9Nw29XFJQge9CkjReqoEaW5SNRBJkZ+w/cQcOJDvgkc7LcqMGiSUg944mK09ODP7cySKzRTjnvUYDxcoPuSE6oA/uK4U7nGanpW0fCMvaZNBn2PTKhL+Ds7n9VW4O+Xf5aTEgi1hbG4tAGO0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nXKvWCai; 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="nXKvWCai" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 441EEC433C7; Sun, 11 Feb 2024 19:26:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707679599; bh=VP9OVvrt+mDvEXoRKqg9vyewTIy5m8BSV12Q9IQuAI0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nXKvWCaijdb6JQpDVWeiDwn3jjoiE36tBqGYBDliIiftuWwyG8b2IgkVW2wycqxfw CmT7R0erFNjeJuHo6qOU8P2lOXzsz1lJ5BOhqUNuWCLI60U2u9NicnnIKci/W7jK9Y todnFwm4gRalEil4Y6iUfcAl1HV8g9Kbn3MolRhlh35ZUdoJ5pNeisPlpy7gZjVte9 AogExk98kAROj8X7S7dsSuxP2Etw5KR4PPL3lS4xYpWc+YpntWAsuT9qjKuAEiqm5+ wWkdzdbmQ8Ls/1/vhpRegPpnbNpP6Dp+ksu8xN8Mx61DDE2qlz1fV8dfsmwKf3aVEI ujowPKDUA2Q4Q== 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 v2 02/14] iio: temp: ltc2983: Use __free(fwnode_handle) to replace fwnode_handle_put() calls Date: Sun, 11 Feb 2024 19:25:28 +0000 Message-ID: <20240211192540.340682-3-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211192540.340682-1-jic23@kernel.org> References: <20240211192540.340682-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 Sun Feb 11 19:25:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13552590 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 F0EBC5D75A; Sun, 11 Feb 2024 19:26: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=1707679606; cv=none; b=ZpckvCRzD45nGy/12Pj4sTDyWstodrCWeG2cfsGEtz4ryvfEt9ZjA+ZbeNOhoZBbX57y16R+Qt2cZNZMVeWDxaeBTPOPns5PU0/u1Dhdn1m9t7mQ+I1P9A35wlmvl9lpqIQeECNiOS+SiEW5gwBQYCUuuZD63LMQXAn4nuqVBR0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707679606; c=relaxed/simple; bh=wXOs3T8wmJwJW6VPW95ZQtHc243uZ8WdCx9gNnNNTfY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MLXUbQ1NlgRbmejWS26WWk/2QEDWeqkuy2bITfrN0zcK3j/GSNetE66yTPns1ZsmHFFPdOqj02Un9vBSaxzJ+fE8ivnYRcmbvLIcjHo0q1zliRkp0+NjqGb0kHQgn5lgsxFYRH+xMCiEVtqcS6tp4HC0pbOp2mGGHamjKqNqv7c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hQ9ZBq3t; 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="hQ9ZBq3t" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52291C433F1; Sun, 11 Feb 2024 19:26:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707679605; bh=wXOs3T8wmJwJW6VPW95ZQtHc243uZ8WdCx9gNnNNTfY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hQ9ZBq3twnJDyINamrLJDC3gL+Btz+tRWr5WTd/QpkdX5d0WDuwCj7H1aAfkVtm29 UFwsvYa0bJzZiBtlQZ70PxW7id76knQfLZbwWKkl+43Ww+KKDJTm21GJwicdDmz6JF YCTIO3+FW/jrOdxEysD0fzMsBn/SG/GtoLQc5eGgdBV7UC7jsSFKegNCQ4EBMLMrfO 5NfCQ0U6f9YTkGrztCMRB6SpUF3k244JqEY6mOimdzQ9ZSOcekR9ftTnw5vk+7S2rG KPmUKsQStuWfrHYpPdCNGMsTdEI2aiUrMr2FeunWQTGS8m1+DSTYmR3btduSODENMm NRcysse9g78Pw== 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 v2 03/14] device property: Introduce device_for_each_child_node_scoped() Date: Sun, 11 Feb 2024 19:25:29 +0000 Message-ID: <20240211192540.340682-4-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211192540.340682-1-jic23@kernel.org> References: <20240211192540.340682-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 Reviewed-by: Andy Shevchenko --- include/linux/property.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/property.h b/include/linux/property.h index bcda028f1a33..e76b8c6646bd 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 Sun Feb 11 19:25:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13552591 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 789E95DF34; Sun, 11 Feb 2024 19:26: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=1707679611; cv=none; b=IJY5bFbgHW7GbJpN3M77fSSVK2zEhEOiLPQ8Yk/FBvQJTfE8eLzlyAb1lBmh4naJrgnWv+a2tCLqjvr5klg4kILJ4yW5DZvBn+FO03m2P3bQvTJhWfPQArtxJd9MBWI11EA9pMX0w5fXzj5tlH3exPUocJUgIflk7Mhol2Qj4h0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707679611; c=relaxed/simple; bh=DU/iOWMCd1LvRo1Q6PdWhghdA/tvkisyLu7vKgJfAP8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qocEpCLxKKCG/htLjHgitTirn8vLvj/dNV4K9JuYRiqwRIh58SbFH9Pob7cIs2+s4Qpc1Jre9l+rmHe7A1hs6nckqTDY6RhgPqFzWiXTatUn7pIAl5vOHCUm/bYaIN2/OtSH0Br2gyzsNXi/uZ6Z3M0NelzDaBbLqBen6PzhdX0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dlqdvnfM; 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="dlqdvnfM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8652C43394; Sun, 11 Feb 2024 19:26:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707679611; bh=DU/iOWMCd1LvRo1Q6PdWhghdA/tvkisyLu7vKgJfAP8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dlqdvnfMHYa/VszGsLdRVPN2qK57Ox7pE58Y0wx8utpoCPtY80XS5uHjRwTkXhu3Z bdNHMdtwxNV8AY5ZlDsnT2tD0lkYfzHWbL+L/Q4B9t795o2s+sLZah+ysL9TvqKuNc YnxrjNtU/vVC47lP3jIbFyWoF0oWUbW1CmqJdXJyhYddlFDoXrsb1aagYaJDCRnRGY vgXeJEO1tW7qYGj4aikvO6bajJxLSmBSI4e21nRK5cGEB6stEs+wcTnxDyKkFd58Df jOlprYtUdbCHq7yWPZWoZH5XYXz+rbBM+/9YNzmBGB4WIT2YiFmVMz5K7GeTtBzuYe Vdo8x+No+GSTg== 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 v2 04/14] iio: adc: max11410: Use device_for_each_child_node_scoped() Date: Sun, 11 Feb 2024 19:25:30 +0000 Message-ID: <20240211192540.340682-5-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211192540.340682-1-jic23@kernel.org> References: <20240211192540.340682-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 Sun Feb 11 19:25:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13552592 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 7C6065D759; Sun, 11 Feb 2024 19:26:57 +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=1707679617; cv=none; b=stETLG6q2TXuFQxbU1w6xbgEKy2/eQVOwkhGnCGfR0Lqexj8aY/WUKwL5XJXMepdsbY+QbEmoA/evSsGCY0bZtufC0h+FyeJS98uBbhNmzQXmAewPv6JlNrfOBb6MA89PqIbjyNbSCpXF34A2ODzaehYCEWFsIWReY7/gWv9b1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707679617; c=relaxed/simple; bh=lBRT+ODr7VMir8e6ZE62Qc0+qCPmjWbG15fYF+vknxQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GvbL0AKrNNz1glb/fpfN2982s/ZVrwdZU83v9j4rQM7vguuW65M9Hoi3cH1QEnZ38J7YyLs5LFe38o+NiMxkK+76WLiDcjvq1fsd9Pjo515vWLio95Mvlo9wHa4MDiGiTZzke3hPjqGbebiQtfyA8S24cbd0DOhYGterXTfhJfQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h2WlHmST; 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="h2WlHmST" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCAA3C433B2; Sun, 11 Feb 2024 19:26:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707679617; bh=lBRT+ODr7VMir8e6ZE62Qc0+qCPmjWbG15fYF+vknxQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h2WlHmSTRpBPyvKA09Q5gdwdOFuOgbBjFZrJC52ior9OCX5zMc3W8iuniW/Fjgoki xq7CUFz8oksPhA2dzjCobfejy9XSPDiWr8h0vz6HOAV/DSKfFARtLJ+ZNoJHMLQndK s5UUmVg80fCSm/HfTnLK0N1amnKit1XLaPpT3FD5Q5NcC9s8MlfkBpA3DuO9dZOFIi xJhKGAKFX/GJwq181bJKJNrmhnxrcZ2IE20KgOd+tvOYZGz4+0pYzT1rTZiuPWG3+p M4mAxvy0O/kgeXhisPr1B7XaOHbNvjUuPxSqzt3iAv5kTzgNUFG9mwgqij51hMMUzY j37KKE/Kmkncg== 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 v2 05/14] iio: adc: mcp3564: Use device_for_each_child_node_scopd() Date: Sun, 11 Feb 2024 19:25:31 +0000 Message-ID: <20240211192540.340682-6-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211192540.340682-1-jic23@kernel.org> References: <20240211192540.340682-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 Sun Feb 11 19:25:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13552593 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 90B835D752; Sun, 11 Feb 2024 19:27:03 +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=1707679623; cv=none; b=Esn9JaapGrkqL60HLMxXPw949uWBbZ8Q+4XY2srpWw3hcw41rFc3h0nyqQihe8lgc7m8igrnzlDR49AMWlLbjD3yfsOkjrUfLHO5UZusKaES9OyP6aC3fOfRd7Jm8Ud7/zpR431KHMotMvkjUr2uumryfLpVk6b0r8ItqQHFtlE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707679623; c=relaxed/simple; bh=otkuWVvm1bamfjcnEtbEOSyFP8EnfuLqCzO7ywXASiU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qwgrZO1U4uhSJFJGfQxqMejfl0TRsnJWRkYa73sSiE6iVjOzRqeg94uV5OwcFvRh0AXz18TZpzWs46Ay1Zq7zyBg5dn1NPWeeyBSexsIIsxgKJKDq3K3lzYjOW1JYZHT2LBg7eG2oPDLnq0pf/wP63QLHt+zJk5YKYotMmSVbD0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J9FAw0wF; 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="J9FAw0wF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FE19C43390; Sun, 11 Feb 2024 19:26:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707679623; bh=otkuWVvm1bamfjcnEtbEOSyFP8EnfuLqCzO7ywXASiU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J9FAw0wFebf+qt6eHfoydoqcJj0gBSnHJpCavbJcT6eexnFD17A7xaHEeOHrwsoC8 9wBoWPVkLiB2U6IrTD8n7cQvu9gyjtGM7DFM62ylJnGDH5qpvqVDI4m5XSDcuOotMd vRXcZ727Dlil9GgTWud/Biz/16fewUmdTO/Y2k1T0nW+CklDiZs9XtgkNMODhpcgQ9 m5SyhQ+9lE3heU5Ha69aIRaPjd1rEpTcMPhc0tD2204W+7hoyEiugwRHRisNgYAguz tOtRSCMQAOfQlSHVpL0fpVbvaMYDcgH981GFiZdS1QP4JvGs9dqUVbQfOgbbRDuLMa xqkIC/B53b2hg== 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 v2 06/14] iio: adc: qcom-spmi-adc5: Use device_for_each_child_node_scopd() Date: Sun, 11 Feb 2024 19:25:32 +0000 Message-ID: <20240211192540.340682-7-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211192540.340682-1-jic23@kernel.org> References: <20240211192540.340682-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: Dmitry Baryshkov Cc: Marijn Suijten Signed-off-by: Jonathan Cameron Reviewed-by: Dmitry Baryshkov --- 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 Sun Feb 11 19:25:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13552594 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 508465D751; Sun, 11 Feb 2024 19:27:09 +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=1707679629; cv=none; b=KWWPQXg2L2x6qFxNScoKU5MvYtxLmdxtvqSCJyvJrjasYzwwF0lKpnUBkhFfirrgeHlp5dJvwANrfj6ZFaf54HGHhpomBGS75CqxEaJJBl1xY+uBZKBwd1+D73VM/AZuWdlKZq/rsEqgauCiEueBJmw2AeQh1sQd2kTkU11Aamo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707679629; c=relaxed/simple; bh=J3pZmC2KKyBlCMRCD/FTEFP9csRqHwyyTXOVXEmuL5w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eHKvJKtpqE3IKeXieWViXBUE6tSUe6yPDsaEBO9pw/iM+qHZqJ9azBY9NdSUq+LBgZDdNBG0QKZqOG0LRq1QuofpRTk2XFdf2NuUFSZ+QWsYOmOMFp501WItmudLj+d9pnJLXImkEv68mg1Us/MdEbfFOwE3xirdjVCb3cdILRM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O2wGx5Xq; 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="O2wGx5Xq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDC3DC433A6; Sun, 11 Feb 2024 19:27:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707679629; bh=J3pZmC2KKyBlCMRCD/FTEFP9csRqHwyyTXOVXEmuL5w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O2wGx5XqlGx+e6wAlcQJm8GmK45CuoMAJUa27M3i9iTdSJUMwA8Q1mXj70tQtQVOz dbFXAzXzq1rIKsP2hQiIITqjIIk0gQrBixcQgd++leQ+XsgmS2yffXccPfQnjs7vLE jUfsV9t7N1s48e6IJ4rSedTgbPB1EkZZzVXWxv0HidG2S8uWwwIUjcSVwOwXS5ylTZ BBrZyQiNrRgW7CzZko7jVxpMezmsz7KSRvGgU8rAfuS0GfoY+81IwfdjOcgC3h+m+H PSo2CCJnQa/LcRePEmLPEv3syyxv9GjSnWNNxQMt/9SF2HnMbzJ69Daq83m46y774I mO6U4hKZsIXCA== 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 v2 07/14] iio: adc: rzg2l_adc: Use device_for_each_child_node_scopd() Date: Sun, 11 Feb 2024 19:25:33 +0000 Message-ID: <20240211192540.340682-8-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211192540.340682-1-jic23@kernel.org> References: <20240211192540.340682-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 Sun Feb 11 19:25:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13552595 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 6B44A5D498; Sun, 11 Feb 2024 19:27:15 +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=1707679635; cv=none; b=rDLs64qnGj0V5qMk539TlqebRZMj/Ky8FIdsWJd0riQo8zlfHDW2ghQbGIZpPVO/4OQkmRKNU3BsIoaGitKQnW3hILsdP+qS483sRksVFu1/ImRmyzUkd/n+9AKnPsK2CPZwVRRWophkYkjt5Lp85JttWnJWgh9UVUKt8wchykk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707679635; c=relaxed/simple; bh=zuux6IujI5Gs3Qy45t6KVgg/GBvblENjdn1E/efkJxg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kLsdN0Qsfr2Q4/4tj4hDiIRO88PRCyV+pcA1xbbGPzLcfJStnPMR26+R9tToDXQCA5SNHSyWVkMoO8X3iBRIyWegLXtrAyfQYW/2WXU1e8nzaoBu234BUjP9Xq0lGlLEV19E+9zCAX/gFIKMADpilVSVC8OXvI+sI8wgi16giWg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gZk8rn2o; 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="gZk8rn2o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94E8DC433C7; Sun, 11 Feb 2024 19:27:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707679634; bh=zuux6IujI5Gs3Qy45t6KVgg/GBvblENjdn1E/efkJxg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gZk8rn2oWsnkW/ijp98NCW61Ij624WSQNjigERv6RxSZY6MXQgVg76nSLEy4cdFqH VO6NkExBHvaD/MfNMc3NxeLYdjeeWIujYPMiXVcCDiOTZNytzo9FHXnG7nzuI9jyxf 54weOhjRWz09VbXEaoyscwt52G5y9mSt35HZuUkGOMl5FneVEqsdkAtA+20dnL9KjP krlQVCyNdU2fCYO3pEReoq04XH6FJXWYUOteiolFi4jLWVkEeICTQHrjBtGd85YXJs 1fO0eEsvPtCBYzea9RXd9m8O9T8xj6+BKVimTXX7Pi7N5JmkP9SeoDeIOiD/naJ82Z XCZq2X6QFMP7w== 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 v2 08/14] iio: adc: stm32: Use device_for_each_child_node_scoped() Date: Sun, 11 Feb 2024 19:25:34 +0000 Message-ID: <20240211192540.340682-9-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211192540.340682-1-jic23@kernel.org> References: <20240211192540.340682-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 Sun Feb 11 19:25: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: 13552596 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 F32BF5D498; Sun, 11 Feb 2024 19:27:20 +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=1707679641; cv=none; b=NVTVbx7DrkUk8c+PHGwl1NqNlhyjOswmBfBrm0B8o82OLeu58ZAMvNqoZehywQZxzQyer92OPYde9fQSsdU9nOtwM3AECQUJKl1HeDgI2tb8ODoS8SXVYSAHExI+mmUO9EoOkrB/hd2VT5Xz96yyJsDvv4NyGDywj9S024RFui4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707679641; c=relaxed/simple; bh=DC6dz+YHtXRBeaRwOAmhjAqY7WW7vUz9C+A/xNQEKws=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DL7f6hVjcp3b07HyhRgrV/XAQ3rE4hoYLdSvyg5QzmcFgbMvRGy2kACo52yjwCWyC78heKPZaQVdB9B1a68l5ob15Z4t0n4UMgAQN2EqFucJOKbeQLaJPLwcp4ndxeB83Vx0dNhjHvxW47IM14iAmvywXGLQzhlHhbBJk6xRVeE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ryvhOpxn; 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="ryvhOpxn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 542EBC433F1; Sun, 11 Feb 2024 19:27:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707679640; bh=DC6dz+YHtXRBeaRwOAmhjAqY7WW7vUz9C+A/xNQEKws=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ryvhOpxnI68NUH317PvMqW/x4yJMbjKNot+pkiYBAyoWy42FnDiLbTa6rG/37srhH SWjj1AJDmMyEd3Q/bkkhf2ecS6TQ/a/RxxiZ0ZOUfyxtnES17YfX2DO5ZlYyzymVtV cnHJqdUX0GSJ8Bo5JmYWfnQTtbF81szSUQFcz9OQK//wmdJxv1TZc9bj51PTiAgHlB X8eb/9S/zCcbWzJjxZZ//gXoctsSGsIJPwdhHJBnGrnymYIEfJrYigXkawWenb53xL PJb81Q9RKb5Sr/TV02ZD/PgH6IWF5CqXj5KRAexbjQfsD2+mg+j+Wb9hSeMh4MxrIN OjiIR69Yiznkw== 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 v2 09/14] iio: adc: ti-ads1015: Use device_for_each_child_node_scoped() Date: Sun, 11 Feb 2024 19:25:35 +0000 Message-ID: <20240211192540.340682-10-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211192540.340682-1-jic23@kernel.org> References: <20240211192540.340682-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 Sun Feb 11 19:25: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: 13552597 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 81E1733CD2; Sun, 11 Feb 2024 19:27:27 +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=1707679647; cv=none; b=txuQRDKQVjnyng0BGHX0aW2+CQxhqaykVUmvkx+rqmmQlqyctxhQNvpGTNXpWMvmaD1kTzsGN3v/nxwNZzEzd5mRHxmqVDLuppkMFejNa1Z1LanSi5zcYn3D6hDhaeB4tKq6BOR+jR3pRwlsur1V59Tcp5eUOX2t80OnwJpJqd0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707679647; c=relaxed/simple; bh=k4Sbe42YicpnKE/blrFSxYSkJ4X6IsERAAaxczqUlwo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RxxOUpmfb6uLN+u8dZKcqJ0eicwZDJqJLDKoBlQsB8DpFuTN3AeKlRnpp5nPuXeZgqtlggbr6ced1aTmQERbK/Y0RjF29bZPQ6kEwrYBuIJroMKOMowgO0T4PPV2eDStVwPDino8Za/qTUPQU15lduq+0dd4GWRLCmU4R2/Hai0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oxN+30P8; 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="oxN+30P8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D6FBC43601; Sun, 11 Feb 2024 19:27:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707679647; bh=k4Sbe42YicpnKE/blrFSxYSkJ4X6IsERAAaxczqUlwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oxN+30P8yLZ7A1k8VcKgYKl5l8KVTi7BjXeVjfpv99gK0pPcsHJ54RYTJ7s6dfLJ7 I7JMKtXDgntKb0tEdkCd3WYk8HvD4WgDIstnWxCOFk0GOlPG8Yi0A/0YzOTrueXtw6 GnCE/Hr4vVYgb3m/v9ZGF4j9O4PhqFVc0bXXPiSpUsschNwhQnIzq6W3baPlbBN3iV 3Me4e0mq+UMbdgOx+Fp2LjbkNzVdnPSmH8OfF2+H6Zy3VO1DFOIRMuQweoe6rfFSyf mh24BDr0Nl5rSwoD2YgTFD2q9DvGGJceaBg90gDBZzvpHdn3G8WRIWdpLO2i2q7QyM Tx7qOre/RhkBQ== 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 v2 10/14] iio: adc: ti-ads131e08: Use device_for_each_child_node_scoped() Date: Sun, 11 Feb 2024 19:25:36 +0000 Message-ID: <20240211192540.340682-11-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211192540.340682-1-jic23@kernel.org> References: <20240211192540.340682-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 Sun Feb 11 19:25:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13552598 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 B269433CD2; Sun, 11 Feb 2024 19:27: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=1707679654; cv=none; b=O4hDgkV2plJ8mZay8b0SFzLjNHtd8LkSix3Am0psrfdlDl4JD3CMWZM5zs9Bf5/ojGn9wPyNMd1I3pUEG/XkAvq1WFAMOlpywMLyZDl+Mny70ZPeHKyv8bszqZ90QTsYiwx7z6xNUDpbT6x8d2jb32M4/e3fxJs9RD1N8zqUMAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707679654; c=relaxed/simple; bh=Ew72D0ROr0xyyVBPfQdzVifZd7Uqo5BIrbLTQOaAPrM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TXuCa0InW6CUBd6P8Qw8yEFv3cUY+ni+tKkbfHZAhaCYuMU8sAtLCyi7JVJcUTleZvyXnfOoNKbPNjCUdY1Dgi1mdiR9E1vKPaadSFIWppv0qWc+Qb0BB/iqOg+7CeibjQOW9mnoyDfqURZkDQJgYLz7lhTyKPWmag9CZPkqq1A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h0U7t3O+; 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="h0U7t3O+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB986C433C7; Sun, 11 Feb 2024 19:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707679654; bh=Ew72D0ROr0xyyVBPfQdzVifZd7Uqo5BIrbLTQOaAPrM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h0U7t3O+uLn9HAscSjJQTp4cbrUJVK0+Z8Wh00yb7E3uFa6+4YuOzsJ85qP1opW54 PruPBg4JR+IFj3Iw4JfjfSyigacKx0ckYUjv9orPCn/aQQ1YalcXfN0cW9t37HXscL xcFc7qixuPnEyCEJByzrg1cDgoYbb6MiyFn4zOGvGcuIb+8hUijW+w9HOlyASPkfsB 8CX28j2W3cKmfxvNAp6hFLnV/cPdYATurgWVHmmZ4gBnoMeIYVKCCsCqlqUvxv4saC FYp9urPAJFY3DsfgpQRHfZuVjsnNXBz9gmTer1bHITEKyJI+X8KrKDFQPbs+OQd9ut ELiIzAWbQcd0g== 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 v2 11/14] iio: addac: ad74413r: Use device_for_each_child_node_scoped() Date: Sun, 11 Feb 2024 19:25:37 +0000 Message-ID: <20240211192540.340682-12-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211192540.340682-1-jic23@kernel.org> References: <20240211192540.340682-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 Sun Feb 11 19:25: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: 13552599 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 118E333CD2; Sun, 11 Feb 2024 19:27:41 +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=1707679661; cv=none; b=LqG4Nv54Muk0BNL/Y73BUjTFPXzjdmkQZDMyIMlyeo1ivxpRbRQSWY6oCYHCfqS9iUJwOg7mWsGpxMbmc3xbDIAzWRReR4aQJPNsJeAgmvD6yWYO1QJyYPR0/PJXztM1x9IwzUhi8MtEzWsPFHBsHYH0Hfe7onSkmFzT4F6OsaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707679661; c=relaxed/simple; bh=rgEoX0FYtg6ykzmDeCYk0UhT2vVjd9laU6gobcrnOxM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HS1/qNPMjJE3Z/f6jdXh9Yr0YsxVfh2yKM9ste+tORhYZnNSYaoQgE80q1Oe1Qs2cT1mG4XYwP5vAnbvs+tUHfpmoJ7ISQDC6+H9IEV019sSih3aF1mNVDgErutGEh0WKxSDSoGf2rvJK8gfH6qpbE/q4C4Ut7ovQlB8h04aFSQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Zo8czDJk; 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="Zo8czDJk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF1C4C433F1; Sun, 11 Feb 2024 19:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707679660; bh=rgEoX0FYtg6ykzmDeCYk0UhT2vVjd9laU6gobcrnOxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zo8czDJkeTSrIi/J7Es5h4WO/uifUc0/4RRdNg49xqhuaZHK4LnsrkrASspNRzktZ s/dFDBOwTY33VKbwkA2qCsTwqIOqpNRrYO4KP2AogKKpgGpXnP1xlWUAHVwB3zjZZ0 D1xO2WbYWItFfXdcGCiJMe7ZqeYa2VzM86JweU0Lf08GNpvWlZ0ekH0b1RDY0lVc0i LN3NDwzs0gmNvU2Ui0Qp/i5bgwqAxqc7GK+S8An9Vl1qPdr8BZ13oQtJX5lwLItA/U FkjPPHoIIGrhwMy6iXtHUn0n3MJ5XdeKFkdgYhJuyZon2CPH21xvk7F0vRFlGf/xRW KZZilQCCF12Jw== 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 v2 12/14] iio: dac: ad3552r: Use device_for_each_child_node_scoped() Date: Sun, 11 Feb 2024 19:25:38 +0000 Message-ID: <20240211192540.340682-13-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211192540.340682-1-jic23@kernel.org> References: <20240211192540.340682-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 Sun Feb 11 19:25: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: 13552600 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 AB2F633CD2; Sun, 11 Feb 2024 19:27: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=1707679668; cv=none; b=I7D4kdzzBIafDmZuEASvjkt+SHVyQR6+xuWmhmTTzaGnALCx8SgldV7Ho+IaJTtdz6DSazbWt1bm8ZB8uE6t2aACRZqHbCxHC/CY1kWKlqpa2CXLyIwmM2T/deea2FS9JX0pe1ct3mrOloRHrhE6qFl+6jT61fW/IbdGi40AXYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707679668; c=relaxed/simple; bh=5i+ESD60B1IvKZDplIYAwXVD5VdjSlxZ809eXXhRSAw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ctkG1kJhd/0+DCBWFw2b9Y8emquO37Rr738VLV7EaF+FGWLZXJh9yMKuv93+3DJCKtOnvO81+FqqpP4wF2BwuWfYpBxlpeYdttLzM+3kEARCo59HxcqvLlOI96F5HnkKHB8YkKSYMohyx8FgNhyODiJylVAdsh+3gOV6/MGNmw8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WApqwAEY; 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="WApqwAEY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9B9FC433C7; Sun, 11 Feb 2024 19:27:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707679668; bh=5i+ESD60B1IvKZDplIYAwXVD5VdjSlxZ809eXXhRSAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WApqwAEYnM26DY24LMhRg71rCxYeAZi+dAeSPGc6+WsJlGGFpjTCOy8N9SP0iZgEv LOTunF402eD/YrrpTRRAnV15YbX3Kn4sszV7ImGhb4LzTB794B6BzyBA95poQIczQ5 1kN3kqzj/Vj0cot6NIxyqUjUnZYlMSWMPiuOJOcSMXY4x+WG6s6hl3d8FzDtpZJC5w gWyd8vCf7dxKHvWuL0QJpX+3y3hz3RJalR68zLmwESyk+CqRdarGokrkgCJghfk1LH jXGVIC9t49DlSxPISpYfHmB1/bfW0DTKH2LOsY7VsKBz5T4IVP3DIxalET5eIQl9R1 aVmS3D3d9kvtw== 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 v2 13/14] iio: dac: ad5770r: Use device_for_each_child_node_scoped() Date: Sun, 11 Feb 2024 19:25:39 +0000 Message-ID: <20240211192540.340682-14-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211192540.340682-1-jic23@kernel.org> References: <20240211192540.340682-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 Sun Feb 11 19:25:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 13552601 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 1C5505D478; Sun, 11 Feb 2024 19:27:56 +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=1707679677; cv=none; b=DLOByX2Q1zSInBt/KO5gqFkU6TdOZzRQELmn+j8lQ55N5FrUhqAI61Lk1CM0SjvmB9LPhUlnPAUEuuk9b4MuNRK5ekQdzIMqBmcCs0lpQSSxcfBQPRUuWLDXWE96O47mb42xjrp3dpS7murR1Ayh6GJjmsZXeprAB3/PFGalqng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707679677; c=relaxed/simple; bh=HkWB5H4zBCE15CCo9JBn41UFUpV14sxEaj2qAo0OdjE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=g3/9ObbX5rIsP03ot3hpsMLYHi94+VbhKHVwg+6t5ghruu/RvW2beQQeIX/fl3xQmSBAIz+SunT6TZQPXzP/BOFzAmP+6JLfgfQFsNdpge58kHFgJ8ygCTjmLnCX9Hv6Tw8Q8WapIwI824ztcAxqmzRfV/phxGFjx0h6h7Kb+9Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sF/6R2H+; 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="sF/6R2H+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07A09C433F1; Sun, 11 Feb 2024 19:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707679676; bh=HkWB5H4zBCE15CCo9JBn41UFUpV14sxEaj2qAo0OdjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sF/6R2H+BFKVTDUf44QTlZ7nOugrL6fEFCgWh3+/xXJmvtgm1fb7+VCFQMv2ZBQSH e8534fSXREa/NjSLS7Msww7ulqv/0hGBwRDkGismZO8ymQ63IM1mJZ1khNVstIMfaK 7JFlM4VqLbls6szEn4X/+WDKgRWgCm4YH1QD5MK3IGBcUHrbSarYUQLxzRPYD1slG7 DiSI+lG1GMuMrFKgmA0q5rqg+Kp3Vpn3uUYKqZ/bDKM5Bx1dA8qIE8No8W6z0sok5v eQLFhs1k2FKvUr5lUELzB0MvXoi04KiquGCghrBtKGwxpBoLukyRIJ/J6a0H+/NrgR z/Tyokxbay2qQ== 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 v2 14/14] iio: dac: ltc2688: Use device_for_each_child_node_scoped() Date: Sun, 11 Feb 2024 19:25:40 +0000 Message-ID: <20240211192540.340682-15-jic23@kernel.org> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240211192540.340682-1-jic23@kernel.org> References: <20240211192540.340682-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/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;