diff mbox series

[01/12] net: phy: refactor phy_device_create function

Message ID 20230405-net-next-topic-net-phy-reset-v1-1-7e5329f08002@pengutronix.de (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series Rework PHY reset handling | expand

Checks

Context Check Description
netdev/series_format warning Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 28 this patch: 26
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang fail Errors and warnings before: 18 this patch: 27
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 28 this patch: 26
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 79 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Marco Felsch April 5, 2023, 9:26 a.m. UTC
Split phy_device_create() into local helper functions. This commit is in
preparation of fixing the phy reset handling. No functional changes for
the public API users.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/net/phy/phy_device.c | 42 ++++++++++++++++++++++++++++++------------
 1 file changed, 30 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 917ba84105fc..dd0aaa866d17 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -629,13 +629,10 @@  static int phy_request_driver_module(struct phy_device *dev, u32 phy_id)
 	return 0;
 }
 
-struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
-				     bool is_c45,
-				     struct phy_c45_device_ids *c45_ids)
+static struct phy_device *phy_device_alloc(struct mii_bus *bus, int addr)
 {
 	struct phy_device *dev;
 	struct mdio_device *mdiodev;
-	int ret = 0;
 
 	/* We allocate the device, and initialize the default values */
 	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
@@ -653,6 +650,15 @@  struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
 	mdiodev->device_free = phy_mdio_device_free;
 	mdiodev->device_remove = phy_mdio_device_remove;
 
+	dev_set_name(&mdiodev->dev, PHY_ID_FMT, bus->id, addr);
+	device_initialize(&mdiodev->dev);
+
+	return dev;
+}
+
+static int phy_device_init(struct phy_device *dev, u32 phy_id, bool is_c45,
+			   struct phy_c45_device_ids *c45_ids)
+{
 	dev->speed = SPEED_UNKNOWN;
 	dev->duplex = DUPLEX_UNKNOWN;
 	dev->pause = 0;
@@ -670,9 +676,6 @@  struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
 		dev->c45_ids = *c45_ids;
 	dev->irq = bus->irq[addr];
 
-	dev_set_name(&mdiodev->dev, PHY_ID_FMT, bus->id, addr);
-	device_initialize(&mdiodev->dev);
-
 	dev->state = PHY_DOWN;
 
 	mutex_init(&dev->lock);
@@ -690,7 +693,7 @@  struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
 	 */
 	if (is_c45 && c45_ids) {
 		const int num_ids = ARRAY_SIZE(c45_ids->device_ids);
-		int i;
+		int ret, i;
 
 		for (i = 1; i < num_ids; i++) {
 			if (c45_ids->device_ids[i] == 0xffffffff)
@@ -699,14 +702,29 @@  struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
 			ret = phy_request_driver_module(dev,
 						c45_ids->device_ids[i]);
 			if (ret)
-				break;
+				return ret;
 		}
-	} else {
-		ret = phy_request_driver_module(dev, phy_id);
+
+		return 0;
 	}
 
+	return phy_request_driver_module(dev, phy_id);
+}
+
+struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
+				     bool is_c45,
+				     struct phy_c45_device_ids *c45_ids)
+{
+	struct phy_device *dev;
+	int ret;
+
+	dev = phy_device_alloc(bus, addr);
+	if (IS_ERR(dev))
+		return dev;
+
+	ret = phy_device_init(dev, phy_id, is_c45, c45_ids);
 	if (ret) {
-		put_device(&mdiodev->dev);
+		put_device(&dev->mdio.dev);
 		dev = ERR_PTR(ret);
 	}