sfc_ef100: potential dereference of null pointer
authorJiasheng Jiang <jiasheng@iscas.ac.cn>
Wed, 15 Dec 2021 14:37:31 +0000 (22:37 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Dec 2021 08:32:44 +0000 (09:32 +0100)
[ Upstream commit 407ecd1bd726f240123f704620d46e285ff30dd9 ]

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 <jiasheng@iscas.ac.cn>
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/sfc/ef100_nic.c

index 518268ce206445e898c0d29b865fe6d3a228a396..d35cafd422b1cb21ae0e978a949972f9179c1424 100644 (file)
@@ -609,6 +609,9 @@ static size_t ef100_update_stats(struct efx_nic *efx,
        ef100_common_stat_mask(mask);
        ef100_ethtool_stat_mask(mask);
 
+       if (!mc_stats)
+               return 0;
+
        efx_nic_copy_stats(efx, mc_stats);
        efx_nic_update_stats(ef100_stat_desc, EF100_STAT_COUNT, mask,
                             stats, mc_stats, false);