2024-05-02 21:00:57

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 0/2] fpga: use 'time_left' instead of 'timeout' with wait_for_*() functions

There is a confusing pattern in the kernel to use a variable named 'timeout' to
store the result of wait_for_*() functions causing patterns like:

timeout = wait_for_completion_timeout(...)
if (!timeout) return -ETIMEDOUT;

with all kinds of permutations. Use 'time_left' as a variable to make the code
obvious and self explaining.

This is part of a tree-wide series. The rest of the patches can be found here
(some parts may still be WIP):

git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/time_left

Because these patches are generated, I audit them before sending. This is why I
will send series step by step. Build bot is happy with these patches, though.
No functional changes intended.

Wolfram Sang (2):
fpga: socfpga: use 'time_left' variable with
wait_for_completion_interruptible_timeout()
fpga: zynq-fpga: use 'time_left' variable with
wait_for_completion_timeout()

drivers/fpga/socfpga.c | 7 ++++---
drivers/fpga/zynq-fpga.c | 8 ++++----
2 files changed, 8 insertions(+), 7 deletions(-)

--
2.43.0



2024-05-02 21:00:56

by Wolfram Sang

[permalink] [raw]
Subject: [PATCH 2/2] fpga: zynq-fpga: use 'time_left' variable with wait_for_completion_timeout()

There is a confusing pattern in the kernel to use a variable named 'timeout' to
store the result of wait_for_completion_timeout() causing patterns like:

timeout = wait_for_completion_timeout(...)
if (!timeout) return -ETIMEDOUT;

with all kinds of permutations. Use 'time_left' as a variable to make the code
self explaining.

Signed-off-by: Wolfram Sang <[email protected]>
---
drivers/fpga/zynq-fpga.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/fpga/zynq-fpga.c b/drivers/fpga/zynq-fpga.c
index 0ac93183d201..4db3d80e10b0 100644
--- a/drivers/fpga/zynq-fpga.c
+++ b/drivers/fpga/zynq-fpga.c
@@ -387,7 +387,7 @@ static int zynq_fpga_ops_write(struct fpga_manager *mgr, struct sg_table *sgt)
const char *why;
int err;
u32 intr_status;
- unsigned long timeout;
+ unsigned long time_left;
unsigned long flags;
struct scatterlist *sg;
int i;
@@ -427,8 +427,8 @@ static int zynq_fpga_ops_write(struct fpga_manager *mgr, struct sg_table *sgt)
zynq_step_dma(priv);
spin_unlock_irqrestore(&priv->dma_lock, flags);

- timeout = wait_for_completion_timeout(&priv->dma_done,
- msecs_to_jiffies(DMA_TIMEOUT_MS));
+ time_left = wait_for_completion_timeout(&priv->dma_done,
+ msecs_to_jiffies(DMA_TIMEOUT_MS));

spin_lock_irqsave(&priv->dma_lock, flags);
zynq_fpga_set_irq(priv, 0);
@@ -452,7 +452,7 @@ static int zynq_fpga_ops_write(struct fpga_manager *mgr, struct sg_table *sgt)

if (priv->cur_sg ||
!((intr_status & IXR_D_P_DONE_MASK) == IXR_D_P_DONE_MASK)) {
- if (timeout == 0)
+ if (time_left == 0)
why = "DMA timed out";
else
why = "DMA did not complete";
--
2.43.0


2024-05-06 08:09:46

by Michal Simek

[permalink] [raw]
Subject: Re: [PATCH 2/2] fpga: zynq-fpga: use 'time_left' variable with wait_for_completion_timeout()



On 5/2/24 23:00, Wolfram Sang wrote:
> There is a confusing pattern in the kernel to use a variable named 'timeout' to
> store the result of wait_for_completion_timeout() causing patterns like:
>
> timeout = wait_for_completion_timeout(...)
> if (!timeout) return -ETIMEDOUT;
>
> with all kinds of permutations. Use 'time_left' as a variable to make the code
> self explaining.
>
> Signed-off-by: Wolfram Sang <[email protected]>
> ---
> drivers/fpga/zynq-fpga.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/fpga/zynq-fpga.c b/drivers/fpga/zynq-fpga.c
> index 0ac93183d201..4db3d80e10b0 100644
> --- a/drivers/fpga/zynq-fpga.c
> +++ b/drivers/fpga/zynq-fpga.c
> @@ -387,7 +387,7 @@ static int zynq_fpga_ops_write(struct fpga_manager *mgr, struct sg_table *sgt)
> const char *why;
> int err;
> u32 intr_status;
> - unsigned long timeout;
> + unsigned long time_left;
> unsigned long flags;
> struct scatterlist *sg;
> int i;
> @@ -427,8 +427,8 @@ static int zynq_fpga_ops_write(struct fpga_manager *mgr, struct sg_table *sgt)
> zynq_step_dma(priv);
> spin_unlock_irqrestore(&priv->dma_lock, flags);
>
> - timeout = wait_for_completion_timeout(&priv->dma_done,
> - msecs_to_jiffies(DMA_TIMEOUT_MS));
> + time_left = wait_for_completion_timeout(&priv->dma_done,
> + msecs_to_jiffies(DMA_TIMEOUT_MS));
>
> spin_lock_irqsave(&priv->dma_lock, flags);
> zynq_fpga_set_irq(priv, 0);
> @@ -452,7 +452,7 @@ static int zynq_fpga_ops_write(struct fpga_manager *mgr, struct sg_table *sgt)
>
> if (priv->cur_sg ||
> !((intr_status & IXR_D_P_DONE_MASK) == IXR_D_P_DONE_MASK)) {
> - if (timeout == 0)
> + if (time_left == 0)
> why = "DMA timed out";
> else
> why = "DMA did not complete";

Acked-by: Michal Simek <[email protected]>

Thanks,
Michal