Skip to contentSkip to conversation

media: ti: vpe: three small fixes

PATCH In review Felix Gu 2 participants 6 messages Mar 21

Subsystems (2)
lore
Share & tools
lore

Felix Gu

author
#0 lore raw

v2 cover media: ti: vpe: three small fixes

---
Changes in v2:
- EDITME: describe what is new in this series revision.
- EDITME: use bulletpoints and terse descriptions.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Felix Gu (3):
media: ti: vpe: Fix fwnode_handle leak in vip_probe_complete()
media: ti: vpe: Fix the error code of devm_request_irq()
media: ti: vpe: Fix the error code of devm_kzalloc() in vip_probe_slice()

 drivers/media/platform/ti/vpe/vip.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

---
base-commit: 95c541ddfb0815a0ea8477af778bb13bb075079a
change-id: 20260317-vip-a2f601930065

Best regards,

Signature · 1 line
Felix Gu <[email protected]>
author
#1 lore raw

PATCH v2 1/3 media: ti: vpe: Fix fwnode_handle leak in vip_probe_complete()

In vip_probe_complete(), the fwnode_handle reference is not released if the loop continues via the default switch case or if alloc_port() fails. This results in a reference count leak.

Switch to using the __free(fwnode_handle) cleanup attribute to ensure the reference is automatically released when the handle goes out of scope.

Fixes fc2873aa4a21 ("media: ti: vpe: Add the VIP driver")
---
 drivers/media/platform/ti/vpe/vip.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/media/platform/ti/vpe/vip.c +3 -4
index a4b616a5ece7..4fe9e059313b 100644
@@ -9,6 +9,7 @@
  */
 
 #include <linux/clk.h>
+#include <linux/cleanup.h>
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
 #include <linux/err.h>
@@ -3389,7 +3390,6 @@ static int vip_probe_complete(struct platform_device *pdev)
 	struct vip_port *port;
 	struct vip_dev *dev;
 	struct device_node *parent = pdev->dev.of_node;
-	struct fwnode_handle *ep = NULL;
 	unsigned int syscon_args[5];
 	int ret, i, slice_id, port_id, p;
 
@@ -3411,8 +3411,8 @@ static int vip_probe_complete(struct platform_device *pdev)
 		ctrl->syscon_bit_field[i] = syscon_args[i + 1];
 
 	for (p = 0; p < (VIP_NUM_PORTS * VIP_NUM_SLICES); p++) {
-		ep = fwnode_graph_get_next_endpoint_by_regs(of_fwnode_handle(parent),
-							    p, 0);
+		struct fwnode_handle *ep __free(fwnode_handle) =
+			fwnode_graph_get_next_endpoint_by_regs(of_fwnode_handle(parent), p, 0);
 		if (!ep)
 			continue;
 
@@ -3447,7 +3447,6 @@ static int vip_probe_complete(struct platform_device *pdev)
 		port = dev->ports[port_id];
 
 		vip_register_subdev_notify(port, ep);
-		fwnode_handle_put(ep);
 	}
 	return 0;
 }
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH v2 2/3 media: ti: vpe: Fix the error code of devm_request_irq()

In reply to Felix Gu

Return the actual error code from devm_request_irq() instead of incorrectly returning -ENOMEM.

Fixes fc2873aa4a21 ("media: ti: vpe: Add the VIP driver")
---
 drivers/media/platform/ti/vpe/vip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/ti/vpe/vip.c +1 -1
index 4fe9e059313b..ea65b7ec9b09 100644
@@ -3471,7 +3471,7 @@ static int vip_probe_slice(struct platform_device *pdev, int slice)
 	ret = devm_request_irq(&pdev->dev, dev->irq, vip_irq,
 			       0, VIP_MODULE_NAME, dev);
 	if (ret < 0)
-		return -ENOMEM;
+		return ret;
 
 	spin_lock_init(&dev->slock);
 	mutex_init(&dev->mutex);
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH v2 2/3] media: ti: vpe: Fix the error code of devm_request_irq()

Quoted 2 lines

Return the actual error code from devm_request_irq() instead of incorrectly returning -ENOMEM.

Would a summary phrase like “Propagate error code of a devm_request_irq() call in vip_probe_slice()” be more helpful?

Regards,
Markus

author
#4 lore raw

PATCH v2 3/3 media: ti: vpe: Fix the error code of devm_kzalloc() in vip_probe_slice()

In reply to Felix Gu

In vip_probe_slice(), the error check for devm_kzalloc() incorrectly uses PTR_ERR_OR_ZERO() which returns 0 for NULL pointer.

Return -ENOMEM for devm_kzalloc() failure.

Fixes fc2873aa4a21 ("media: ti: vpe: Add the VIP driver")
---
 drivers/media/platform/ti/vpe/vip.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/platform/ti/vpe/vip.c +3 -3
index ea65b7ec9b09..c2da11cc5cfa 100644
@@ -3489,7 +3489,7 @@ static int vip_probe_slice(struct platform_device *pdev, int slice)
 
 	parser = devm_kzalloc(&pdev->dev, sizeof(*dev->parser), GFP_KERNEL);
 	if (!parser)
-		return PTR_ERR_OR_ZERO(parser);
+		return -ENOMEM;
 
 	parser->base = dev->base + (slice ? VIP_SLICE1_PARSER : VIP_SLICE0_PARSER);
 	if (IS_ERR(parser->base))
@@ -3501,7 +3501,7 @@ static int vip_probe_slice(struct platform_device *pdev, int slice)
 	dev->sc_assigned = VIP_NOT_ASSIGNED;
 	sc = devm_kzalloc(&pdev->dev, sizeof(*dev->sc), GFP_KERNEL);
 	if (!sc)
-		return PTR_ERR_OR_ZERO(sc);
+		return -ENOMEM;
 
 	sc->base = dev->base + (slice ? VIP_SLICE1_SC : VIP_SLICE0_SC);
 	if (IS_ERR(sc->base))
@@ -3513,7 +3513,7 @@ static int vip_probe_slice(struct platform_device *pdev, int slice)
 	dev->csc_assigned = VIP_NOT_ASSIGNED;
 	csc = devm_kzalloc(&pdev->dev, sizeof(*dev->csc), GFP_KERNEL);
 	if (!csc)
-		return PTR_ERR_OR_ZERO(csc);
+		return -ENOMEM;
 
 	csc->base = dev->base + (slice ? VIP_SLICE1_CSC : VIP_SLICE0_CSC);
 	if (IS_ERR(csc->base))
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH v2 3/3] media: ti: vpe: Fix the error code of devm_kzalloc() in vip_probe_slice()

Quoted 2 lines

In vip_probe_slice(), the error check for devm_kzalloc() incorrectly uses PTR_ERR_OR_ZERO() which returns 0 for NULL pointer.

…

I find such a change description still improvable.
Return statements should be corrected because a corresponding failure predicate is known already for the called function.
https://elixir.bootlin.com/linux/v7.0-rc4/source/include/linux/device/devres.h#L48-L51
https://elixir.bootlin.com/linux/v7.0-rc4/source/drivers/media/platform/ti/vpe/vip.c#L3455-L3527

Regards,
Markus