* [PATCH net-next 0/3] net: mdio: improve reset handling of mdio devices
@ 2025-10-31 11:32 Buday Csaba
2025-10-31 11:32 ` [PATCH net-next 1/3] net: mdio: move device reset functions to mdio_device.c Buday Csaba
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Buday Csaba @ 2025-10-31 11:32 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Philipp Zabel, netdev,
linux-kernel
Cc: Buday Csaba
This patchset refactors and slightly improves the reset handling of
`mdio_device`.
The patches were split from a larger series, dicussed previously in the
link below.
Link: https://lore.kernel.org/all/cover.1761732347.git.buday.csaba@prolan.hu/
Buday Csaba (3):
net: mdio: move device reset functions to mdio_device.c
net: mdio: common handling of phy device reset properties
net: mdio: improve reset handling in mdio_device.c
drivers/net/mdio/fwnode_mdio.c | 5 ----
drivers/net/phy/mdio_bus.c | 36 ++---------------------
drivers/net/phy/mdio_device.c | 53 ++++++++++++++++++++++++++++++++++
include/linux/mdio.h | 2 ++
4 files changed, 57 insertions(+), 39 deletions(-)
base-commit: 0d0eb186421d0886ac466008235f6d9eedaf918e
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next 1/3] net: mdio: move device reset functions to mdio_device.c
2025-10-31 11:32 [PATCH net-next 0/3] net: mdio: improve reset handling of mdio devices Buday Csaba
@ 2025-10-31 11:32 ` Buday Csaba
2025-10-31 11:32 ` [PATCH net-next 2/3] net: mdio: common handling of phy device reset properties Buday Csaba
2025-10-31 11:32 ` [PATCH net-next 3/3] net: mdio: improve reset handling in mdio_device.c Buday Csaba
2 siblings, 0 replies; 5+ messages in thread
From: Buday Csaba @ 2025-10-31 11:32 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Philipp Zabel, netdev,
linux-kernel
Cc: Buday Csaba
The functions mdiobus_register_gpiod() and mdiobus_register_reset()
handle the mdio device reset initialization, which belong to
mdio_device.c.
Move them from mdio_bus.c to mdio_device.c, and rename them to match
the corresponding source file: mdio_device_register_gpio() and
mdio_device_register_reset().
Remove 'static' qualifiers and declare them in mdio.h.
Signed-off-by: Buday Csaba <buday.csaba@prolan.hu>
---
drivers/net/phy/mdio_bus.c | 31 ++-----------------------------
drivers/net/phy/mdio_device.c | 27 +++++++++++++++++++++++++++
include/linux/mdio.h | 2 ++
3 files changed, 31 insertions(+), 29 deletions(-)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index cad6ed3aa..f23298232 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -33,33 +33,6 @@
#define CREATE_TRACE_POINTS
#include <trace/events/mdio.h>
-static int mdiobus_register_gpiod(struct mdio_device *mdiodev)
-{
- /* Deassert the optional reset signal */
- mdiodev->reset_gpio = gpiod_get_optional(&mdiodev->dev,
- "reset", GPIOD_OUT_LOW);
- if (IS_ERR(mdiodev->reset_gpio))
- return PTR_ERR(mdiodev->reset_gpio);
-
- if (mdiodev->reset_gpio)
- gpiod_set_consumer_name(mdiodev->reset_gpio, "PHY reset");
-
- return 0;
-}
-
-static int mdiobus_register_reset(struct mdio_device *mdiodev)
-{
- struct reset_control *reset;
-
- reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy");
- if (IS_ERR(reset))
- return PTR_ERR(reset);
-
- mdiodev->reset_ctrl = reset;
-
- return 0;
-}
-
int mdiobus_register_device(struct mdio_device *mdiodev)
{
int err;
@@ -68,11 +41,11 @@ int mdiobus_register_device(struct mdio_device *mdiodev)
return -EBUSY;
if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) {
- err = mdiobus_register_gpiod(mdiodev);
+ err = mdio_device_register_gpiod(mdiodev);
if (err)
return err;
- err = mdiobus_register_reset(mdiodev);
+ err = mdio_device_register_reset(mdiodev);
if (err)
return err;
diff --git a/drivers/net/phy/mdio_device.c b/drivers/net/phy/mdio_device.c
index f64176e0e..5a78d8624 100644
--- a/drivers/net/phy/mdio_device.c
+++ b/drivers/net/phy/mdio_device.c
@@ -118,6 +118,33 @@ void mdio_device_remove(struct mdio_device *mdiodev)
}
EXPORT_SYMBOL(mdio_device_remove);
+int mdio_device_register_gpiod(struct mdio_device *mdiodev)
+{
+ /* Deassert the optional reset signal */
+ mdiodev->reset_gpio = gpiod_get_optional(&mdiodev->dev,
+ "reset", GPIOD_OUT_LOW);
+ if (IS_ERR(mdiodev->reset_gpio))
+ return PTR_ERR(mdiodev->reset_gpio);
+
+ if (mdiodev->reset_gpio)
+ gpiod_set_consumer_name(mdiodev->reset_gpio, "PHY reset");
+
+ return 0;
+}
+
+int mdio_device_register_reset(struct mdio_device *mdiodev)
+{
+ struct reset_control *reset;
+
+ reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy");
+ if (IS_ERR(reset))
+ return PTR_ERR(reset);
+
+ mdiodev->reset_ctrl = reset;
+
+ return 0;
+}
+
void mdio_device_reset(struct mdio_device *mdiodev, int value)
{
unsigned int d;
diff --git a/include/linux/mdio.h b/include/linux/mdio.h
index 42d6d47e4..1322d2623 100644
--- a/include/linux/mdio.h
+++ b/include/linux/mdio.h
@@ -92,6 +92,8 @@ void mdio_device_free(struct mdio_device *mdiodev);
struct mdio_device *mdio_device_create(struct mii_bus *bus, int addr);
int mdio_device_register(struct mdio_device *mdiodev);
void mdio_device_remove(struct mdio_device *mdiodev);
+int mdio_device_register_gpiod(struct mdio_device *mdiodev);
+int mdio_device_register_reset(struct mdio_device *mdiodev);
void mdio_device_reset(struct mdio_device *mdiodev, int value);
int mdio_driver_register(struct mdio_driver *drv);
void mdio_driver_unregister(struct mdio_driver *drv);
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next 2/3] net: mdio: common handling of phy device reset properties
2025-10-31 11:32 [PATCH net-next 0/3] net: mdio: improve reset handling of mdio devices Buday Csaba
2025-10-31 11:32 ` [PATCH net-next 1/3] net: mdio: move device reset functions to mdio_device.c Buday Csaba
@ 2025-10-31 11:32 ` Buday Csaba
2025-10-31 11:32 ` [PATCH net-next 3/3] net: mdio: improve reset handling in mdio_device.c Buday Csaba
2 siblings, 0 replies; 5+ messages in thread
From: Buday Csaba @ 2025-10-31 11:32 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Philipp Zabel, netdev,
linux-kernel
Cc: Buday Csaba
Unify the handling of the per device reset properties for
`mdio_device`.
Merge mdio_device_register_gpiod() and mdio_device_register_reset()
into mdio_device_register_reset(), that handles both
reset-controllers and reset-gpios.
Move reading of the reset firmware properties (reset-assert-us,
reset-deassert-us) from fwnode_mdio.c to mdio_device_register_reset(),
so all reset related initialization code is kept in one place.
Introduce mdio_device_unregister_reset() to release the associated
resources.
These changes make tracking the reset properties easier.
Added kernel-doc for mdio_device_register/unregister_reset().
No functional changes intended.
Signed-off-by: Buday Csaba <buday.csaba@prolan.hu>
---
drivers/net/mdio/fwnode_mdio.c | 5 -----
drivers/net/phy/mdio_bus.c | 7 +------
drivers/net/phy/mdio_device.c | 35 ++++++++++++++++++++++++++--------
include/linux/mdio.h | 2 +-
4 files changed, 29 insertions(+), 20 deletions(-)
diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c
index 9b41d4697..ba7091518 100644
--- a/drivers/net/mdio/fwnode_mdio.c
+++ b/drivers/net/mdio/fwnode_mdio.c
@@ -92,11 +92,6 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio,
if (fwnode_property_read_bool(child, "broken-turn-around"))
mdio->phy_ignore_ta_mask |= 1 << addr;
- fwnode_property_read_u32(child, "reset-assert-us",
- &phy->mdio.reset_assert_delay);
- fwnode_property_read_u32(child, "reset-deassert-us",
- &phy->mdio.reset_deassert_delay);
-
/* Associate the fwnode with the device structure so it
* can be looked up later
*/
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index f23298232..748c6a9aa 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -41,10 +41,6 @@ int mdiobus_register_device(struct mdio_device *mdiodev)
return -EBUSY;
if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) {
- err = mdio_device_register_gpiod(mdiodev);
- if (err)
- return err;
-
err = mdio_device_register_reset(mdiodev);
if (err)
return err;
@@ -64,8 +60,7 @@ int mdiobus_unregister_device(struct mdio_device *mdiodev)
if (mdiodev->bus->mdio_map[mdiodev->addr] != mdiodev)
return -EINVAL;
- gpiod_put(mdiodev->reset_gpio);
- reset_control_put(mdiodev->reset_ctrl);
+ mdio_device_unregister_reset(mdiodev);
mdiodev->bus->mdio_map[mdiodev->addr] = NULL;
diff --git a/drivers/net/phy/mdio_device.c b/drivers/net/phy/mdio_device.c
index 5a78d8624..ec0263264 100644
--- a/drivers/net/phy/mdio_device.c
+++ b/drivers/net/phy/mdio_device.c
@@ -118,8 +118,17 @@ void mdio_device_remove(struct mdio_device *mdiodev)
}
EXPORT_SYMBOL(mdio_device_remove);
-int mdio_device_register_gpiod(struct mdio_device *mdiodev)
+/**
+ * mdio_device_register_reset - Read and initialize the reset properties of
+ * an mdio device
+ * @mdiodev: mdio_device structure
+ *
+ * Return: Zero if successful, negative error code on failure
+ */
+int mdio_device_register_reset(struct mdio_device *mdiodev)
{
+ struct reset_control *reset;
+
/* Deassert the optional reset signal */
mdiodev->reset_gpio = gpiod_get_optional(&mdiodev->dev,
"reset", GPIOD_OUT_LOW);
@@ -129,22 +138,32 @@ int mdio_device_register_gpiod(struct mdio_device *mdiodev)
if (mdiodev->reset_gpio)
gpiod_set_consumer_name(mdiodev->reset_gpio, "PHY reset");
- return 0;
-}
-
-int mdio_device_register_reset(struct mdio_device *mdiodev)
-{
- struct reset_control *reset;
-
reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy");
if (IS_ERR(reset))
return PTR_ERR(reset);
mdiodev->reset_ctrl = reset;
+ /* Read optional firmware properties */
+ fwnode_property_read_u32(dev_fwnode(&mdiodev->dev), "reset-assert-us",
+ &mdiodev->reset_assert_delay);
+ fwnode_property_read_u32(dev_fwnode(&mdiodev->dev), "reset-deassert-us",
+ &mdiodev->reset_deassert_delay);
+
return 0;
}
+/**
+ * mdio_device_unregister_reset - uninitialize the reset properties of
+ * an mdio device
+ * @mdiodev: mdio_device structure
+ */
+void mdio_device_unregister_reset(struct mdio_device *mdiodev)
+{
+ gpiod_put(mdiodev->reset_gpio);
+ reset_control_put(mdiodev->reset_ctrl);
+}
+
void mdio_device_reset(struct mdio_device *mdiodev, int value)
{
unsigned int d;
diff --git a/include/linux/mdio.h b/include/linux/mdio.h
index 1322d2623..e76f5a6c2 100644
--- a/include/linux/mdio.h
+++ b/include/linux/mdio.h
@@ -92,8 +92,8 @@ void mdio_device_free(struct mdio_device *mdiodev);
struct mdio_device *mdio_device_create(struct mii_bus *bus, int addr);
int mdio_device_register(struct mdio_device *mdiodev);
void mdio_device_remove(struct mdio_device *mdiodev);
-int mdio_device_register_gpiod(struct mdio_device *mdiodev);
int mdio_device_register_reset(struct mdio_device *mdiodev);
+void mdio_device_unregister_reset(struct mdio_device *mdiodev);
void mdio_device_reset(struct mdio_device *mdiodev, int value);
int mdio_driver_register(struct mdio_driver *drv);
void mdio_driver_unregister(struct mdio_driver *drv);
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next 3/3] net: mdio: improve reset handling in mdio_device.c
2025-10-31 11:32 [PATCH net-next 0/3] net: mdio: improve reset handling of mdio devices Buday Csaba
2025-10-31 11:32 ` [PATCH net-next 1/3] net: mdio: move device reset functions to mdio_device.c Buday Csaba
2025-10-31 11:32 ` [PATCH net-next 2/3] net: mdio: common handling of phy device reset properties Buday Csaba
@ 2025-10-31 11:32 ` Buday Csaba
2025-11-06 22:46 ` Jakub Kicinski
2 siblings, 1 reply; 5+ messages in thread
From: Buday Csaba @ 2025-10-31 11:32 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Philipp Zabel, netdev,
linux-kernel
Cc: Buday Csaba
Change fwnode_property_read_u32() in mdio_device_register_reset()
to device_property_read_u32(), which is more appropriate here.
Fix a potential leak in mdio_device_register_reset() if both
a reset-gpio and a reset-controller are present.
Make mdio_device_unregister_reset() truly reverse
mdio_device_register_reset() by setting the internal fields to
their default values.
Signed-off-by: Buday Csaba <buday.csaba@prolan.hu>
---
drivers/net/phy/mdio_device.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/net/phy/mdio_device.c b/drivers/net/phy/mdio_device.c
index ec0263264..2de401961 100644
--- a/drivers/net/phy/mdio_device.c
+++ b/drivers/net/phy/mdio_device.c
@@ -139,15 +139,18 @@ int mdio_device_register_reset(struct mdio_device *mdiodev)
gpiod_set_consumer_name(mdiodev->reset_gpio, "PHY reset");
reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy");
- if (IS_ERR(reset))
+ if (IS_ERR(reset)) {
+ gpiod_put(mdiodev->reset_gpio);
+ mdiodev->reset_gpio = NULL;
return PTR_ERR(reset);
+ }
mdiodev->reset_ctrl = reset;
/* Read optional firmware properties */
- fwnode_property_read_u32(dev_fwnode(&mdiodev->dev), "reset-assert-us",
+ device_property_read_u32(&mdiodev->dev, "reset-assert-us",
&mdiodev->reset_assert_delay);
- fwnode_property_read_u32(dev_fwnode(&mdiodev->dev), "reset-deassert-us",
+ device_property_read_u32(&mdiodev->dev, "reset-deassert-us",
&mdiodev->reset_deassert_delay);
return 0;
@@ -161,7 +164,11 @@ int mdio_device_register_reset(struct mdio_device *mdiodev)
void mdio_device_unregister_reset(struct mdio_device *mdiodev)
{
gpiod_put(mdiodev->reset_gpio);
+ mdiodev->reset_gpio = NULL;
reset_control_put(mdiodev->reset_ctrl);
+ mdiodev->reset_ctrl = NULL;
+ mdiodev->reset_assert_delay = 0;
+ mdiodev->reset_deassert_delay = 0;
}
void mdio_device_reset(struct mdio_device *mdiodev, int value)
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next 3/3] net: mdio: improve reset handling in mdio_device.c
2025-10-31 11:32 ` [PATCH net-next 3/3] net: mdio: improve reset handling in mdio_device.c Buday Csaba
@ 2025-11-06 22:46 ` Jakub Kicinski
0 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2025-11-06 22:46 UTC (permalink / raw)
To: Buday Csaba
Cc: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
Eric Dumazet, Paolo Abeni, Philipp Zabel, netdev, linux-kernel
On Fri, 31 Oct 2025 12:32:28 +0100 Buday Csaba wrote:
> reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy");
> - if (IS_ERR(reset))
> + if (IS_ERR(reset)) {
> + gpiod_put(mdiodev->reset_gpio);
> + mdiodev->reset_gpio = NULL;
> return PTR_ERR(reset);
> + }
We usually consider all sort of leaks as real fixes.
Let's fix this in mdiobus_register_device() in net/main first?
Then do the refactoring once net merges into net-next (every Thu)?
--
pw-bot: cr
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-11-06 22:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-31 11:32 [PATCH net-next 0/3] net: mdio: improve reset handling of mdio devices Buday Csaba
2025-10-31 11:32 ` [PATCH net-next 1/3] net: mdio: move device reset functions to mdio_device.c Buday Csaba
2025-10-31 11:32 ` [PATCH net-next 2/3] net: mdio: common handling of phy device reset properties Buday Csaba
2025-10-31 11:32 ` [PATCH net-next 3/3] net: mdio: improve reset handling in mdio_device.c Buday Csaba
2025-11-06 22:46 ` Jakub Kicinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).