* [PATCH 0/3] media: i2c: Adopt scope-based fwnode_handle_put
@ 2026-06-15 22:30 Biren Pandya
2026-06-15 22:30 ` [PATCH 1/3] media: i2c: ov5640: Drop manual fwnode_handle_put() via scope-based cleanup Biren Pandya
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Biren Pandya @ 2026-06-15 22:30 UTC (permalink / raw)
To: linux-media
Cc: Dave Stevenson, Sakari Ailus, Mauro Carvalho Chehab,
Manivannan Sadhasivam, Steve Longerbeam, linux-kernel,
Biren Pandya
This series updates the firmware node parsing logic across three highly active
V4L2 I2C sensor drivers (ov5640, imx290, and imx219) to utilize the modern
__free(fwnode_handle) scoped guard macro introduced in <linux/cleanup.h>.
By binding the lifecycle of the fwnode_handle directly to the variable's scope,
we eliminate the need for manual fwnode_handle_put() calls. This permanently
removes the risk of subtle early-free or missing-put memory leaks in
error-handling paths and establishes a cleaner pattern for newly merged
drivers to follow.
Biren Pandya (3):
media: i2c: ov5640: Drop manual fwnode_handle_put() via scope-based
cleanup
media: i2c: imx290: Drop manual fwnode_handle_put() via scope-based
cleanup
media: i2c: imx219: Drop manual fwnode_handle_put() via scope-based
cleanup
drivers/media/i2c/imx219.c | 6 +++---
drivers/media/i2c/imx290.c | 6 +++---
drivers/media/i2c/ov5640.c | 7 +++----
3 files changed, 9 insertions(+), 10 deletions(-)
--
2.50.1 (Apple Git-155)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] media: i2c: ov5640: Drop manual fwnode_handle_put() via scope-based cleanup
2026-06-15 22:30 [PATCH 0/3] media: i2c: Adopt scope-based fwnode_handle_put Biren Pandya
@ 2026-06-15 22:30 ` Biren Pandya
2026-07-08 8:49 ` Sakari Ailus
2026-06-15 22:30 ` [PATCH 2/3] media: i2c: imx290: " Biren Pandya
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Biren Pandya @ 2026-06-15 22:30 UTC (permalink / raw)
To: linux-media
Cc: Dave Stevenson, Sakari Ailus, Mauro Carvalho Chehab,
Manivannan Sadhasivam, Steve Longerbeam, linux-kernel,
Biren Pandya
Utilize the __free(fwnode_handle) scoped guard macro from <linux/cleanup.h> to automate the lifecycle management of the endpoint fwnode in ov5640_probe().
This eliminates the need for the manual fwnode_handle_put() call, preventing potential memory leaks in error paths and simplifying the probe routine.
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
---
drivers/media/i2c/ov5640.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index ce6b0724afa1..7795f2de0f75 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -4,6 +4,7 @@
* Copyright (C) 2014-2017 Mentor Graphics Inc.
*/
+#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/clkdev.h>
@@ -3845,7 +3846,6 @@ static int ov5640_check_chip_id(struct ov5640_dev *sensor)
static int ov5640_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
- struct fwnode_handle *endpoint;
struct ov5640_dev *sensor;
int ret;
@@ -3870,15 +3870,14 @@ static int ov5640_probe(struct i2c_client *client)
sensor->ae_target = 52;
- endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(&client->dev),
- NULL);
+ struct fwnode_handle *endpoint __free(fwnode_handle) =
+ fwnode_graph_get_next_endpoint(dev_fwnode(&client->dev), NULL);
if (!endpoint) {
dev_err(dev, "endpoint node not found\n");
return -EINVAL;
}
ret = v4l2_fwnode_endpoint_parse(endpoint, &sensor->ep);
- fwnode_handle_put(endpoint);
if (ret) {
dev_err(dev, "Could not parse endpoint\n");
return ret;
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] media: i2c: imx290: Drop manual fwnode_handle_put() via scope-based cleanup
2026-06-15 22:30 [PATCH 0/3] media: i2c: Adopt scope-based fwnode_handle_put Biren Pandya
2026-06-15 22:30 ` [PATCH 1/3] media: i2c: ov5640: Drop manual fwnode_handle_put() via scope-based cleanup Biren Pandya
@ 2026-06-15 22:30 ` Biren Pandya
2026-06-15 22:30 ` [PATCH 3/3] media: i2c: imx219: " Biren Pandya
[not found] ` <20260708134403.45935-5-birenpandya@gmail.com>
3 siblings, 0 replies; 8+ messages in thread
From: Biren Pandya @ 2026-06-15 22:30 UTC (permalink / raw)
To: linux-media
Cc: Dave Stevenson, Sakari Ailus, Mauro Carvalho Chehab,
Manivannan Sadhasivam, Steve Longerbeam, linux-kernel,
Biren Pandya
Utilize the __free(fwnode_handle) scoped guard macro from <linux/cleanup.h> to automate the lifecycle management of the endpoint fwnode in imx290_parse_dt().
This safely ties the release of the fwnode_handle to its compiler scope, allowing us to drop the manual fwnode_handle_put() call and removing the risk of missed puts if new early returns are added in the future.
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
---
drivers/media/i2c/imx290.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c
index 21cbc81cb2ed..b0fd3e1dec2e 100644
--- a/drivers/media/i2c/imx290.c
+++ b/drivers/media/i2c/imx290.c
@@ -8,6 +8,7 @@
* Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
*/
+#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
@@ -1514,20 +1515,19 @@ static int imx290_parse_dt(struct imx290 *imx290)
struct v4l2_fwnode_endpoint ep = {
.bus_type = V4L2_MBUS_CSI2_DPHY
};
- struct fwnode_handle *endpoint;
int ret;
s64 fq;
imx290->model = of_device_get_match_data(imx290->dev);
- endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(imx290->dev), NULL);
+ struct fwnode_handle *endpoint __free(fwnode_handle) =
+ fwnode_graph_get_next_endpoint(dev_fwnode(imx290->dev), NULL);
if (!endpoint) {
dev_err(imx290->dev, "Endpoint node not found\n");
return -EINVAL;
}
ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, &ep);
- fwnode_handle_put(endpoint);
if (ret == -ENXIO) {
dev_err(imx290->dev, "Unsupported bus type, should be CSI2\n");
goto done;
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] media: i2c: imx219: Drop manual fwnode_handle_put() via scope-based cleanup
2026-06-15 22:30 [PATCH 0/3] media: i2c: Adopt scope-based fwnode_handle_put Biren Pandya
2026-06-15 22:30 ` [PATCH 1/3] media: i2c: ov5640: Drop manual fwnode_handle_put() via scope-based cleanup Biren Pandya
2026-06-15 22:30 ` [PATCH 2/3] media: i2c: imx290: " Biren Pandya
@ 2026-06-15 22:30 ` Biren Pandya
[not found] ` <20260708134403.45935-5-birenpandya@gmail.com>
3 siblings, 0 replies; 8+ messages in thread
From: Biren Pandya @ 2026-06-15 22:30 UTC (permalink / raw)
To: linux-media
Cc: Dave Stevenson, Sakari Ailus, Mauro Carvalho Chehab,
Manivannan Sadhasivam, Steve Longerbeam, linux-kernel,
Biren Pandya
Utilize the __free(fwnode_handle) scoped guard macro from <linux/cleanup.h> to automate the lifecycle management of the endpoint fwnode in imx219_check_hwcfg().
This inherently guarantees that the endpoint node is released when it goes out of scope. Consequently, the manual fwnode_handle_put() call in the error_out label is no longer needed and has been removed.
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
---
drivers/media/i2c/imx219.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index 7da02ce5da15..14dd5acee284 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -14,6 +14,7 @@
*
*/
+#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
@@ -1110,14 +1111,14 @@ static int imx219_identify_module(struct imx219 *imx219)
static int imx219_check_hwcfg(struct device *dev, struct imx219 *imx219)
{
- struct fwnode_handle *endpoint;
struct v4l2_fwnode_endpoint ep_cfg = {
.bus_type = V4L2_MBUS_CSI2_DPHY
};
unsigned long link_freq_bitmap;
int ret = -EINVAL;
- endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL);
+ struct fwnode_handle *endpoint __free(fwnode_handle) =
+ fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL);
if (!endpoint)
return dev_err_probe(dev, -EINVAL, "endpoint node not found\n");
@@ -1172,7 +1173,6 @@ static int imx219_check_hwcfg(struct device *dev, struct imx219 *imx219)
error_out:
v4l2_fwnode_endpoint_free(&ep_cfg);
- fwnode_handle_put(endpoint);
return ret;
}
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] media: i2c: ov5640: Drop manual fwnode_handle_put() via scope-based cleanup
2026-06-15 22:30 ` [PATCH 1/3] media: i2c: ov5640: Drop manual fwnode_handle_put() via scope-based cleanup Biren Pandya
@ 2026-07-08 8:49 ` Sakari Ailus
0 siblings, 0 replies; 8+ messages in thread
From: Sakari Ailus @ 2026-07-08 8:49 UTC (permalink / raw)
To: Biren Pandya
Cc: linux-media, Dave Stevenson, Mauro Carvalho Chehab,
Manivannan Sadhasivam, Steve Longerbeam, linux-kernel
Hi Biren,
On Tue, Jun 16, 2026 at 04:00:53AM +0530, Biren Pandya wrote:
> Utilize the __free(fwnode_handle) scoped guard macro from <linux/cleanup.h> to automate the lifecycle management of the endpoint fwnode in ov5640_probe().
>
> This eliminates the need for the manual fwnode_handle_put() call, preventing potential memory leaks in error paths and simplifying the probe routine.
Please wrap to 75 characters per line.
>
> Signed-off-by: Biren Pandya <birenpandya@gmail.com>
> ---
> drivers/media/i2c/ov5640.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
> index ce6b0724afa1..7795f2de0f75 100644
> --- a/drivers/media/i2c/ov5640.c
> +++ b/drivers/media/i2c/ov5640.c
> @@ -4,6 +4,7 @@
> * Copyright (C) 2014-2017 Mentor Graphics Inc.
> */
>
> +#include <linux/cleanup.h>
> #include <linux/clk.h>
> #include <linux/clk-provider.h>
> #include <linux/clkdev.h>
> @@ -3845,7 +3846,6 @@ static int ov5640_check_chip_id(struct ov5640_dev *sensor)
> static int ov5640_probe(struct i2c_client *client)
> {
> struct device *dev = &client->dev;
> - struct fwnode_handle *endpoint;
> struct ov5640_dev *sensor;
> int ret;
>
> @@ -3870,15 +3870,14 @@ static int ov5640_probe(struct i2c_client *client)
>
> sensor->ae_target = 52;
>
> - endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(&client->dev),
> - NULL);
> + struct fwnode_handle *endpoint __free(fwnode_handle) =
> + fwnode_graph_get_next_endpoint(dev_fwnode(&client->dev), NULL);
I'm fine with using __free() here.
> if (!endpoint) {
> dev_err(dev, "endpoint node not found\n");
> return -EINVAL;
> }
This check can be removed in the same patch. It's now redundant as
v4l2_fwnode_endpoint_parse() also does it.
>
> ret = v4l2_fwnode_endpoint_parse(endpoint, &sensor->ep);
> - fwnode_handle_put(endpoint);
> if (ret) {
> dev_err(dev, "Could not parse endpoint\n");
> return ret;
--
Regards,
Sakari Ailus
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3 1/3] media: i2c: ov5640: use scoped fwnode_handle endpoint cleanup
[not found] ` <20260708134403.45935-5-birenpandya@gmail.com>
@ 2026-07-08 13:44 ` Biren Pandya
2026-07-08 13:44 ` [PATCH v3 2/3] media: i2c: imx290: Drop manual fwnode_handle_put() via scope-based cleanup Biren Pandya
2026-07-08 13:44 ` [PATCH v3 3/3] media: i2c: imx219: " Biren Pandya
2 siblings, 0 replies; 8+ messages in thread
From: Biren Pandya @ 2026-07-08 13:44 UTC (permalink / raw)
To: slongerbeam, sakari.ailus, mchehab, linux-media, linux-kernel
Cc: Biren Pandya
Utilize the __free(fwnode_handle) scoped guard macro from
<linux/cleanup.h> to automate the lifecycle management of the endpoint
fwnode in ov5640_probe().
This eliminates the need for manual fwnode_handle_put() calls.
Additionally, drop the redundant !endpoint check before
v4l2_fwnode_endpoint_parse(), as the parse function already handles
NULL endpoints safely.
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
---
Changes in v3:
- Resend as a complete series to fix broken threading.
- Moved changelogs here.
Changes in v2:
- Used scoped __free(fwnode_handle) macro (Laurent).
- Dropped redundant !endpoint check in ov5640 (Sakari).
drivers/media/i2c/ov5640.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index 8deb5f5501faf..29d4dee9690b9 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -4,6 +4,7 @@
* Copyright (C) 2014-2017 Mentor Graphics Inc.
*/
+#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/clkdev.h>
@@ -3844,7 +3845,6 @@ static int ov5640_check_chip_id(struct ov5640_dev *sensor)
static int ov5640_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
- struct fwnode_handle *endpoint;
struct ov5640_dev *sensor;
int ret;
@@ -3869,15 +3869,10 @@ static int ov5640_probe(struct i2c_client *client)
sensor->ae_target = 52;
- endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(&client->dev),
- NULL);
- if (!endpoint) {
- dev_err(dev, "endpoint node not found\n");
- return -EINVAL;
- }
+ struct fwnode_handle *endpoint __free(fwnode_handle) =
+ fwnode_graph_get_next_endpoint(dev_fwnode(&client->dev), NULL);
ret = v4l2_fwnode_endpoint_parse(endpoint, &sensor->ep);
- fwnode_handle_put(endpoint);
if (ret) {
dev_err(dev, "Could not parse endpoint\n");
return ret;
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3 2/3] media: i2c: imx290: Drop manual fwnode_handle_put() via scope-based cleanup
[not found] ` <20260708134403.45935-5-birenpandya@gmail.com>
2026-07-08 13:44 ` [PATCH v3 1/3] media: i2c: ov5640: use scoped fwnode_handle endpoint cleanup Biren Pandya
@ 2026-07-08 13:44 ` Biren Pandya
2026-07-08 13:44 ` [PATCH v3 3/3] media: i2c: imx219: " Biren Pandya
2 siblings, 0 replies; 8+ messages in thread
From: Biren Pandya @ 2026-07-08 13:44 UTC (permalink / raw)
To: sakari.ailus, mani, mchehab, linux-media, linux-kernel; +Cc: Biren Pandya
Utilize the __free(fwnode_handle) scoped guard macro from
<linux/cleanup.h> to automate the lifecycle management of the endpoint
fwnode in imx290_parse_dt().
This safely ties the release of the fwnode_handle to its compiler
scope, allowing us to drop the manual fwnode_handle_put() call and
removing the risk of missed puts if new early returns are added in
the future.
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
---
Changes in v3:
- Resend as a complete series to fix broken threading.
- Collected Reviewed-by tag.
drivers/media/i2c/imx290.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c
index 21cbc81cb2edc..5c369c7ee21f7 100644
--- a/drivers/media/i2c/imx290.c
+++ b/drivers/media/i2c/imx290.c
@@ -8,6 +8,7 @@
* Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
*/
+#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
@@ -1514,7 +1515,7 @@ static int imx290_parse_dt(struct imx290 *imx290)
struct v4l2_fwnode_endpoint ep = {
.bus_type = V4L2_MBUS_CSI2_DPHY
};
- struct fwnode_handle *endpoint;
+ struct fwnode_handle *endpoint __free(fwnode_handle) = NULL;
int ret;
s64 fq;
@@ -1527,7 +1528,6 @@ static int imx290_parse_dt(struct imx290 *imx290)
}
ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, &ep);
- fwnode_handle_put(endpoint);
if (ret == -ENXIO) {
dev_err(imx290->dev, "Unsupported bus type, should be CSI2\n");
goto done;
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v3 3/3] media: i2c: imx219: Drop manual fwnode_handle_put() via scope-based cleanup
[not found] ` <20260708134403.45935-5-birenpandya@gmail.com>
2026-07-08 13:44 ` [PATCH v3 1/3] media: i2c: ov5640: use scoped fwnode_handle endpoint cleanup Biren Pandya
2026-07-08 13:44 ` [PATCH v3 2/3] media: i2c: imx290: Drop manual fwnode_handle_put() via scope-based cleanup Biren Pandya
@ 2026-07-08 13:44 ` Biren Pandya
2 siblings, 0 replies; 8+ messages in thread
From: Biren Pandya @ 2026-07-08 13:44 UTC (permalink / raw)
To: sakari.ailus, dave.stevenson, mchehab, linux-media, linux-kernel
Cc: Biren Pandya
Utilize the __free(fwnode_handle) scoped guard macro from
<linux/cleanup.h> to automate the lifecycle management of the endpoint
fwnode in imx219_check_hwcfg().
This inherently guarantees that the endpoint node is released when it
goes out of scope. Consequently, the manual fwnode_handle_put() call
in the error_out label is no longer needed and has been removed.
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
---
Changes in v3:
- Resend as a complete series to fix broken threading.
- Collected Reviewed-by tag.
drivers/media/i2c/imx219.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index 7da02ce5da154..d76eae880d730 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -14,6 +14,7 @@
*
*/
+#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
@@ -1110,7 +1111,7 @@ static int imx219_identify_module(struct imx219 *imx219)
static int imx219_check_hwcfg(struct device *dev, struct imx219 *imx219)
{
- struct fwnode_handle *endpoint;
+ struct fwnode_handle *endpoint __free(fwnode_handle) = NULL;
struct v4l2_fwnode_endpoint ep_cfg = {
.bus_type = V4L2_MBUS_CSI2_DPHY
};
@@ -1172,7 +1173,6 @@ static int imx219_check_hwcfg(struct device *dev, struct imx219 *imx219)
error_out:
v4l2_fwnode_endpoint_free(&ep_cfg);
- fwnode_handle_put(endpoint);
return ret;
}
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-07-08 13:44 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-15 22:30 [PATCH 0/3] media: i2c: Adopt scope-based fwnode_handle_put Biren Pandya
2026-06-15 22:30 ` [PATCH 1/3] media: i2c: ov5640: Drop manual fwnode_handle_put() via scope-based cleanup Biren Pandya
2026-07-08 8:49 ` Sakari Ailus
2026-06-15 22:30 ` [PATCH 2/3] media: i2c: imx290: " Biren Pandya
2026-06-15 22:30 ` [PATCH 3/3] media: i2c: imx219: " Biren Pandya
[not found] ` <20260708134403.45935-5-birenpandya@gmail.com>
2026-07-08 13:44 ` [PATCH v3 1/3] media: i2c: ov5640: use scoped fwnode_handle endpoint cleanup Biren Pandya
2026-07-08 13:44 ` [PATCH v3 2/3] media: i2c: imx290: Drop manual fwnode_handle_put() via scope-based cleanup Biren Pandya
2026-07-08 13:44 ` [PATCH v3 3/3] media: i2c: imx219: " Biren Pandya
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox