[PATCH] crypto: cavium - Fix the if condition to exit loop after timeout

Everest K.C. posted 1 patch 1 month, 1 week ago
drivers/crypto/cavium/cpt/cptpf_main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] crypto: cavium - Fix the if condition to exit loop after timeout
Posted by Everest K.C. 1 month, 1 week ago
The while loop breaks in the first run because of incorrect
if condition. It also causes the statements after the if to
appear dead.
Fix this by changing the condition from if(timeout--) to
if(!timeout--).

This bug was reported by Coverity Scan.
Report:
CID 1600859: (#1 of 1): Logically dead code (DEADCODE)
dead_error_line: Execution cannot reach this statement: udelay(30UL);

Fixes: 9e2c7d99941d ("crypto: cavium - Add Support for Octeon-tx CPT Engine")
Signed-off-by: Everest K.C. <everestkc@everestkc.com.np>
---
 drivers/crypto/cavium/cpt/cptpf_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/cavium/cpt/cptpf_main.c b/drivers/crypto/cavium/cpt/cptpf_main.c
index 6872ac344001..ec17beee24c0 100644
--- a/drivers/crypto/cavium/cpt/cptpf_main.c
+++ b/drivers/crypto/cavium/cpt/cptpf_main.c
@@ -44,7 +44,7 @@ static void cpt_disable_cores(struct cpt_device *cpt, u64 coremask,
 		dev_err(dev, "Cores still busy %llx", coremask);
 		grp = cpt_read_csr64(cpt->reg_base,
 				     CPTX_PF_EXEC_BUSY(0));
-		if (timeout--)
+		if (!timeout--)
 			break;
 
 		udelay(CSR_DELAY);
@@ -394,7 +394,7 @@ static void cpt_disable_all_cores(struct cpt_device *cpt)
 		dev_err(dev, "Cores still busy");
 		grp = cpt_read_csr64(cpt->reg_base,
 				     CPTX_PF_EXEC_BUSY(0));
-		if (timeout--)
+		if (!timeout--)
 			break;
 
 		udelay(CSR_DELAY);
-- 
2.43.0
Re: [PATCH] crypto: cavium - Fix the if condition to exit loop after timeout
Posted by Herbert Xu 1 month ago
On Fri, Oct 18, 2024 at 10:23:10AM -0600, Everest K.C. wrote:
> The while loop breaks in the first run because of incorrect
> if condition. It also causes the statements after the if to
> appear dead.
> Fix this by changing the condition from if(timeout--) to
> if(!timeout--).
> 
> This bug was reported by Coverity Scan.
> Report:
> CID 1600859: (#1 of 1): Logically dead code (DEADCODE)
> dead_error_line: Execution cannot reach this statement: udelay(30UL);
> 
> Fixes: 9e2c7d99941d ("crypto: cavium - Add Support for Octeon-tx CPT Engine")
> Signed-off-by: Everest K.C. <everestkc@everestkc.com.np>
> ---
>  drivers/crypto/cavium/cpt/cptpf_main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt