media: ti: j721e-csi2rx: Minor cleanup of loop variables
Subsystems (2)
PATCH 1/1 media: ti: j721e-csi2rx: Minor cleanup of loop variables
Replace open-coded i--; for (; i >= 0; i--) patterns with the idiomatic while (i--) in the error unwind paths of csi_async_notifier_complete() and ti_csi2rx_probe().
Also scope loop variables directly in the for statement instead of declaring them at the top of the function in ti_csi2rx_suspend(), ti_csi2rx_resume() and ti_csi2rx_remove(). Change the type to unsigned int in the first two to match csi->num_ctx.
---
This patch depends on [1]
[1]: https://lore.kernel.org/all/[email protected]/
.../platform/ti/j721e-csi2rx/j721e-csi2rx.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c +7 -10
@@ -485,8 +485,7 @@ static int csi_async_notifier_complete(struct v4l2_async_notifier *notifier)return 0 ; unregister_dev: - i--; -for (; i >=0 ; i--) { +while (i--) {media_entity_remove_links (&csi->ctx[i].vdev.entity);video_unregister_device (&csi->ctx[i].vdev); }
@@ -1552,7 +1551,7 @@ static int ti_csi2rx_suspend(struct device *dev)struct ti_csi2rx_ctx *ctx;struct ti_csi2rx_dma *dma;unsigned long flags =0 ; -int i, ret =0 ; +int ret =0 ;/* If device was not in use we can simply suspend */ if (pm_runtime_status_suspended (dev))
@@ -1564,7 +1563,7 @@ static int ti_csi2rx_suspend(struct device *dev)*/ writel (0 , csi->shim +SHIM_CNTL ); -for (i =0 ; i < csi->num_ctx; i++) { +for (unsigned int i =0 ; i < csi->num_ctx; i++) { ctx = &csi->ctx[i]; dma = &ctx->dma;
@@ -1604,7 +1603,7 @@ static int ti_csi2rx_resume(struct device *dev)struct ti_csi2rx_buffer *buf;unsigned long flags =0 ;unsigned int reg; -int i, ret =0 ; +int ret =0 ;/* If device was not in use, we can simply wakeup */ if (pm_runtime_status_suspended (dev))
@@ -1614,7 +1613,7 @@ static int ti_csi2rx_resume(struct device *dev) reg =SHIM_CNTL_PIX_RST ;writel (reg, csi->shim +SHIM_CNTL ); -for (i =0 ; i < csi->num_ctx; i++) { +for (unsigned int i =0 ; i < csi->num_ctx; i++) { ctx = &csi->ctx[i]; dma = &ctx->dma;spin_lock_irqsave (&dma->lock, flags);
@@ -1755,8 +1754,7 @@ static int ti_csi2rx_probe(struct platform_device *pdev) err_notifier:ti_csi2rx_cleanup_notifier (csi); err_ctx: - i--; -for (; i >=0 ; i--) +while (i--)ti_csi2rx_cleanup_ctx (&csi->ctx[i]);ti_csi2rx_cleanup_v4l2 (csi); err_dma_chan:
@@ -1768,12 +1766,11 @@ static int ti_csi2rx_probe(struct platform_device *pdev)static void ti_csi2rx_remove (struct platform_device *pdev) {struct ti_csi2rx_dev *csi =platform_get_drvdata (pdev); -unsigned int i;if (!pm_runtime_status_suspended (&pdev->dev))pm_runtime_set_suspended (&pdev->dev); -for (i =0 ; i < csi->num_ctx; i++) +for (unsigned int i =0 ; i < csi->num_ctx; i++)ti_csi2rx_cleanup_ctx (&csi->ctx[i]);ti_csi2rx_cleanup_notifier (csi);
Signature · 1 line
2.34.1
Quoting Rishikesh Donadkar (2026-05-20 15:57:05)
Quoted 10 lines
Replace open-coded
i--; for (; i >= 0; i--)patterns with the idiomaticwhile (i--)in the error unwind paths ofcsi_async_notifier_complete()andti_csi2rx_probe().Also scope loop variables directly in the for statement instead of declaring them at the top of the function in
ti_csi2rx_suspend(),ti_csi2rx_resume()andti_csi2rx_remove(). Change the type to unsigned int in the first two to matchcsi->num_ctx.Signed-off-by Rishikesh Donadkar <[email protected]>
Quoted 85 lines
---
This patch depends on [1][1]: https://lore.kernel.org/all/[email protected]/
.../platform/ti/j721e-csi2rx/j721e-csi2rx.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c +7
-10@@ -485,8 +485,7 @@ static int csi_async_notifier_complete(struct v4l2_async_notifier *notifier)return 0 ; unregister_dev: - i--; -for (; i >=0 ; i--) { +while (i--) {media_entity_remove_links (&csi->ctx[i].vdev.entity);video_unregister_device (&csi->ctx[i].vdev); }@@ -1552,7 +1551,7 @@ static int ti_csi2rx_suspend(struct device *dev)struct ti_csi2rx_ctx *ctx;struct ti_csi2rx_dma *dma;unsigned long flags =0 ; -int i, ret =0 ; +int ret =0 ;/* If device was not in use we can simply suspend */ if (pm_runtime_status_suspended (dev))@@ -1564,7 +1563,7 @@ static int ti_csi2rx_suspend(struct device *dev)*/ writel (0 , csi->shim +SHIM_CNTL ); -for (i =0 ; i < csi->num_ctx; i++) { +for (unsigned int i =0 ; i < csi->num_ctx; i++) { ctx = &csi->ctx[i]; dma = &ctx->dma;@@ -1604,7 +1603,7 @@ static int ti_csi2rx_resume(struct device *dev)struct ti_csi2rx_buffer *buf;unsigned long flags =0 ;unsigned int reg; -int i, ret =0 ; +int ret =0 ;/* If device was not in use, we can simply wakeup */ if (pm_runtime_status_suspended (dev))@@ -1614,7 +1613,7 @@ static int ti_csi2rx_resume(struct device *dev) reg =SHIM_CNTL_PIX_RST ;writel (reg, csi->shim +SHIM_CNTL ); -for (i =0 ; i < csi->num_ctx; i++) { +for (unsigned int i =0 ; i < csi->num_ctx; i++) { ctx = &csi->ctx[i]; dma = &ctx->dma;spin_lock_irqsave (&dma->lock, flags);@@ -1755,8 +1754,7 @@ static int ti_csi2rx_probe(struct platform_device *pdev) err_notifier:ti_csi2rx_cleanup_notifier (csi); err_ctx: - i--; -for (; i >=0 ; i--) +while (i--)ti_csi2rx_cleanup_ctx (&csi->ctx[i]);ti_csi2rx_cleanup_v4l2 (csi); err_dma_chan:@@ -1768,12 +1766,11 @@ static int ti_csi2rx_probe(struct platform_device *pdev)static void ti_csi2rx_remove (struct platform_device *pdev) {struct ti_csi2rx_dev *csi =platform_get_drvdata (pdev); -unsigned int i;if (!pm_runtime_status_suspended (&pdev->dev))pm_runtime_set_suspended (&pdev->dev); -for (i =0 ; i < csi->num_ctx; i++) +for (unsigned int i =0 ; i < csi->num_ctx; i++)ti_csi2rx_cleanup_ctx (&csi->ctx[i]);ti_csi2rx_cleanup_notifier (csi);Signature · 1 line
2.34.1
Hi,
Quoted 10 lines · Rishikesh Donadkar
Replace open-coded
i--; for (; i >= 0; i--)patterns with the idiomaticwhile (i--)in the error unwind paths ofcsi_async_notifier_complete()andti_csi2rx_probe().Also scope loop variables directly in the for statement instead of declaring them at the top of the function in
ti_csi2rx_suspend(),ti_csi2rx_resume()andti_csi2rx_remove(). Change the type to unsigned int in the first two to matchcsi->num_ctx.Signed-off-by Rishikesh Donadkar <[email protected]>
Tomi
Quoted 82 lines
---
This patch depends on [1][1]: https://lore.kernel.org/all/[email protected]/
.../platform/ti/j721e-csi2rx/j721e-csi2rx.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c +7
-10@@ -485,8 +485,7 @@ static int csi_async_notifier_complete(struct v4l2_async_notifier *notifier)return 0 ; unregister_dev: - i--; -for (; i >=0 ; i--) { +while (i--) {media_entity_remove_links (&csi->ctx[i].vdev.entity);video_unregister_device (&csi->ctx[i].vdev); }@@ -1552,7 +1551,7 @@ static int ti_csi2rx_suspend(struct device *dev)struct ti_csi2rx_ctx *ctx;struct ti_csi2rx_dma *dma;unsigned long flags =0 ; -int i, ret =0 ; +int ret =0 ;/* If device was not in use we can simply suspend */ if (pm_runtime_status_suspended (dev))@@ -1564,7 +1563,7 @@ static int ti_csi2rx_suspend(struct device *dev)*/ writel (0 , csi->shim +SHIM_CNTL ); -for (i =0 ; i < csi->num_ctx; i++) { +for (unsigned int i =0 ; i < csi->num_ctx; i++) { ctx = &csi->ctx[i]; dma = &ctx->dma;@@ -1604,7 +1603,7 @@ static int ti_csi2rx_resume(struct device *dev)struct ti_csi2rx_buffer *buf;unsigned long flags =0 ;unsigned int reg; -int i, ret =0 ; +int ret =0 ;/* If device was not in use, we can simply wakeup */ if (pm_runtime_status_suspended (dev))@@ -1614,7 +1613,7 @@ static int ti_csi2rx_resume(struct device *dev) reg =SHIM_CNTL_PIX_RST ;writel (reg, csi->shim +SHIM_CNTL ); -for (i =0 ; i < csi->num_ctx; i++) { +for (unsigned int i =0 ; i < csi->num_ctx; i++) { ctx = &csi->ctx[i]; dma = &ctx->dma;spin_lock_irqsave (&dma->lock, flags);@@ -1755,8 +1754,7 @@ static int ti_csi2rx_probe(struct platform_device *pdev) err_notifier:ti_csi2rx_cleanup_notifier (csi); err_ctx: - i--; -for (; i >=0 ; i--) +while (i--)ti_csi2rx_cleanup_ctx (&csi->ctx[i]);ti_csi2rx_cleanup_v4l2 (csi); err_dma_chan:@@ -1768,12 +1766,11 @@ static int ti_csi2rx_probe(struct platform_device *pdev)static void ti_csi2rx_remove (struct platform_device *pdev) {struct ti_csi2rx_dev *csi =platform_get_drvdata (pdev); -unsigned int i;if (!pm_runtime_status_suspended (&pdev->dev))pm_runtime_set_suspended (&pdev->dev); -for (i =0 ; i < csi->num_ctx; i++) +for (unsigned int i =0 ; i < csi->num_ctx; i++)ti_csi2rx_cleanup_ctx (&csi->ctx[i]);ti_csi2rx_cleanup_notifier (csi);