072-net-add-devm-version-of-alloc_etherdev_mqs-function.patch 2.3 KB

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