Skip to content

Commit 19b596b

Browse files
Govindarajulu Varadarajandavem330
authored andcommitted
enic: check return value for stat dump
We do not check the return value of enic_dev_stats_dump(). If allocation fails, we will hit NULL pointer reference. Return only if memory allocation fails. For other failures, we return the previously recorded values. Signed-off-by: Govindarajulu Varadarajan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6286e82 commit 19b596b

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

drivers/net/ethernet/cisco/enic/enic_ethtool.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,15 @@ static void enic_get_drvinfo(struct net_device *netdev,
131131
{
132132
struct enic *enic = netdev_priv(netdev);
133133
struct vnic_devcmd_fw_info *fw_info;
134+
int err;
134135

135-
enic_dev_fw_info(enic, &fw_info);
136+
err = enic_dev_fw_info(enic, &fw_info);
137+
/* return only when pci_zalloc_consistent fails in vnic_dev_fw_info
138+
* For other failures, like devcmd failure, we return previously
139+
* recorded info.
140+
*/
141+
if (err == -ENOMEM)
142+
return;
136143

137144
strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
138145
strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
@@ -181,8 +188,15 @@ static void enic_get_ethtool_stats(struct net_device *netdev,
181188
struct enic *enic = netdev_priv(netdev);
182189
struct vnic_stats *vstats;
183190
unsigned int i;
184-
185-
enic_dev_stats_dump(enic, &vstats);
191+
int err;
192+
193+
err = enic_dev_stats_dump(enic, &vstats);
194+
/* return only when pci_zalloc_consistent fails in vnic_dev_stats_dump
195+
* For other failures, like devcmd failure, we return previously
196+
* recorded stats.
197+
*/
198+
if (err == -ENOMEM)
199+
return;
186200

187201
for (i = 0; i < enic_n_tx_stats; i++)
188202
*(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].index];

drivers/net/ethernet/cisco/enic/enic_main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,15 @@ static struct rtnl_link_stats64 *enic_get_stats(struct net_device *netdev,
615615
{
616616
struct enic *enic = netdev_priv(netdev);
617617
struct vnic_stats *stats;
618+
int err;
618619

619-
enic_dev_stats_dump(enic, &stats);
620+
err = enic_dev_stats_dump(enic, &stats);
621+
/* return only when pci_zalloc_consistent fails in vnic_dev_stats_dump
622+
* For other failures, like devcmd failure, we return previously
623+
* recorded stats.
624+
*/
625+
if (err == -ENOMEM)
626+
return net_stats;
620627

621628
net_stats->tx_packets = stats->tx.tx_frames_ok;
622629
net_stats->tx_bytes = stats->tx.tx_bytes_ok;

0 commit comments

Comments
 (0)