All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amit Pundir <amit.pundir@linaro.org>
To: stable@vger.kernel.org
Cc: gregkh@linuxfoundation.org, "Rafał Miłecki" <rafal@milecki.pl>,
	"David S . Miller" <davem@davemloft.net>
Subject: [PATCH v2 for-4.9 18/32] net: add devm version of alloc_etherdev_mqs function
Date: Wed,  5 Apr 2017 16:02:10 +0530	[thread overview]
Message-ID: <1491388344-13521-19-git-send-email-amit.pundir@linaro.org> (raw)
In-Reply-To: <1491388344-13521-1-git-send-email-amit.pundir@linaro.org>

From: Rafał Miłecki <rafal@milecki.pl>

This patch adds devm_alloc_etherdev_mqs function and devm_alloc_etherdev
macro. These can be used for simpler netdev allocation without having to
care about calling free_netdev.

Thanks to this change drivers, their error paths and removal paths may
get simpler by a bit.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 40be0dda0725886b623d67868db3219a2e74683b)
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
---
 include/linux/etherdevice.h |  5 +++++
 net/ethernet/eth.c          | 28 ++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index 6fec9e8..83ae88c 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -54,6 +54,11 @@ struct net_device *alloc_etherdev_mqs(int sizeof_priv, unsigned int txqs,
 #define alloc_etherdev(sizeof_priv) alloc_etherdev_mq(sizeof_priv, 1)
 #define alloc_etherdev_mq(sizeof_priv, count) alloc_etherdev_mqs(sizeof_priv, count, count)
 
+struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv,
+					   unsigned int txqs,
+					   unsigned int rxqs);
+#define devm_alloc_etherdev(dev, sizeof_priv) devm_alloc_etherdev_mqs(dev, sizeof_priv, 1, 1)
+
 struct sk_buff **eth_gro_receive(struct sk_buff **head,
 				 struct sk_buff *skb);
 int eth_gro_complete(struct sk_buff *skb, int nhoff);
diff --git a/net/ethernet/eth.c b/net/ethernet/eth.c
index 24d7aff..fbf1de9 100644
--- a/net/ethernet/eth.c
+++ b/net/ethernet/eth.c
@@ -391,6 +391,34 @@ struct net_device *alloc_etherdev_mqs(int sizeof_priv, unsigned int txqs,
 }
 EXPORT_SYMBOL(alloc_etherdev_mqs);
 
