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

Felix Gu posted 3 patches 1 week, 6 days ago
[PATCH v2 3/3] media: ti: vpe: Fix the error code of devm_kzalloc() in vip_probe_slice()
Posted by Felix Gu 1 week, 6 days ago
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")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/media/platform/ti/vpe/vip.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/ti/vpe/vip.c b/drivers/media/platform/ti/vpe/vip.c
index ea65b7ec9b09..c2da11cc5cfa 100644
--- a/drivers/media/platform/ti/vpe/vip.c
+++ b/drivers/media/platform/ti/vpe/vip.c
@@ -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))

-- 
2.43.0
Re: [PATCH v2 3/3] media: ti: vpe: Fix the error code of devm_kzalloc() in vip_probe_slice()
Posted by Markus Elfring 1 week, 6 days ago
> 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