media:cdns-csi2tx: replace of_node_put() with __free
Subsystems (2)
PATCH 1/1 media:cdns-csi2tx: replace of_node_put() with __free
Use the new cleanup magic to replace of_node_put() with __free(device_node) marking to auto release when they get out of scope.
--- drivers/media/platform/cadence/cdns-csi2tx.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
drivers/media/platform/cadence/cdns-csi2tx.c +7 -12
@@ -496,48 +496,43 @@ static int csi2tx_get_resources(struct csi2tx_priv *csi2tx,static int csi2tx_check_lanes (struct csi2tx_priv *csi2tx) {struct v4l2_fwnode_endpoint v4l2_ep = { .bus_type =0 }; -struct device_node *ep;int ret, i; - - ep =of_graph_get_endpoint_by_regs (csi2tx->dev->of_node,0 ,0 ); + struct device_node *ep __free(device_node) = +of_graph_get_endpoint_by_regs (csi2tx->dev->of_node,0 ,0 ); +if (!ep)return -EINVAL ; ret =v4l2_fwnode_endpoint_parse (of_fwnode_handle (ep), &v4l2_ep);if (ret) {dev_err (csi2tx->dev,"Could not parse v4l2 endpoint\n" ); - goto out; +return ret; }if (v4l2_ep.bus_type !=V4L2_MBUS_CSI2_DPHY ) {dev_err (csi2tx->dev,"Unsupported media bus type: 0x%x\n" , v4l2_ep.bus_type); - ret = -EINVAL ; - goto out; +return -EINVAL ; } csi2tx->num_lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes;if (csi2tx->num_lanes > csi2tx->max_lanes) {dev_err (csi2tx->dev,"Current configuration uses more lanes than supported\n" ); - ret = -EINVAL ; - goto out; +return -EINVAL ; }for (i =0 ; i < csi2tx->num_lanes; i++) {if (v4l2_ep.bus.mipi_csi2.data_lanes[i] <1 ) {dev_err (csi2tx->dev,"Invalid lane[%d] number: %u\n" , i, v4l2_ep.bus.mipi_csi2.data_lanes[i]); - ret = -EINVAL ; - goto out; +return -EINVAL ; } }memcpy (csi2tx->lanes, v4l2_ep.bus.mipi_csi2.data_lanes,sizeof (csi2tx->lanes)); -out: -of_node_put (ep);return ret; }
Signature · 1 line
2.34.1
Le 29/04/2024 à 19:15, R Sundar a écrit :
Quoted 57 lines
Use the new cleanup magic to replace
of_node_put()with__free(device_node)marking to auto release when they get out of scope.Suggested-by Julia Lawall <[email protected]>Signed-off-by R Sundar <[email protected]>--- drivers/media/platform/cadence/cdns-csi2tx.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)drivers/media/platform/cadence/cdns-csi2tx.c +6
-10@@ -496,48 +496,43 @@ static int csi2tx_get_resources(struct csi2tx_priv *csi2tx,static int csi2tx_check_lanes (struct csi2tx_priv *csi2tx) {struct v4l2_fwnode_endpoint v4l2_ep = { .bus_type =0 }; -struct device_node *ep;int ret, i; - - ep =of_graph_get_endpoint_by_regs (csi2tx->dev->of_node,0 ,0 ); + struct device_node *ep __free(device_node) = +of_graph_get_endpoint_by_regs (csi2tx->dev->of_node,0 ,0 ); +if (!ep)return -EINVAL ; ret =v4l2_fwnode_endpoint_parse (of_fwnode_handle (ep), &v4l2_ep);if (ret) {dev_err (csi2tx->dev,"Could not parse v4l2 endpoint\n" ); - goto out; +return ret; }if (v4l2_ep.bus_type !=V4L2_MBUS_CSI2_DPHY ) {dev_err (csi2tx->dev,"Unsupported media bus type: 0x%x\n" , v4l2_ep.bus_type); - ret = -EINVAL ; - goto out; +return -EINVAL ; } csi2tx->num_lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes;if (csi2tx->num_lanes > csi2tx->max_lanes) {dev_err (csi2tx->dev,"Current configuration uses more lanes than supported\n" ); - ret = -EINVAL ; - goto out; +return -EINVAL ; }for (i =0 ; i < csi2tx->num_lanes; i++) {if (v4l2_ep.bus.mipi_csi2.data_lanes[i] <1 ) {dev_err (csi2tx->dev,"Invalid lane[%d] number: %u\n" , i, v4l2_ep.bus.mipi_csi2.data_lanes[i]); - ret = -EINVAL ; - goto out;
drivers/media/platform/cadence/cdns-csi2tx.c static int csi2tx_get_resources(struct csi2tx_priv *csi2tx, · line 536
Quoted 10 lines
drivers/media/platform/cadence/cdns-csi2tx.c +1
-2+return -EINVAL ; } }memcpy (csi2tx->lanes, v4l2_ep.bus.mipi_csi2.data_lanes,sizeof (csi2tx->lanes)); -out: -of_node_put (ep);return ret;
Hi,
Nit: return 0; ?
CJ
Quoted 2 lines
drivers/media/platform/cadence/cdns-csi2tx.c +0
-0}
Quoted 66 lines · Christophe JAILLET
Le 29/04/2024 à 19:15, R Sundar a écrit :
Quoted 52 lines
Use the new cleanup magic to replace
of_node_put()with__free(device_node)marking to auto release when they get out of scope.Suggested-by Julia Lawall <[email protected]>Signed-off-by R Sundar <[email protected]>---
drivers/media/platform/cadence/cdns-csi2tx.c| 19 +++++++------------1 file changed, 7 insertions(+), 12 deletions(-)drivers/media/platform/cadence/cdns-csi2tx.c +6
-8@@ -496,48 +496,43 @@ static int csi2tx_get_resources(structcsi2tx_priv *csi2tx, static int csi2tx_check_lanes(struct csi2tx_priv *csi2tx) { struct v4l2_fwnode_endpoint v4l2_ep = { .bus_type = 0 }; - struct device_node *ep; int ret, i; - - ep = of_graph_get_endpoint_by_regs(csi2tx->dev->of_node, 0, 0); + struct device_node *ep __free(device_node) = + of_graph_get_endpoint_by_regs(csi2tx->dev->of_node, 0, 0); + if (!ep) return -EINVAL; ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &v4l2_ep); if (ret) { dev_err(csi2tx->dev, "Could not parse v4l2 endpoint\n"); - goto out; + return ret; } if (v4l2_ep.bus_type != V4L2_MBUS_CSI2_DPHY) { dev_err(csi2tx->dev, "Unsupported media bus type: 0x%x\n", v4l2_ep.bus_type); - ret = -EINVAL; - goto out; + return -EINVAL; } csi2tx->num_lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes; if (csi2tx->num_lanes > csi2tx->max_lanes) { dev_err(csi2tx->dev, "Current configuration uses more lanes than supported\n"); - ret = -EINVAL; - goto out; + return -EINVAL; } for (i = 0; i < csi2tx->num_lanes; i++) { if (v4l2_ep.bus.mipi_csi2.data_lanes[i] < 1) { dev_err(csi2tx->dev, "Invalid lane[%d] number: %u\n", i, v4l2_ep.bus.mipi_csi2.data_lanes[i]);drivers/media/platform/cadence/cdns-csi2tx.c static int csi2tx_get_resources(struct · line 531
Quoted 10 lines
drivers/media/platform/cadence/cdns-csi2tx.c +1
-4- ret = -EINVAL; - goto out; + return -EINVAL; } } memcpy(csi2tx->lanes, v4l2_ep.bus.mipi_csi2.data_lanes, sizeof(csi2tx->lanes)); -out: - of_node_put(ep); return ret;Hi,
Quoted 6 lines
Nit: return 0; ?
CJ
Quoted 1 line
drivers/media/platform/cadence/cdns-csi2tx.c +0
-0}
Hi,
In success case, ret variable value also will be zero, else for non-zero ret value it will return from v4l2_fwnode_endpoint_parse()'s error case handling block.
Thanks,
Sundar
Quoted 72 lines · R Sundar
Quoted 71 lines · Christophe JAILLET
Le 29/04/2024 à 19:15, R Sundar a écrit :
Quoted 53 lines
Use the new cleanup magic to replace
of_node_put()with__free(device_node)marking to auto release when they get out of scope.Suggested-by Julia Lawall <[email protected]>Signed-off-by R Sundar <[email protected]>---
drivers/media/platform/cadence/cdns-csi2tx.c| 19 +++++++------------1 file changed, 7 insertions(+), 12 deletions(-)drivers/media/platform/cadence/cdns-csi2tx.c +6
-8@@ -496,48 +496,43 @@ static int csi2tx_get_resources(struct csi2tx_priv *csi2tx, static int csi2tx_check_lanes(struct csi2tx_priv *csi2tx) { struct v4l2_fwnode_endpoint v4l2_ep = { .bus_type = 0 }; - struct device_node *ep; int ret, i; - - ep = of_graph_get_endpoint_by_regs(csi2tx->dev->of_node, 0, 0); + struct device_node *ep __free(device_node) = + of_graph_get_endpoint_by_regs(csi2tx->dev->of_node, 0, 0); + if (!ep) return -EINVAL; ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &v4l2_ep); if (ret) { dev_err(csi2tx->dev, "Could not parse v4l2 endpoint\n"); - goto out; + return ret; } if (v4l2_ep.bus_type != V4L2_MBUS_CSI2_DPHY) { dev_err(csi2tx->dev, "Unsupported media bus type: 0x%x\n", v4l2_ep.bus_type); - ret = -EINVAL; - goto out; + return -EINVAL; } csi2tx->num_lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes; if (csi2tx->num_lanes > csi2tx->max_lanes) { dev_err(csi2tx->dev, "Current configuration uses more lanes than supported\n"); - ret = -EINVAL; - goto out; + return -EINVAL; } for (i = 0; i < csi2tx->num_lanes; i++) { if (v4l2_ep.bus.mipi_csi2.data_lanes[i] < 1) { dev_err(csi2tx->dev, "Invalid lane[%d] number: %u\n", i, v4l2_ep.bus.mipi_csi2.data_lanes[i]);drivers/media/platform/cadence/cdns-csi2tx.c static int csi2tx_get_resources(struct csi2tx_priv · line 531
Quoted 10 lines
drivers/media/platform/cadence/cdns-csi2tx.c +1
-4- ret = -EINVAL; - goto out; + return -EINVAL; } } memcpy(csi2tx->lanes, v4l2_ep.bus.mipi_csi2.data_lanes, sizeof(csi2tx->lanes)); -out: - of_node_put(ep); return ret;Hi,
Nit: return 0; ?
CJ
Quoted 7 lines
Quoted 2 lines
drivers/media/platform/cadence/cdns-csi2tx.c static int csi2tx_get_resources(struct csi2tx_priv · line 532
Quoted 1 line
drivers/media/platform/cadence/cdns-csi2tx.c +0
-0}Hi,
In success case, ret variable value also will be zero, else for non-zero ret value it will return from v4l2_fwnode_endpoint_parse()'s error case handling block.
Indeed, but it seems that the return ret at the end of the function always returns 0? If that is the case, return 0 would be better, as one can see that that code is only reached in the success case.
julia
Quoted 84 lines · Julia Lawall
Quoted 72 lines · R Sundar
Quoted 71 lines · Christophe JAILLET
Le 29/04/2024 à 19:15, R Sundar a écrit :
Quoted 53 lines
Use the new cleanup magic to replace
of_node_put()with__free(device_node)marking to auto release when they get out of scope.Suggested-by Julia Lawall <[email protected]>Signed-off-by R Sundar <[email protected]>--- drivers/media/platform/cadence/cdns-csi2tx.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)drivers/media/platform/cadence/cdns-csi2tx.c +6
-8@@ -496,48 +496,43 @@ static int csi2tx_get_resources(struct csi2tx_priv *csi2tx, static int csi2tx_check_lanes(struct csi2tx_priv *csi2tx) { struct v4l2_fwnode_endpoint v4l2_ep = { .bus_type = 0 }; - struct device_node *ep; int ret, i; - - ep = of_graph_get_endpoint_by_regs(csi2tx->dev->of_node, 0, 0); + struct device_node *ep __free(device_node) = + of_graph_get_endpoint_by_regs(csi2tx->dev->of_node, 0, 0); + if (!ep) return -EINVAL; ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &v4l2_ep); if (ret) { dev_err(csi2tx->dev, "Could not parse v4l2 endpoint\n"); - goto out; + return ret; } if (v4l2_ep.bus_type != V4L2_MBUS_CSI2_DPHY) { dev_err(csi2tx->dev, "Unsupported media bus type: 0x%x\n", v4l2_ep.bus_type); - ret = -EINVAL; - goto out; + return -EINVAL; } csi2tx->num_lanes = v4l2_ep.bus.mipi_csi2.num_data_lanes; if (csi2tx->num_lanes > csi2tx->max_lanes) { dev_err(csi2tx->dev, "Current configuration uses more lanes than supported\n"); - ret = -EINVAL; - goto out; + return -EINVAL; } for (i = 0; i < csi2tx->num_lanes; i++) { if (v4l2_ep.bus.mipi_csi2.data_lanes[i] < 1) { dev_err(csi2tx->dev, "Invalid lane[%d] number: %u\n", i, v4l2_ep.bus.mipi_csi2.data_lanes[i]);drivers/media/platform/cadence/cdns-csi2tx.c static int csi2tx_get_resources(struct csi2tx_priv · line 531
Quoted 10 lines
drivers/media/platform/cadence/cdns-csi2tx.c +1
-4- ret = -EINVAL; - goto out; + return -EINVAL; } } memcpy(csi2tx->lanes, v4l2_ep.bus.mipi_csi2.data_lanes, sizeof(csi2tx->lanes)); -out: - of_node_put(ep); return ret;Hi,
Nit: return 0; ?
CJ
Quoted 7 lines
Quoted 2 lines
drivers/media/platform/cadence/cdns-csi2tx.c static int csi2tx_get_resources(struct csi2tx_priv · line 532
Quoted 1 line
drivers/media/platform/cadence/cdns-csi2tx.c +0
-0}Hi,
In success case, ret variable value also will be zero, else for non-zero ret value it will return from v4l2_fwnode_endpoint_parse()'s error case handling block.
Quoted 5 lines
Indeed, but it seems that the return ret at the end of the function always returns 0? If that is the case, return 0 would be better, as one can see that that code is only reached in the success case.
julia
Hi Julia,
Noted.
@CJ, Thanks for comments. Understood the point of Nit.
Will update the changes.
Thanks,
Sundar