Skip to contentSkip to conversation

staging: media: meson: vdec: propagate devm_clk_get() errors

PATCH In review Alfie Varghese 3 participants 3 messages Jul 17

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

PATCH v3 1/1 staging: media: meson: vdec: propagate devm_clk_get() errors

vdec_probe() hardcodes -EPROBE_DEFER for all devm_clk_get() failures. This masks the actual error code returned by the clock framework, such as -ENOENT when a clock is not registered or -ENOMEM on allocation failure.

Return PTR_ERR() instead to propagate the real error to the caller.

---
 drivers/staging/media/meson/vdec/vdec.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/staging/media/meson/vdec/vdec.c +5 -5
index a039d925c0fe..fba1e7f88d81 100644
@@ -1026,24 +1026,24 @@ static int vdec_probe(struct platform_device *pdev)
 	    core->platform->revision == VDEC_REVISION_SM1) {
 		core->vdec_hevcf_clk = devm_clk_get(dev, "vdec_hevcf");
 		if (IS_ERR(core->vdec_hevcf_clk))
-			return -EPROBE_DEFER;
+			return PTR_ERR(core->vdec_hevcf_clk);
 	}
 
 	core->dos_parser_clk = devm_clk_get(dev, "dos_parser");
 	if (IS_ERR(core->dos_parser_clk))
-		return -EPROBE_DEFER;
+		return PTR_ERR(core->dos_parser_clk);
 
 	core->dos_clk = devm_clk_get(dev, "dos");
 	if (IS_ERR(core->dos_clk))
-		return -EPROBE_DEFER;
+		return PTR_ERR(core->dos_clk);
 
 	core->vdec_1_clk = devm_clk_get(dev, "vdec_1");
 	if (IS_ERR(core->vdec_1_clk))
-		return -EPROBE_DEFER;
+		return PTR_ERR(core->vdec_1_clk);
 
 	core->vdec_hevc_clk = devm_clk_get(dev, "vdec_hevc");
 	if (IS_ERR(core->vdec_hevc_clk))
-		return -EPROBE_DEFER;
+		return PTR_ERR(core->vdec_hevc_clk);
 
 	irq = platform_get_irq_byname(pdev, "vdec");
 	if (irq < 0)
Signature · 1 line
2.54.0.windows.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [Critical] The driver holds an unpinned pointer to the amlogic-canvas provider, leading to a Use-After-Free vulnerability if the canvas driver is unbound.
- [High] The vdec_isr and vdec_threaded_isr interrupt handlers unconditionally dereference core->cur_sess. If an interrupt fires immediately upon registration (e.g., left pending by the bootloader), this will cause a fatal NULL pointer dereference because core->cur_sess is initialized to NULL. --

--- Patch [1]: [PATCH v3] staging: media: meson: vdec: propagate devm_clk_get() errors --- commit 9a8ffbf8f058a33cad3c2292a9632f5eb5e8f843
Author: Alfie Varghese <[email protected]>

staging: media: meson: vdec: propagate devm_clk_get() errors

vdec_probe() hardcodes -EPROBE_DEFER for all devm_clk_get() failures. This masks the actual error code returned by the clock framework, such as -ENOENT when a clock is not registered or -ENOMEM on allocation failure. Return PTR_ERR() instead to propagate the real error to the caller.

Quoted 5 lines
drivers/staging/media/meson/vdec/vdec.c +0 -0
index a039d925c0fe5..fba1e7f88d81f 100644
@@ -1026,24 +1026,24 @@ static int vdec_probe(struct platform_device *pdev)

[ ... ]

drivers/staging/media/meson/vdec/vdec.c static int vdec_probe(struct platform_device *pdev) · line 1049

Quoted 7 lines
drivers/staging/media/meson/vdec/vdec.c +1 -1
 	core->vdec_hevc_clk = devm_clk_get(dev, "vdec_hevc");
 	if (IS_ERR(core->vdec_hevc_clk))
-		return -EPROBE_DEFER;
+		return PTR_ERR(core->vdec_hevc_clk);
 
 	irq = platform_get_irq_byname(pdev, "vdec");
 	if (irq < 0)

[Severity: Critical]
This is a pre-existing issue, but earlier in vdec_probe() we store a pointer to the canvas device:

	core->canvas = meson_canvas_get(dev);

Looking at drivers/soc/amlogic/meson-canvas.c:meson_canvas_get(), the function drops the reference to the canvas device before returning the driver data pointer:

	canvas = dev_get_drvdata(&canvas_pdev->dev);
	put_device(&canvas_pdev->dev);
	if (!canvas)
		return ERR_PTR(-EINVAL);

	return canvas;

Since there is no device link and no reference is held, is it possible for the amlogic-canvas device to be freely unbound via sysfs, freeing the canvas structure?

If the vdec driver later attempts a video decoding operation, might it access the freed memory and result in a use-after-free?

[Severity: High]
This isn't a bug introduced by this patch, but just below the modified code we request the interrupt without IRQF_NO_AUTOEN:

	ret = devm_request_threaded_irq(core->dev, irq, vdec_isr,
					vdec_threaded_isr, IRQF_ONESHOT,
					"vdec", core);

If there is a pending interrupt left over by the bootloader, it might fire immediately upon registration. The interrupt handler vdec_isr() unconditionally dereferences core->cur_sess:

	struct amvdec_session *sess = core->cur_sess;
	sess->last_irq_jiffies = get_jiffies_64();

Since core->cur_sess is initialized to NULL and only assigned later during streaming, will this lead to a NULL pointer dereference?

Would it be safer to add the IRQF_NO_AUTOEN flag when registering this interrupt?

Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
#2 lore raw
In reply to Alfie Varghese
Quoted 10 lines · Alfie Varghese

vdec_probe() hardcodes -EPROBE_DEFER for all devm_clk_get() failures. This masks the actual error code returned by the clock framework, such as -ENOENT when a clock is not registered or -ENOMEM on allocation failure.

Return PTR_ERR() instead to propagate the real error to the caller.

---

There is supposed to be a note here under the --- cut off line which says what changed. Did you resend just to add my Reviewed-by line?

No need for that.

regards,
dan carpenter