[dpdk-dev] net/nfp: check BAR size is above a safe size

Message ID 1510144091-27452-1-git-send-email-alejandro.lucero@netronome.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Alejandro Lucero Nov. 8, 2017, 12:28 p.m. UTC
  We do not know how big can the BAR be, but we know anything less
than 1MB is an error. This BAR needs to be big enough for accessing
most of NFP internals.

Fixes: d12206e00590 ("net/nfp: add NSP user space interface")
Coverity: 195024

Signed-off-by: Alejandro Lucero <alejandro.lucero@netronome.com>
---
 drivers/net/nfp/nfp_nfpu.c | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

Ferruh Yigit Nov. 10, 2017, 9:39 a.m. UTC | #1
On 11/8/2017 4:28 AM, Alejandro Lucero wrote:
> We do not know how big can the BAR be, but we know anything less
> than 1MB is an error. This BAR needs to be big enough for accessing
> most of NFP internals.
> 
> Fixes: d12206e00590 ("net/nfp: add NSP user space interface")
> Coverity: 195024
> 
> Signed-off-by: Alejandro Lucero <alejandro.lucero@netronome.com>

Applied to dpdk/master, thanks.
  

Patch

diff --git a/drivers/net/nfp/nfp_nfpu.c b/drivers/net/nfp/nfp_nfpu.c
index 5775d8d..f11afef 100644
--- a/drivers/net/nfp/nfp_nfpu.c
+++ b/drivers/net/nfp/nfp_nfpu.c
@@ -75,8 +75,13 @@ 
 	/* barsz in log2 */
 	while (barsz >>= 1)
 		i++;
+
 	barsz = i;
 
+	/* Sanity check: we can assume any bar size less than 1MB an error */
+	if (barsz < 20)
+		return -1;
+
 	/* Getting address for NFP expansion BAR registers */
 	cfg_base = pci_dev->mem_resource[0].addr;
 	cfg_base = (uint8_t *)cfg_base + NFP_CFG_EXP_BAR_CFG_BASE;