mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: ore@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 4/9] net: dsa: factor out dsa_port_alloc helper
Date: Mon, 16 Jan 2023 14:44:56 +0100	[thread overview]
Message-ID: <20230116134501.2006391-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230116134501.2006391-1-a.fatoum@pengutronix.de>

We'll reuse this helper in a follow-up commit for allocating the CPU
port's struct dsa_port, so prepare for this by creating a helper
function.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/net/dsa.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/net/dsa.c b/drivers/net/dsa.c
index d51e9c861114..ea1a6a699698 100644
--- a/drivers/net/dsa.c
+++ b/drivers/net/dsa.c
@@ -235,10 +235,9 @@ static int dsa_ether_get_ethaddr(struct eth_device *edev, unsigned char *adr)
 	return edev_master->get_ethaddr(edev_master, adr);
 }
 
-static int dsa_switch_register_edev(struct dsa_switch *ds,
-				    struct device_node *dn, int port)
+static struct dsa_port *dsa_port_alloc(struct dsa_switch *ds,
+				       struct device_node *dn, int port)
 {
-	struct eth_device *edev;
 	struct device *dev;
 	struct dsa_port *dp;
 
@@ -248,14 +247,24 @@ static int dsa_switch_register_edev(struct dsa_switch *ds,
 	dev = of_platform_device_create(dn, ds->dev);
 	of_platform_device_dummy_drv(dev);
 	dp->dev = dev;
-
-	dp->rx_buf = xmalloc(DSA_PKTSIZE);
 	dp->ds = ds;
 	dp->index = port;
 
+	return dp;
+}
+
+static int dsa_switch_register_edev(struct dsa_switch *ds,
+				    struct device_node *dn, int port)
+{
+	struct eth_device *edev;
+	struct dsa_port *dp;
+
+	dp = dsa_port_alloc(ds, dn, port);
+	dp->rx_buf = xmalloc(DSA_PKTSIZE);
+
 	edev = &dp->edev;
 	edev->priv = dp;
-	edev->parent = dev;
+	edev->parent = dp->dev;
 	edev->init = dsa_port_probe;
 	edev->open = dsa_port_start;
 	edev->send = dsa_port_send;
-- 
2.30.2




  parent reply	other threads:[~2023-01-16 13:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-16 13:44 [PATCH 0/9] net: dsa: add Realtek (rtl8365mb/rtl8366rb) switch support Ahmad Fatoum
2023-01-16 13:44 ` [PATCH 1/9] driver: alias of_match_ptr and DRV_OF_COMPAT Ahmad Fatoum
2023-01-16 13:44 ` [PATCH 2/9] gpiolib: implement gpio_direction_input/output Ahmad Fatoum
2023-01-16 13:44 ` [PATCH 3/9] net: dsa: rename dsa_ops to dsa_switch_ops Ahmad Fatoum
2023-01-16 13:44 ` Ahmad Fatoum [this message]
2023-01-16 13:44 ` [PATCH 5/9] net: dsa: populate struct dsa_port::index/dev members Ahmad Fatoum
2023-01-16 13:44 ` [PATCH 6/9] net: dsa: always call port_pre_enable before port_enable Ahmad Fatoum
2023-01-16 13:44 ` [PATCH 7/9] net: dsa: add some helpers to ease porting kernel drivers Ahmad Fatoum
2023-01-16 13:45 ` [PATCH 8/9] net: dsa: add struct dsa_switch::priv member for driver use Ahmad Fatoum
2023-01-16 13:45 ` [PATCH 9/9] net: dsa: add Realtek (rtl8365mb/rtl8366rb) switch support Ahmad Fatoum
2023-01-23  8:21 ` [PATCH 0/9] " Sascha Hauer

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=20230116134501.2006391-5-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=ore@pengutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox