* [PATCH] staging: gpib: Remove a dead condition in if statement
@ 2024-10-15 20:06 Everest K.C.
2024-10-15 22:47 ` Shuah Khan
2024-10-16 7:38 ` Greg KH
0 siblings, 2 replies; 4+ messages in thread
From: Everest K.C. @ 2024-10-15 20:06 UTC (permalink / raw)
To: dpenkler, gregkh; +Cc: Everest K.C., skhan, linux-staging, linux-kernel
The variable `residue` is an unsigned int, also the function
`fluke_get_dma_residue` returns an unsigned int. The value of
an unsigned int can only be 0 at minimum.
The less-than-zero comparision can never be true.
Fix it by removing the dead condition in the if statement.
This issue was reported by Coverity Scan.
Report:
CID 1600782: (#1 of 1): Macro compares unsigned to 0 (NO_EFFECT)
unsigned_compare: This less-than-zero comparison of an unsigned value
is never true. residue < 0U.
Fixes: 55936779f496 ("staging: gpib: Add Fluke cda based cards GPIB driver")
Signed-off-by: Everest K.C. <everestkc@everestkc.com.np>
---
drivers/staging/gpib/eastwood/fluke_gpib.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/gpib/eastwood/fluke_gpib.c b/drivers/staging/gpib/eastwood/fluke_gpib.c
index f9f149db222d..51b4f9891a34 100644
--- a/drivers/staging/gpib/eastwood/fluke_gpib.c
+++ b/drivers/staging/gpib/eastwood/fluke_gpib.c
@@ -644,7 +644,7 @@ static int fluke_dma_read(gpib_board_t *board, uint8_t *buffer,
*/
usleep_range(10, 15);
residue = fluke_get_dma_residue(e_priv->dma_channel, dma_cookie);
- if (WARN_ON_ONCE(residue > length || residue < 0))
+ if (WARN_ON_ONCE(residue > length))
return -EFAULT;
*bytes_read += length - residue;
dmaengine_terminate_all(e_priv->dma_channel);
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] staging: gpib: Remove a dead condition in if statement
2024-10-15 20:06 [PATCH] staging: gpib: Remove a dead condition in if statement Everest K.C.
@ 2024-10-15 22:47 ` Shuah Khan
2024-10-15 23:50 ` Everest K.C.
2024-10-16 7:38 ` Greg KH
1 sibling, 1 reply; 4+ messages in thread
From: Shuah Khan @ 2024-10-15 22:47 UTC (permalink / raw)
To: Everest K.C., dpenkler, gregkh; +Cc: linux-staging, linux-kernel, Shuah Khan
On 10/15/24 14:06, Everest K.C. wrote:
> The variable `residue` is an unsigned int, also the function
> `fluke_get_dma_residue` returns an unsigned int. The value of
> an unsigned int can only be 0 at minimum.
> The less-than-zero comparision can never be true.
> Fix it by removing the dead condition in the if statement.
>
> This issue was reported by Coverity Scan.
> Report:
> CID 1600782: (#1 of 1): Macro compares unsigned to 0 (NO_EFFECT)
> unsigned_compare: This less-than-zero comparison of an unsigned value
> is never true. residue < 0U.
>
> Fixes: 55936779f496 ("staging: gpib: Add Fluke cda based cards GPIB driver")
> Signed-off-by: Everest K.C. <everestkc@everestkc.com.np>
> ---
> drivers/staging/gpib/eastwood/fluke_gpib.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/gpib/eastwood/fluke_gpib.c b/drivers/staging/gpib/eastwood/fluke_gpib.c
> index f9f149db222d..51b4f9891a34 100644
> --- a/drivers/staging/gpib/eastwood/fluke_gpib.c
> +++ b/drivers/staging/gpib/eastwood/fluke_gpib.c
> @@ -644,7 +644,7 @@ static int fluke_dma_read(gpib_board_t *board, uint8_t *buffer,
> */
> usleep_range(10, 15);
> residue = fluke_get_dma_residue(e_priv->dma_channel, dma_cookie);
> - if (WARN_ON_ONCE(residue > length || residue < 0))
> + if (WARN_ON_ONCE(residue > length))
Are you sure this is the right fix? length is size_t
fluke_get_dma_residue() returns unsigned int - yes
the coverity report is correct, but should fluke_get_dma_residue()
return size_t?
> return -EFAULT;
> *bytes_read += length - residue;
bytes_read is also size_t
> dmaengine_terminate_all(e_priv->dma_channel);
The patch should indicate it is against next. [PATCH next].
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] staging: gpib: Remove a dead condition in if statement
2024-10-15 22:47 ` Shuah Khan
@ 2024-10-15 23:50 ` Everest K.C.
0 siblings, 0 replies; 4+ messages in thread
From: Everest K.C. @ 2024-10-15 23:50 UTC (permalink / raw)
To: Shuah Khan; +Cc: dpenkler, gregkh, linux-staging, linux-kernel
On Tue, Oct 15, 2024 at 4:47 PM Shuah Khan <skhan@linuxfoundation.org> wrote:
>
> On 10/15/24 14:06, Everest K.C. wrote:
> > The variable `residue` is an unsigned int, also the function
> > `fluke_get_dma_residue` returns an unsigned int. The value of
> > an unsigned int can only be 0 at minimum.
> > The less-than-zero comparision can never be true.
> > Fix it by removing the dead condition in the if statement.
> >
> > This issue was reported by Coverity Scan.
> > Report:
> > CID 1600782: (#1 of 1): Macro compares unsigned to 0 (NO_EFFECT)
> > unsigned_compare: This less-than-zero comparison of an unsigned value
> > is never true. residue < 0U.
> >
> > Fixes: 55936779f496 ("staging: gpib: Add Fluke cda based cards GPIB driver")
> > Signed-off-by: Everest K.C. <everestkc@everestkc.com.np>
> > ---
> > drivers/staging/gpib/eastwood/fluke_gpib.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/staging/gpib/eastwood/fluke_gpib.c b/drivers/staging/gpib/eastwood/fluke_gpib.c
> > index f9f149db222d..51b4f9891a34 100644
> > --- a/drivers/staging/gpib/eastwood/fluke_gpib.c
> > +++ b/drivers/staging/gpib/eastwood/fluke_gpib.c
> > @@ -644,7 +644,7 @@ static int fluke_dma_read(gpib_board_t *board, uint8_t *buffer,
> > */
> > usleep_range(10, 15);
> > residue = fluke_get_dma_residue(e_priv->dma_channel, dma_cookie);
> > - if (WARN_ON_ONCE(residue > length || residue < 0))
> > + if (WARN_ON_ONCE(residue > length))
>
> Are you sure this is the right fix? length is size_t
> fluke_get_dma_residue() returns unsigned int - yes
> the coverity report is correct, but should fluke_get_dma_residue()
> return size_t?
I agree that it looks kind of inconsistent. The variable residue returned
by fluke_get_dma_residue() is defined in a u32 defined in struct dma_tx_state.
I will wait for the feedback from the maintainers on this.
> > return -EFAULT;
> > *bytes_read += length - residue;
>
> bytes_read is also size_t
>
> > dmaengine_terminate_all(e_priv->dma_channel);
>
> The patch should indicate it is against next. [PATCH next].
The patch was created from linux staging.
> thanks,
> -- Shuah
>
>
Thanks,
Everest K.C.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] staging: gpib: Remove a dead condition in if statement
2024-10-15 20:06 [PATCH] staging: gpib: Remove a dead condition in if statement Everest K.C.
2024-10-15 22:47 ` Shuah Khan
@ 2024-10-16 7:38 ` Greg KH
1 sibling, 0 replies; 4+ messages in thread
From: Greg KH @ 2024-10-16 7:38 UTC (permalink / raw)
To: Everest K.C.; +Cc: dpenkler, skhan, linux-staging, linux-kernel
On Tue, Oct 15, 2024 at 02:06:47PM -0600, Everest K.C. wrote:
> The variable `residue` is an unsigned int, also the function
> `fluke_get_dma_residue` returns an unsigned int. The value of
> an unsigned int can only be 0 at minimum.
> The less-than-zero comparision can never be true.
> Fix it by removing the dead condition in the if statement.
>
> This issue was reported by Coverity Scan.
> Report:
> CID 1600782: (#1 of 1): Macro compares unsigned to 0 (NO_EFFECT)
> unsigned_compare: This less-than-zero comparison of an unsigned value
> is never true. residue < 0U.
>
> Fixes: 55936779f496 ("staging: gpib: Add Fluke cda based cards GPIB driver")
Again, a code cleanup does not deserve a "Fixes:" tag, sorry.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-10-16 7:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-15 20:06 [PATCH] staging: gpib: Remove a dead condition in if statement Everest K.C.
2024-10-15 22:47 ` Shuah Khan
2024-10-15 23:50 ` Everest K.C.
2024-10-16 7:38 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox