Skip to contentSkip to conversation

media: nuvoton: Fix some reference handling issues

PATCH New Ricardo Ribalda 1 participant 3 messages Feb 24, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover media: nuvoton: Fix some reference handling issues

When trying out 6.13 cocci, some bugs were found.

---
Changes in v2:
- Squash fixes and port to cleanup.h.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Ricardo Ribalda (2):
media: nuvoton: Fix reference handling of ece_node
media: nuvoton: Fix reference handling of ece_pdev

 drivers/media/platform/nuvoton/npcm-video.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

---
base-commit: c2b96a6818159fba8a3bcc38262da9e77f9b3ec7
change-id: 20250121-nuvoton-fe870cbeffb6

Best regards,

Signature · 1 line
Ricardo Ribalda <[email protected]>
#1 lore raw

PATCH v2 1/2 media: nuvoton: Fix reference handling of ece_node

Make sure all the code paths call of_node_put().

Instead of manually calling of_node_put, use the __free macros/helpers.

Fixes 46c15a4ff1f4 ("media: nuvoton: Add driver for NPCM video capture and encoding engine")
---
 drivers/media/platform/nuvoton/npcm-video.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/platform/nuvoton/npcm-video.c +1 -2
index 024cd8ee1709..0547f119c38f 100644
@@ -1648,8 +1648,8 @@ static int npcm_video_setup_video(struct npcm_video *video)
 
 static int npcm_video_ece_init(struct npcm_video *video)
 {
+	struct device_node *ece_node __free(device_node) = NULL;
 	struct device *dev = video->dev;
-	struct device_node *ece_node;
 	struct platform_device *ece_pdev;
 	void __iomem *regs;
 
@@ -1669,7 +1669,6 @@ static int npcm_video_ece_init(struct npcm_video *video)
 			dev_err(dev, "Failed to find ECE device\n");
 			return -ENODEV;
 		}
-		of_node_put(ece_node);
 
 		regs = devm_platform_ioremap_resource(ece_pdev, 0);
 		if (IS_ERR(regs)) {
Signature · 1 line
2.48.1.601.g30ceb7b040-goog
#2 lore raw

PATCH v2 2/2 media: nuvoton: Fix reference handling of ece_pdev

In reply to Ricardo Ribalda

When we obtain a reference to of a platform_device, we need to release it via put_device.

Found by cocci:
./platform/nuvoton/npcm-video.c:1677:3-9: ERROR: missing put_device; call of_find_device_by_node on line 1667, but without a corresponding object release within this function. ./platform/nuvoton/npcm-video.c:1684:3-9: ERROR: missing put_device; call of_find_device_by_node on line 1667, but without a corresponding object release within this function. ./platform/nuvoton/npcm-video.c:1690:3-9: ERROR: missing put_device; call of_find_device_by_node on line 1667, but without a corresponding object release within this function. ./platform/nuvoton/npcm-video.c:1694:1-7: ERROR: missing put_device; call of_find_device_by_node on line 1667, but without a corresponding object release within this function.

Instead of manually calling put_device, use the __free macros.

Fixes 46c15a4ff1f4 ("media: nuvoton: Add driver for NPCM video capture and encoding engine")
---
 drivers/media/platform/nuvoton/npcm-video.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/nuvoton/npcm-video.c +2 -1
index 0547f119c38f..7a9d8928ae40 100644
@@ -1669,6 +1669,7 @@ static int npcm_video_ece_init(struct npcm_video *video)
 			dev_err(dev, "Failed to find ECE device\n");
 			return -ENODEV;
 		}
+		struct device *ece_dev __free(put_device) = &ece_pdev->dev;
 
 		regs = devm_platform_ioremap_resource(ece_pdev, 0);
 		if (IS_ERR(regs)) {
@@ -1683,7 +1684,7 @@ static int npcm_video_ece_init(struct npcm_video *video)
 			return PTR_ERR(video->ece.regmap);
 		}
 
-		video->ece.reset = devm_reset_control_get(&ece_pdev->dev, NULL);
+		video->ece.reset = devm_reset_control_get(ece_dev, NULL);
 		if (IS_ERR(video->ece.reset)) {
 			dev_err(dev, "Failed to get ECE reset control in DTS\n");
 			return PTR_ERR(video->ece.reset);
Signature · 1 line
2.48.1.601.g30ceb7b040-goog