+static void devm_free_netdev(struct device *dev, void *res)
+{
+	free_netdev(*(struct net_device **)res);
+}
+
+struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv,
+					   unsigned int txqs, unsigned int rxqs)
+{
+	struct net_device **dr;
+	struct net_device *netdev;
+
+	dr = devres_alloc(devm_free_netdev, sizeof(*dr), GFP_KERNEL);
+	if (!dr)
+		return NULL;
+
+	netdev = alloc_etherdev_mqs(sizeof_priv, txqs, rxqs);
+	if (!netdev) {
+		devres_free(dr);
+		return NULL;
+	}
+
+	*dr = netdev;
+	devres_add(dev, dr);
+
+	return netdev;
+}
+EXPORT_SYMBOL(devm_alloc_etherdev_mqs);
+
 ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len)
 {
 	return scnprintf(buf, PAGE_SIZE, "%*phC\n", len, addr);
-- 
2.7.4

  parent reply	other threads:[~2017-04-05 10:33 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-05 10:31 [PATCH v2 for-4.9 00/32] Stable commits picked up from lede project Amit Pundir
2017-04-05 10:31 ` [PATCH v2 for-4.9 01/32] ARM: BCM5301X: Add back handler ignoring external imprecise aborts Amit Pundir
2017-04-05 10:31 ` [PATCH v2 for-4.9 02/32] ARM: dts: BCM5301X: Correct GIC_PPI interrupt flags Amit Pundir
2017-04-06  7:33   ` Greg KH
2017-04-05 10:31 ` [PATCH v2 for-4.9 03/32] PCI: iproc: Save host bridge window resource in struct iproc_pcie Amit Pundir
2017-04-06  7:33   ` Greg KH
2017-04-05 10:31 ` [PATCH v2 for-4.9 04/32] MIPS: Lantiq: Fix cascaded IRQ setup Amit Pundir
2017-04-06  7:34   ` Greg KH
2017-04-06  9:29   ` James Hogan
2017-04-06  9:29     ` James Hogan
2017-04-06 10:53     ` Amit Pundir
2017-04-06 11:25       ` James Hogan
2017-04-06 11:25         ` James Hogan
2017-04-06 11:44         ` Amit Pundir
2017-04-05 10:31 ` [PATCH v2 for-4.9 05/32] i2c: bcm2835: Fix hang for writing messages larger than 16 bytes Amit Pundir
2017-04-05 10:31 ` [PATCH v2 for-4.9 06/32] i2c: bcm2835: Protect against unexpected TXW/RXR interrupts Amit Pundir
2017-04-05 10:31 ` [PATCH v2 for-4.9 07/32] i2c: bcm2835: Use dev_dbg logging on transfer errors Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 08/32] i2c: bcm2835: Can't support I2C_M_IGNORE_NAK Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 09/32] clk: bcm: Support rate change propagation on bcm2835 clocks Amit Pundir
2017-04-12 13:17   ` Greg KH
2017-04-12 13:33     ` Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 10/32] clk: bcm: Allow rate change propagation to PLLH_AUX on VEC clock Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 11/32] clk: bcm: Fix 'maybe-uninitialized' warning in bcm2835_clock_choose_div_and_prate() Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 12/32] clk: bcm2835: Don't rate change PLLs on behalf of DSI PLL dividers Amit Pundir
2017-04-06 16:53   ` Eric Anholt
2017-04-05 10:32 ` [PATCH v2 for-4.9 13/32] clk: bcm2835: Register the DSI0/DSI1 pixel clocks Amit Pundir
2017-04-12 13:15   ` Greg KH
2017-04-05 10:32 ` [PATCH v2 for-4.9 14/32] clk: bcm2835: Add leaf clock measurement support, disabled by default Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 15/32] dmaengine: bcm2835: Fix cyclic DMA period splitting Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 16/32] usb: dwc2: Remove unnecessary kfree Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 17/32] mtd: bcm47xxpart: fix parsing first block after aligned TRX Amit Pundir
2017-04-05 10:32 ` Amit Pundir [this message]
2017-04-05 10:32 ` [PATCH v2 for-4.9 19/32] net: bgmac: allocate struct bgmac just once & don't copy it Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 20/32] net: bgmac: drop struct bcma_mdio we don't need anymore Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 21/32] of: Add check to of_scan_flat_dt() before accessing initial_boot_params Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 22/32] rt2500usb: don't mark register accesses as inline Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 23/32] brcmfmac: check brcmf_bus_get_memdump result for error Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 24/32] brcmfmac: be more verbose when PSM's watchdog fires Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 25/32] brcmfmac: merge two brcmf_err macros into one Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 26/32] brcmfmac: switch to C function (__brcmf_err) for printing errors Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 27/32] brcmfmac: merge two remaining brcmf_err macros Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 28/32] rt2x00usb: do not anchor rx and tx urb's Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 29/32] rt2x00usb: fix anchor initialization Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 30/32] brcmfmac: Use net_device_stats from struct net_device Amit Pundir
2017-04-12 13:18   ` Greg KH
2017-04-12 13:46     ` Tobias Klauser
2017-04-12 13:52     ` Kalle Valo
2017-04-12 14:29       ` Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 31/32] rt2x00: Fix incorrect usage of CONFIG_RT2X00_LIB_USB Amit Pundir
2017-04-05 10:32 ` [PATCH v2 for-4.9 32/32] rt2x00: avoid introducing a USB dependency in the rt2x00lib module Amit Pundir
2017-04-06  7:29 ` [PATCH v2 for-4.9 00/32] Stable commits picked up from lede project Greg KH
2017-04-06  7:44   ` Amit Pundir

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1491388344-13521-19-git-send-email-amit.pundir@linaro.org \
    --to=amit.pundir@linaro.org \
    --cc=davem@davemloft.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=rafal@milecki.pl \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.