022-net-add-devm-version-of-alloc_etherdev_mqs-function.patch 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
  2. Date: Sat, 28 Jan 2017 15:15:42 +0100
  3. Subject: [PATCH] net: add devm version of alloc_etherdev_mqs function
  4. MIME-Version: 1.0
  5. Content-Type: text/plain; charset=UTF-8
  6. Content-Transfer-Encoding: 8bit
  7. This patch adds devm_alloc_etherdev_mqs function and devm_alloc_etherdev
  8. macro. These can be used for simpler netdev allocation without having to
  9. care about calling free_netdev.
  10. Thanks to this change drivers, their error paths and removal paths may
  11. get simpler by a bit.
  12. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  13. Signed-off-by: David S. Miller <davem@davemloft.net>
  14. ---
  15. --- a/include/linux/etherdevice.h
  16. +++ b/include/linux/etherdevice.h
  17. @@ -54,6 +54,11 @@ struct net_device *alloc_etherdev_mqs(in
  18. #define alloc_etherdev(sizeof_priv) alloc_etherdev_mq(sizeof_priv, 1)
  19. #define alloc_etherdev_mq(sizeof_priv, count) alloc_etherdev_mqs(sizeof_priv, count, count)
  20. +struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv,
  21. + unsigned int txqs,
  22. + unsigned int rxqs);
  23. +#define devm_alloc_etherdev(dev, sizeof_priv) devm_alloc_etherdev_mqs(dev, sizeof_priv, 1, 1)
  24. +
  25. struct sk_buff **eth_gro_receive(struct sk_buff **head,
  26. struct sk_buff *skb);
  27. int eth_gro_complete(struct sk_buff *skb, int nhoff);
  28. --- a/net/ethernet/eth.c
  29. +++ b/net/ethernet/eth.c
  30. @@ -391,6 +391,34 @@ struct net_device *alloc_etherdev_mqs(in
  31. }
  32. EXPORT_SYMBOL(alloc_etherdev_mqs);
  33. +static void devm_free_netdev(struct device *dev, void *res)
  34. +{
  35. + free_netdev(*(struct net_device **)res);
  36. +}
  37. +
  38. +struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv,
  39. + unsigned int txqs, unsigned int rxqs)
  40. +{
  41. + struct net_device **dr;
  42. + struct net_device *netdev;
  43. +
  44. + dr = devres_alloc(devm_free_netdev, sizeof(*dr), GFP_KERNEL);
  45. + if (!dr)
  46. + return NULL;
  47. +
  48. + netdev = alloc_etherdev_mqs(sizeof_priv, txqs, rxqs);
  49. + if (!netdev) {
  50. + devres_free(dr);
  51. + return NULL;
  52. + }
  53. +
  54. + *dr = netdev;
  55. + devres_add(dev, dr);
  56. +
  57. + return netdev;
  58. +}
  59. +EXPORT_SYMBOL(devm_alloc_etherdev_mqs);
  60. +
  61. ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len)
  62. {
  63. return scnprintf(buf, PAGE_SIZE, "%*phC\n", len, addr);