Skip to contentSkip to conversation

Update net core to use devres.

RFC PATCH In review Brandon Philips 3 participants 3 messages Aug 2, 2007 – Aug 3, 2007

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

RFC PATCH 2/5 Update net core to use devres.

* netdev_pci_remove_one() can replace simple pci device remove functions

* devm_alloc_netdev() is like alloc_netdev but allocates memory using devres.

---
 include/linux/etherdevice.h |    5 ++
 include/linux/netdevice.h   |    7 ++
 net/core/dev.c              |  109 +++++++++++++++++++++++++++++++++++++++-----
 net/ethernet/eth.c          |    8 +++
 4 files changed, 119 insertions(+), 10 deletions(-)
include/linux/netdevice.h +7 -0
Index: linux-2.6/include/linux/netdevice.h
===================================================================
@@ -656,6 +656,7 @@ extern int		dev_queue_xmit(struct sk_buf
 extern int		register_netdevice(struct net_device *dev);
 extern void		unregister_netdevice(struct net_device *dev);
 extern void		free_netdev(struct net_device *dev);
+extern void		netdev_pci_remove_one(struct pci_dev *pdev);
 extern void		synchronize_net(void);
 extern int 		register_netdevice_notifier(struct notifier_block *nb);
 extern int		unregister_netdevice_notifier(struct notifier_block *nb);
@@ -1085,8 +1086,14 @@ extern void		ether_setup(struct net_devi
 extern struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
 				       void (*setup)(struct net_device *),
 				       unsigned int queue_count);
+extern struct net_device *devm_alloc_netdev_mq(struct device *dev,
+				       int sizeof_priv, const char *name,
+				       void (*setup)(struct net_device *),
+				       unsigned int queue_count);
 #define alloc_netdev(sizeof_priv, name, setup) \
 	alloc_netdev_mq(sizeof_priv, name, setup, 1)
+#define devm_alloc_netdev(dev, sizeof_priv, name, setup) \
+	devm_alloc_netdev_mq(dev, sizeof_priv, name, setup, 1)
 extern int		register_netdev(struct net_device *dev);
 extern void		unregister_netdev(struct net_device *dev);
 /* Functions used for secondary unicast and multicast support */
net/core/dev.c +99 -10

137 lines not on this page · raw message

include/linux/etherdevice.h +5 -0
Index: linux-2.6/include/linux/etherdevice.h
===================================================================
@@ -40,7 +40,12 @@ extern int		eth_header_cache(struct neig
 					 struct hh_cache *hh);
 
 extern struct net_device *alloc_etherdev_mq(int sizeof_priv, unsigned int queue_count);
+extern struct net_device *devm_alloc_etherdev_mq(struct device *dev,
+					      int sizeof_priv,
+					      unsigned int queue_count);
 #define alloc_etherdev(sizeof_priv) alloc_etherdev_mq(sizeof_priv, 1)
+#define devm_alloc_etherdev(dev, sizeof_priv) \
+	devm_alloc_etherdev_mq(dev, sizeof_priv, 1)
 
 /**
  * is_zero_ether_addr - Determine if give Ethernet address is all zeros.
net/ethernet/eth.c +8 -0
Index: linux-2.6/net/ethernet/eth.c
===================================================================
@@ -337,3 +337,11 @@ struct net_device *alloc_etherdev_mq(int
 	return alloc_netdev_mq(sizeof_priv, "eth%d", ether_setup, queue_count);
 }
 EXPORT_SYMBOL(alloc_etherdev_mq);
+
+struct net_device *devm_alloc_etherdev_mq(struct device *dev, int sizeof_priv,
+						unsigned int queue_count)
+{
+	return devm_alloc_netdev_mq(dev, sizeof_priv, "eth%d", ether_setup,
+				    queue_count);
+}
+EXPORT_SYMBOL(devm_alloc_etherdev_mq);
#1 lore raw

net/core/dev.c static struct net_device_stats *internal · line 3688

Quoted 11 lines
net/core/dev.c +11 -0
+static inline void * register_netdev_devres(struct device *gendev,
+						struct net_device *dev)
+{
+	struct net_device **p;
+
+	/* 0 size because we don't need it. The net_device is already alloc'd
+	 * in alloc_netdev_mq.  We can't use devm_kzalloc in alloc_netdeev_mq
+	 * because a net_device cannot be free'd directly as it can be a
+	 * kobject.  See free_netdev.
+	 */
+	p = devres_alloc(devm_free_netdev, 0, GFP_KERNEL);

s/0/sizeof(*p)/

Signature · 1 line
tejun
#2 lore raw
Quoted 3 lines · Tejun Heo

net/core/dev.c static struct net_device_stats *internal · line 3688

Quoted 1 line
net/core/dev.c +1 -0
+	p = devres_alloc(devm_free_netdev, 0, GFP_KERNEL);

s/0/sizeof(*p)/

Oops! It should have read like this:

+static void * register_netdev_devres(struct device *gendev,
+ struct net_device *dev)
+{
+ void *p;
+
+ /* 0 size because we don't need it. The net_device is already alloc'd

+        * in alloc_netdev_mq.  We can't use devm_kzalloc in alloc_netdev_mq
+        * because a net_device cannot be free'd directly as it can be a
+        * kobject.  See free_netdev.
+        */

+ p = devres_alloc(devm_free_netdev, 0, GFP_KERNEL);
+
+ if (unlikely(!p))
+ return NULL;
+
+ devres_add(gendev, p);
+
+ return dev;
+}

I will send the full correct patch.

Thanks,

Brandon