dma/idxd: fix truncated error code in status check

Message ID 20211026142045.2996949-1-kevin.laatz@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series dma/idxd: fix truncated error code in status check |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot: build success github build: passed
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS

Commit Message

Kevin Laatz Oct. 26, 2021, 2:20 p.m. UTC
  When checking if the DMA device is active, the result of the operand will
always be zero since the err_code is truncated to 8 bits which makes
checking the 31st bit impossible.

This is fixed by changing the type of err_code to uint32_t so that it is
not truncated.

Coverity issue: 373657
Fixes: 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")

Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
---
 drivers/dma/idxd/idxd_pci.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Comments

Bruce Richardson Oct. 27, 2021, 1:08 p.m. UTC | #1
On Tue, Oct 26, 2021 at 02:20:45PM +0000, Kevin Laatz wrote:
> When checking if the DMA device is active, the result of the operand will
> always be zero since the err_code is truncated to 8 bits which makes
> checking the 31st bit impossible.
> 
> This is fixed by changing the type of err_code to uint32_t so that it is
> not truncated.
> 
> Coverity issue: 373657
> Fixes: 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
> 
> Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
> ---
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  
Conor Walsh Oct. 27, 2021, 1:12 p.m. UTC | #2
> From: dev <dev-bounces@dpdk.org> On Behalf Of Kevin Laatz
> Sent: Tuesday 26 October 2021 15:21
> To: dev@dpdk.org
> Cc: Richardson, Bruce <bruce.richardson@intel.com>; Laatz, Kevin
> <kevin.laatz@intel.com>
> Subject: [dpdk-dev] [PATCH] dma/idxd: fix truncated error code in status
> check
> 
> When checking if the DMA device is active, the result of the operand will
> always be zero since the err_code is truncated to 8 bits which makes
> checking the 31st bit impossible.
> 
> This is fixed by changing the type of err_code to uint32_t so that it is
> not truncated.
> 
> Coverity issue: 373657
> Fixes: 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
> 
> Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
> ---

Reviewed-by: Conor Walsh <conor.walsh@intel.com>
  
Thomas Monjalon Oct. 27, 2021, 3 p.m. UTC | #3
27/10/2021 15:08, Bruce Richardson:
> On Tue, Oct 26, 2021 at 02:20:45PM +0000, Kevin Laatz wrote:
> > When checking if the DMA device is active, the result of the operand will
> > always be zero since the err_code is truncated to 8 bits which makes
> > checking the 31st bit impossible.
> > 
> > This is fixed by changing the type of err_code to uint32_t so that it is
> > not truncated.
> > 
> > Coverity issue: 373657
> > Fixes: 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
> > 
> > Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
> > ---
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Applied, thanks.
  

Patch

diff --git a/drivers/dma/idxd/idxd_pci.c b/drivers/dma/idxd/idxd_pci.c
index 1aabacee41..9ca1ec64e9 100644
--- a/drivers/dma/idxd/idxd_pci.c
+++ b/drivers/dma/idxd/idxd_pci.c
@@ -22,7 +22,7 @@  const struct rte_pci_id pci_id_idxd_map[] = {
 static inline int
 idxd_pci_dev_command(struct idxd_dmadev *idxd, enum rte_idxd_cmds command)
 {
-	uint8_t err_code;
+	uint32_t err_code;
 	uint16_t qid = idxd->qid;
 	int i = 0;
 
@@ -37,7 +37,8 @@  idxd_pci_dev_command(struct idxd_dmadev *idxd, enum rte_idxd_cmds command)
 		if (++i >= 1000) {
 			IDXD_PMD_ERR("Timeout waiting for command response from HW");
 			rte_spinlock_unlock(&idxd->u.pci->lk);
-			return err_code;
+			err_code &= CMDSTATUS_ERR_MASK;
+			return -err_code;
 		}
 	} while (err_code & CMDSTATUS_ACTIVE_MASK);
 	rte_spinlock_unlock(&idxd->u.pci->lk);