The return value of kmalloc() needs to be checked.
To avoid use in efx_nic_update_stats() in case of the failure of alloc.
Fixes: b593b6f1b492 ("sfc_ef100: statistics gathering")
Signed-off-by: Jiasheng Jiang <[email protected]>
---
drivers/net/ethernet/sfc/ef100_nic.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/net/ethernet/sfc/ef100_nic.c b/drivers/net/ethernet/sfc/ef100_nic.c
index 518268ce2064..ac55c6740e35 100644
--- a/drivers/net/ethernet/sfc/ef100_nic.c
+++ b/drivers/net/ethernet/sfc/ef100_nic.c
@@ -602,6 +602,9 @@ static size_t ef100_update_stats(struct efx_nic *efx,
struct rtnl_link_stats64 *core_stats)
{
__le64 *mc_stats = kmalloc(array_size(efx->num_mac_stats, sizeof(__le64)), GFP_ATOMIC);
+ if (!mc_stats)
+ return 0;
+
struct ef100_nic_data *nic_data = efx->nic_data;
DECLARE_BITMAP(mask, EF100_STAT_COUNT) = {};
u64 *stats = nic_data->stats;
--
2.25.1
Hi Jiasheng,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.16-rc5 next-20211214]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Jiasheng-Jiang/sfc_ef100-potential-dereference-of-null-pointer/20211215-174422
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 5472f14a37421d1bca3dddf33cabd3bd6dbefbbc
config: microblaze-allyesconfig (https://download.01.org/0day-ci/archive/20211215/[email protected]/config)
compiler: microblaze-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/fc56ac03164889a206ee1b65187a8be7aa7b0f04
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jiasheng-Jiang/sfc_ef100-potential-dereference-of-null-pointer/20211215-174422
git checkout fc56ac03164889a206ee1b65187a8be7aa7b0f04
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=microblaze SHELL=/bin/bash drivers/net/ethernet/sfc/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
All warnings (new ones prefixed by >>):
drivers/net/ethernet/sfc/ef100_nic.c: In function 'ef100_update_stats':
>> drivers/net/ethernet/sfc/ef100_nic.c:608:9: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
608 | struct ef100_nic_data *nic_data = efx->nic_data;
| ^~~~~~
vim +608 drivers/net/ethernet/sfc/ef100_nic.c
b593b6f1b492170 Edward Cree 2020-08-03 599
b593b6f1b492170 Edward Cree 2020-08-03 600 static size_t ef100_update_stats(struct efx_nic *efx,
b593b6f1b492170 Edward Cree 2020-08-03 601 u64 *full_stats,
b593b6f1b492170 Edward Cree 2020-08-03 602 struct rtnl_link_stats64 *core_stats)
b593b6f1b492170 Edward Cree 2020-08-03 603 {
b593b6f1b492170 Edward Cree 2020-08-03 604 __le64 *mc_stats = kmalloc(array_size(efx->num_mac_stats, sizeof(__le64)), GFP_ATOMIC);
fc56ac03164889a Jiasheng Jiang 2021-12-15 605 if (!mc_stats)
fc56ac03164889a Jiasheng Jiang 2021-12-15 606 return 0;
fc56ac03164889a Jiasheng Jiang 2021-12-15 607
b593b6f1b492170 Edward Cree 2020-08-03 @608 struct ef100_nic_data *nic_data = efx->nic_data;
b593b6f1b492170 Edward Cree 2020-08-03 609 DECLARE_BITMAP(mask, EF100_STAT_COUNT) = {};
b593b6f1b492170 Edward Cree 2020-08-03 610 u64 *stats = nic_data->stats;
b593b6f1b492170 Edward Cree 2020-08-03 611
b593b6f1b492170 Edward Cree 2020-08-03 612 ef100_common_stat_mask(mask);
b593b6f1b492170 Edward Cree 2020-08-03 613 ef100_ethtool_stat_mask(mask);
b593b6f1b492170 Edward Cree 2020-08-03 614
b593b6f1b492170 Edward Cree 2020-08-03 615 efx_nic_copy_stats(efx, mc_stats);
b593b6f1b492170 Edward Cree 2020-08-03 616 efx_nic_update_stats(ef100_stat_desc, EF100_STAT_COUNT, mask,
b593b6f1b492170 Edward Cree 2020-08-03 617 stats, mc_stats, false);
b593b6f1b492170 Edward Cree 2020-08-03 618
b593b6f1b492170 Edward Cree 2020-08-03 619 kfree(mc_stats);
b593b6f1b492170 Edward Cree 2020-08-03 620
b593b6f1b492170 Edward Cree 2020-08-03 621 return ef100_update_stats_common(efx, full_stats, core_stats);
b593b6f1b492170 Edward Cree 2020-08-03 622 }
b593b6f1b492170 Edward Cree 2020-08-03 623
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
Hi Jiasheng,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.16-rc5 next-20211214]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Jiasheng-Jiang/sfc_ef100-potential-dereference-of-null-pointer/20211215-174422
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 5472f14a37421d1bca3dddf33cabd3bd6dbefbbc
config: arm64-randconfig-r021-20211214 (https://download.01.org/0day-ci/archive/20211216/[email protected]/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project dd245bab9fbb364faa1581e4f92ba3119a872fba)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/0day-ci/linux/commit/fc56ac03164889a206ee1b65187a8be7aa7b0f04
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jiasheng-Jiang/sfc_ef100-potential-dereference-of-null-pointer/20211215-174422
git checkout fc56ac03164889a206ee1b65187a8be7aa7b0f04
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash drivers/net/ethernet/sfc/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
All warnings (new ones prefixed by >>):
>> drivers/net/ethernet/sfc/ef100_nic.c:608:25: warning: ISO C90 forbids mixing declarations and code [-Wdeclaration-after-statement]
struct ef100_nic_data *nic_data = efx->nic_data;
^
1 warning generated.
vim +608 drivers/net/ethernet/sfc/ef100_nic.c
b593b6f1b492170 Edward Cree 2020-08-03 599
b593b6f1b492170 Edward Cree 2020-08-03 600 static size_t ef100_update_stats(struct efx_nic *efx,
b593b6f1b492170 Edward Cree 2020-08-03 601 u64 *full_stats,
b593b6f1b492170 Edward Cree 2020-08-03 602 struct rtnl_link_stats64 *core_stats)
b593b6f1b492170 Edward Cree 2020-08-03 603 {
b593b6f1b492170 Edward Cree 2020-08-03 604 __le64 *mc_stats = kmalloc(array_size(efx->num_mac_stats, sizeof(__le64)), GFP_ATOMIC);
fc56ac03164889a Jiasheng Jiang 2021-12-15 605 if (!mc_stats)
fc56ac03164889a Jiasheng Jiang 2021-12-15 606 return 0;
fc56ac03164889a Jiasheng Jiang 2021-12-15 607
b593b6f1b492170 Edward Cree 2020-08-03 @608 struct ef100_nic_data *nic_data = efx->nic_data;
b593b6f1b492170 Edward Cree 2020-08-03 609 DECLARE_BITMAP(mask, EF100_STAT_COUNT) = {};
b593b6f1b492170 Edward Cree 2020-08-03 610 u64 *stats = nic_data->stats;
b593b6f1b492170 Edward Cree 2020-08-03 611
b593b6f1b492170 Edward Cree 2020-08-03 612 ef100_common_stat_mask(mask);
b593b6f1b492170 Edward Cree 2020-08-03 613 ef100_ethtool_stat_mask(mask);
b593b6f1b492170 Edward Cree 2020-08-03 614
b593b6f1b492170 Edward Cree 2020-08-03 615 efx_nic_copy_stats(efx, mc_stats);
b593b6f1b492170 Edward Cree 2020-08-03 616 efx_nic_update_stats(ef100_stat_desc, EF100_STAT_COUNT, mask,
b593b6f1b492170 Edward Cree 2020-08-03 617 stats, mc_stats, false);
b593b6f1b492170 Edward Cree 2020-08-03 618
b593b6f1b492170 Edward Cree 2020-08-03 619 kfree(mc_stats);
b593b6f1b492170 Edward Cree 2020-08-03 620
b593b6f1b492170 Edward Cree 2020-08-03 621 return ef100_update_stats_common(efx, full_stats, core_stats);
b593b6f1b492170 Edward Cree 2020-08-03 622 }
b593b6f1b492170 Edward Cree 2020-08-03 623
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]