Skip to contentSkip to conversation

dev->priv to netdev_priv(dev), for drivers/net/bonding

PATCH NAK Yoann Padioleau 1 participant 1 message Aug 3, 2007

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 4/13 dev->priv to netdev_priv(dev), for drivers/net/bonding

Replacing accesses to dev->priv to netdev_priv(dev). The replacment is safe when netdev_priv is used to access a private structure that is right next to the net_device structure in memory. Cf
http://groups.google.com/group/comp.os.linux.development.system/browse_thread/thread/de19321bcd94dbb8/0d74a4adcd6177bd
This is the case when the net_device structure was allocated with a call to alloc_netdev or one of its derivative.

Here is an excerpt of the semantic patch that performs the transformation

@ rule1 @
type T;
struct net_device *dev;
@@

dev =
(
alloc_netdev
|
alloc_etherdev
|
alloc_trdev
)
(sizeof(T), ...)

@ rule1bis @
struct net_device *dev;
expression E;
@@
dev->priv = E

@ rule2 depends on rule1 && !rule1bis @
struct net_device *dev;
type rule1.T;
@@

- (T*) dev->priv
+ netdev_priv(dev)

---

 drivers/net/bonding/bond_3ad.c  |    6 +--
 drivers/net/bonding/bond_alb.c  |    6 +--
 drivers/net/bonding/bond_main.c |   62 ++++++++++++++++++++--------------------
 3 files changed, 37 insertions(+), 37 deletions(-)
drivers/net/bonding/bond_3ad.c +3 -3
index f829e4a..9ad88d0 100644
@@ -2364,7 +2364,7 @@ int bond_3ad_get_active_agg_info(struct 
 int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
 {
 	struct slave *slave, *start_at;
-	struct bonding *bond = dev->priv;
+	struct bonding *bond = netdev_priv(dev);
 	int slave_agg_no;
 	int slaves_in_agg;
 	int agg_id;
@@ -2444,7 +2444,7 @@ out:
 
 int bond_3ad_lacpdu_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type* ptype, struct net_device *orig_dev)
 {
-	struct bonding *bond = dev->priv;
+	struct bonding *bond = netdev_priv(dev);
 	struct slave *slave = NULL;
 	int ret = NET_RX_DROP;
 
@@ -2452,7 +2452,7 @@ int bond_3ad_lacpdu_recv(struct sk_buff 
 		goto out;
 
 	read_lock(&bond->lock);
-	slave = bond_get_slave_by_dev((struct bonding *)dev->priv, orig_dev);
+	slave = bond_get_slave_by_dev(netdev_priv(dev), orig_dev);
 	if (!slave)
 		goto out_unlock;
 
drivers/net/bonding/bond_alb.c +3 -3
index 92c3b6f..c90524b 100644
@@ -341,7 +341,7 @@ static void rlb_update_entry_from_arp(st
 
 static int rlb_arp_recv(struct sk_buff *skb, struct net_device *bond_dev, struct packet_type *ptype, struct net_device *orig_dev)
 {
-	struct bonding *bond = bond_dev->priv;
+	struct bonding *bond = netdev_priv(bond_dev);
 	struct arp_pkt *arp = (struct arp_pkt *)skb->data;
 	int res = NET_RX_DROP;
 
@@ -1260,7 +1260,7 @@ void bond_alb_deinitialize(struct bondin
 
 int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
 {
-	struct bonding *bond = bond_dev->priv;
+	struct bonding *bond = netdev_priv(bond_dev);
 	struct ethhdr *eth_data;
 	struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
 	struct slave *tx_slave = NULL;
@@ -1621,7 +1621,7 @@ void bond_alb_handle_active_change(struc
 
 int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr)
 {
-	struct bonding *bond = bond_dev->priv;
+	struct bonding *bond = netdev_priv(bond_dev);
 	struct sockaddr *sa = addr;
 	struct slave *slave, *swap_slave;
 	int res;
drivers/net/bonding/bond_main.c +31 -31

246 lines not on this page · raw message