net/bnxt: fix compiler warnings
PATCH 1/1 net/bnxt: fix compiler warnings
From: Dakota Sicher <[email protected]>
Fix a compiler warning in bnxt_tf_pmd_shim for comparison of differently signed values. Fix compiler warnings for array out-of-bounds in ulp_bs_pull_lsb and ulp_bs_pull_msb.
--- drivers/net/bnxt/tf_ulp/bnxt_tf_pmd_shim.c | 14 +++++++++++--- drivers/net/bnxt/tf_ulp/ulp_utils.h | 14 +++++++------- 2 files changed, 18 insertions(+), 10 deletions(-)
drivers/net/bnxt/tf_ulp/bnxt_tf_pmd_shim.c +11 -3
@@ -140,10 +140,14 @@ static int32_t ulp_pmd_get_mac_by_pci(const char *pci_name, uint8_t *mac)glob_t gres;FILE *fp;int32_t rc = -EINVAL ; +int32_t pr;memset (path,0 ,sizeof (path)); -sprintf (path,PARENT_PHY_INTF_PATH , pci_name); - + pr =snprintf (path,sizeof (path),PARENT_PHY_INTF_PATH , pci_name); +if (unlikely ((size_t )pr >=sizeof (path) || pr <0 )) { +BNXT_DRV_DBG (ERR ,"Error writing path: %s" , path); +return rc; + }/* There can be only one, no more, no less */ if (glob (path,0 , glob_error_fn, &gres) ==0 ) {if (gres.gl_pathc !=1 )
@@ -151,7 +155,11 @@ static int32_t ulp_pmd_get_mac_by_pci(const char *pci_name, uint8_t *mac)/* Replace the PCI address with interface name and get index */ intf_name =basename (gres.gl_pathv[0 ]); -sprintf (path,ULP_PRT_MAC_PATH , pci_name, intf_name); + pr =snprintf (path,sizeof (path),ULP_PRT_MAC_PATH , pci_name, intf_name); +if (unlikely ((size_t )pr >=sizeof (path) || pr <0 )) { +BNXT_DRV_DBG (ERR ,"Error writing path: %s" , path); +return rc; + } fp =fopen (path,"r" );if (!fp) {
drivers/net/bnxt/tf_ulp/ulp_utils.h +7 -7
@@ -699,18 +699,18 @@ ulp_bs_pull_lsb(uint8_t *src, uint8_t *dst, uint32_t size, {uint32_t idx;uint32_t cnt =ULP_BITS_2_BYTE_NR (len); +uint32_t rem = len %ULP_BLOB_BYTE ;/* iterate bytewise to get data */ -for (idx =0 ; idx < cnt; idx++) { +for (idx =0 ; idx < cnt && idx < size; idx++) {ulp_bs_get_lsb (src, offset,ULP_BLOB_BYTE , &dst[size -1 - idx]); offset +=ULP_BLOB_BYTE ; - len -=ULP_BLOB_BYTE ; }/* Extract the last reminder data that is not 8 byte boundary */ -if (len) -ulp_bs_get_lsb (src, offset, len, &dst[size -1 - idx]); +if (rem && idx < size) +ulp_bs_get_lsb (src, offset, rem, &dst[size -1 - idx]); }/*
@@ -764,17 +764,17 @@ ulp_bs_pull_msb(uint8_t *src, uint8_t *dst, {uint32_t idx;uint32_t cnt =ULP_BITS_2_BYTE_NR (len); +uint32_t rem = len %ULP_BLOB_BYTE ;/* iterate bytewise to get data */ for (idx =0 ; idx < cnt; idx++) {ulp_bs_get_msb (src, offset,ULP_BLOB_BYTE , &dst[idx]); offset +=ULP_BLOB_BYTE ; - len -=ULP_BLOB_BYTE ; }/* Extract the last reminder data that is not 8 byte boundary */ -if (len) -ulp_bs_get_msb (src, offset, len, &dst[idx]); +if (rem) +ulp_bs_get_msb (src, offset, rem, &dst[idx]); }/*
Signature · 1 line
2.31.1
PATCH v2 1/1 net/bnxt: fix parent MAC lookup path handling
From: Dakota Sicher <[email protected]>
ulp_pmd_get_mac_by_pci() builds sysfs paths with sprintf() into a 256 byte buffer from a PCI name and an interface name taken from glob(). Use snprintf() and fail if the path is truncated.
The glob() result was also never released. Call globfree() on every exit path once glob() has succeeded.
---
v2:
- Also free the glob() result on every exit path; it was never released
- Drop the ulp_utils.h hunks, they are covered by the -Warray-bounds patch
- New subject and body, Cc: stable added
drivers/net/bnxt/tf_ulp/bnxt_tf_pmd_shim.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/net/bnxt/tf_ulp/bnxt_tf_pmd_shim.c +16 -6
@@ -140,30 +140,38 @@ static int32_t ulp_pmd_get_mac_by_pci(const char *pci_name, uint8_t *mac)glob_t gres;FILE *fp;int32_t rc = -EINVAL ; +int32_t pr;memset (path,0 ,sizeof (path)); -sprintf (path,PARENT_PHY_INTF_PATH , pci_name); - + pr =snprintf (path,sizeof (path),PARENT_PHY_INTF_PATH , pci_name); +if (unlikely ((size_t )pr >=sizeof (path) || pr <0 )) { +BNXT_DRV_DBG (ERR ,"Error writing path: %s" , path); +return rc; + }/* There can be only one, no more, no less */ if (glob (path,0 , glob_error_fn, &gres) ==0 ) {if (gres.gl_pathc !=1 ) -return rc; + goto free_glob;/* Replace the PCI address with interface name and get index */ intf_name =basename (gres.gl_pathv[0 ]); -sprintf (path,ULP_PRT_MAC_PATH , pci_name, intf_name); + pr =snprintf (path,sizeof (path),ULP_PRT_MAC_PATH , pci_name, intf_name); +if (unlikely ((size_t )pr >=sizeof (path) || pr <0 )) { +BNXT_DRV_DBG (ERR ,"Error writing path: %s" , path); + goto free_glob; + } fp =fopen (path,"r" );if (!fp) {BNXT_DRV_DBG (ERR ,"Error in getting bond mac address\n" ); -return rc; + goto free_glob; }memset (dev_str,0 ,sizeof (dev_str));if (fgets (dev_str,sizeof (dev_str), fp) ==NULL ) {BNXT_DRV_DBG (ERR ,"Error in reading %s\n" , path);fclose (fp); -return rc; + goto free_glob; } if (sscanf(dev_str, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx\n",
@@ -171,6 +179,8 @@ static int32_t ulp_pmd_get_mac_by_pci(const char *pci_name, uint8_t *mac) &mac[3], &mac[4], &mac[5]) == 6) rc =0 ;fclose (fp); +free_glob: +globfree (&gres); }return rc; }
Signature · 1 line
2.47.3