Commit 418e8f3d authored by Laurent Riffard's avatar Laurent Riffard Committed by Jeff Garzik
Browse files

[PATCH] bonding: fix an oops when slave device does not provide get_stats



Bonding driver unconditionnaly dereference get_stats function pointer
for each of its slave device. This patch
- adds a check for NULL dev->get_stats pointer in bond_get_stats
- prints a notice when the bonding device enslave a device without
  get_stats function.

Signed-off-by: default avatarLaurent Riffard <laurent.riffard@free.fr>
Signed-off-by: default avatarJeff Garzik <jeff@garzik.org>
parent c1cb0b77
Loading
Loading
Loading
Loading
+36 −27
Original line number Diff line number Diff line
@@ -1336,6 +1336,13 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
		goto err_undo_flags;
	}

	if (slave_dev->get_stats == NULL) {
		printk(KERN_NOTICE DRV_NAME
			": %s: the driver for slave device %s does not provide "
			"get_stats function, network statistics will be "
			"inaccurate.\n", bond_dev->name, slave_dev->name);
	}

	new_slave = kmalloc(sizeof(struct slave), GFP_KERNEL);
	if (!new_slave) {
		res = -ENOMEM;
@@ -3605,6 +3612,7 @@ static struct net_device_stats *bond_get_stats(struct net_device *bond_dev)
	read_lock_bh(&bond->lock);

	bond_for_each_slave(bond, slave, i) {
		if (slave->dev->get_stats) {
			sstats = slave->dev->get_stats(slave->dev);

			stats->rx_packets += sstats->rx_packets;
@@ -3633,6 +3641,7 @@ static struct net_device_stats *bond_get_stats(struct net_device *bond_dev)
			stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors;
			stats->tx_window_errors += sstats->tx_window_errors;
		}
	}

	read_unlock_bh(&bond->lock);