[PATCH 1/3] media: i2c: ov5640: Drop manual fwnode_handle_put() via scope-based cleanup
From: Biren Pandya
Date: Mon Jun 15 2026 - 18:33:44 EST
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@xxxxxxxxx>
---
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)