Re: [PATCH] media: rzg2l-cru: Replace usleep_range with udelay

From: Laurent Pinchart
Date: Tue Dec 02 2025 - 21:36:27 EST


Hi Tommaso,

Thank you for the patch.

On Tue, Dec 02, 2025 at 05:08:41PM +0100, Tommaso Merciai wrote:
> `usleep_range()` should not be used in atomic contexts like between
> spin_lock_irqsave()/spin_lock_irqrestore() pair inside function
> rzg2l_cru_stop_image_processing(). That may cause scheduling while
> atomic bug.
>
> Signed-off-by: Khai Nguyen <khai.nguyen.wx@xxxxxxxxxxx>
> Signed-off-by: Hao Bui <hao.bui.yg@xxxxxxxxxxx>
> Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@xxxxxxxxxxxxxx>
> ---
> drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
> index 162e2ace6931..1355bfd186d4 100644
> --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
> +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
> @@ -369,7 +369,7 @@ void rzg2l_cru_stop_image_processing(struct rzg2l_cru_dev *cru)
> if (cru->info->fifo_empty(cru))
> break;
>
> - usleep_range(10, 20);
> + udelay(10);

There's an instance of msleep() earlier in this function, surrounded by
spin_unlock_irqrestore() and spin_lock_irqsave(). I wondered if we
should do the same here, but that lead to a second question: why does
the driver need to cover the whole stop procedure with a spinlock in the
first place ?

> }
>
> /* Notify that FIFO is not empty here */
> @@ -385,7 +385,7 @@ void rzg2l_cru_stop_image_processing(struct rzg2l_cru_dev *cru)
> AMnAXISTPACK_AXI_STOP_ACK)
> break;
>
> - usleep_range(10, 20);
> + udelay(10);
> }
>
> /* Notify that AXI bus can not stop here */

--
Regards,

Laurent Pinchart