Commit 19b596bd authored by Govindarajulu Varadarajan's avatar Govindarajulu Varadarajan Committed by David S. Miller

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: default avatarGovindarajulu Varadarajan <_govind@gmx.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6286e828
...@@ -131,8 +131,15 @@ static void enic_get_drvinfo(struct net_device *netdev, ...@@ -131,8 +131,15 @@ static void enic_get_drvinfo(struct net_device *netdev,
{ {
struct enic *enic = netdev_priv(netdev); struct enic *enic = netdev_priv(netdev);
struct vnic_devcmd_fw_info *fw_info; struct vnic_devcmd_fw_info *fw_info;
int err;
enic_dev_fw_info(enic, &fw_info); err = enic_dev_fw_info(enic, &fw_info);
/* return only when pci_zalloc_consistent fails in vnic_dev_fw_info
* For other failures, like devcmd failure, we return previously
* recorded info.
*/
if (err == -ENOMEM)
return;
strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver)); strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version)); strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
...@@ -181,8 +188,15 @@ static void enic_get_ethtool_stats(struct net_device *netdev, ...@@ -181,8 +188,15 @@ static void enic_get_ethtool_stats(struct net_device *netdev,
struct enic *enic = netdev_priv(netdev); struct enic *enic = netdev_priv(netdev);
struct vnic_stats *vstats; struct vnic_stats *vstats;
unsigned int i; unsigned int i;
int err;
enic_dev_stats_dump(enic, &vstats);
err = enic_dev_stats_dump(enic, &vstats);
/* return only when pci_zalloc_consistent fails in vnic_dev_stats_dump
* For other failures, like devcmd failure, we return previously
* recorded stats.
*/
if (err == -ENOMEM)
return;
for (i = 0; i < enic_n_tx_stats; i++) for (i = 0; i < enic_n_tx_stats; i++)
*(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].index]; *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].index];
......
...@@ -615,8 +615,15 @@ static struct rtnl_link_stats64 *enic_get_stats(struct net_device *netdev, ...@@ -615,8 +615,15 @@ static struct rtnl_link_stats64 *enic_get_stats(struct net_device *netdev,
{ {
struct enic *enic = netdev_priv(netdev); struct enic *enic = netdev_priv(netdev);
struct vnic_stats *stats; struct vnic_stats *stats;
int err;
enic_dev_stats_dump(enic, &stats); err = enic_dev_stats_dump(enic, &stats);
/* return only when pci_zalloc_consistent fails in vnic_dev_stats_dump
* For other failures, like devcmd failure, we return previously
* recorded stats.
*/
if (err == -ENOMEM)
return net_stats;
net_stats->tx_packets = stats->tx.tx_frames_ok; net_stats->tx_packets = stats->tx.tx_frames_ok;
net_stats->tx_bytes = stats->tx.tx_bytes_ok; net_stats->tx_bytes = stats->tx.tx_bytes_ok;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment