[PATCH net-next v3 1/2] net: phy: micrel: Introduce function __lan8814_ptp_probe_once

Horatiu Vultur posted 2 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH net-next v3 1/2] net: phy: micrel: Introduce function __lan8814_ptp_probe_once
Posted by Horatiu Vultur 1 month, 1 week ago
Introduce the function __lan8814_ptp_probe_once as this function will be
used also by lan8842 driver. This change doesn't have any functional
changes.

Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
---
 drivers/net/phy/micrel.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index 04bd744920b0d..42af075894bec 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -4242,7 +4242,8 @@ static void lan8814_ptp_init(struct phy_device *phydev)
 	phydev->default_timestamp = true;
 }
 
-static int lan8814_ptp_probe_once(struct phy_device *phydev)
+static int __lan8814_ptp_probe_once(struct phy_device *phydev, char *pin_name,
+				    size_t gpios)
 {
 	struct lan8814_shared_priv *shared = phy_package_get_priv(phydev);
 
@@ -4250,18 +4251,18 @@ static int lan8814_ptp_probe_once(struct phy_device *phydev)
 	mutex_init(&shared->shared_lock);
 
 	shared->pin_config = devm_kmalloc_array(&phydev->mdio.dev,
-						LAN8814_PTP_GPIO_NUM,
+						gpios,
 						sizeof(*shared->pin_config),
 						GFP_KERNEL);
 	if (!shared->pin_config)
 		return -ENOMEM;
 
-	for (int i = 0; i < LAN8814_PTP_GPIO_NUM; i++) {
+	for (int i = 0; i < gpios; i++) {
 		struct ptp_pin_desc *ptp_pin = &shared->pin_config[i];
 
 		memset(ptp_pin, 0, sizeof(*ptp_pin));
 		snprintf(ptp_pin->name,
-			 sizeof(ptp_pin->name), "lan8814_ptp_pin_%02d", i);
+			 sizeof(ptp_pin->name), "%s_%02d", pin_name, i);
 		ptp_pin->index = i;
 		ptp_pin->func =  PTP_PF_NONE;
 	}
@@ -4271,7 +4272,7 @@ static int lan8814_ptp_probe_once(struct phy_device *phydev)
 	shared->ptp_clock_info.max_adj = 31249999;
 	shared->ptp_clock_info.n_alarm = 0;
 	shared->ptp_clock_info.n_ext_ts = LAN8814_PTP_EXTTS_NUM;
-	shared->ptp_clock_info.n_pins = LAN8814_PTP_GPIO_NUM;
+	shared->ptp_clock_info.n_pins = gpios;
 	shared->ptp_clock_info.pps = 0;
 	shared->ptp_clock_info.supported_extts_flags = PTP_RISING_EDGE |
 						       PTP_FALLING_EDGE |
@@ -4318,6 +4319,12 @@ static int lan8814_ptp_probe_once(struct phy_device *phydev)
 	return 0;
 }
 
+static int lan8814_ptp_probe_once(struct phy_device *phydev)
+{
+	return __lan8814_ptp_probe_once(phydev, "lan8814_ptp_pin",
+					LAN8814_PTP_GPIO_NUM);
+}
+
 static void lan8814_setup_led(struct phy_device *phydev, int val)
 {
 	int temp;
-- 
2.34.1
Re: [PATCH net-next v3 1/2] net: phy: micrel: Introduce function __lan8814_ptp_probe_once
Posted by Jakub Kicinski 1 month ago
On Tue, 26 Aug 2025 09:10:59 +0200 Horatiu Vultur wrote:
> -static int lan8814_ptp_probe_once(struct phy_device *phydev)
> +static int __lan8814_ptp_probe_once(struct phy_device *phydev, char *pin_name,
> +				    size_t gpios)

nit: size_t for gpios seems excessive, n_pins is an int. I'm guessing
you chose it based on kmalloc_array() arg type but, yeah, not sure it
makes sense within this context..
Re: [PATCH net-next v3 1/2] net: phy: micrel: Introduce function __lan8814_ptp_probe_once
Posted by Horatiu Vultur 1 month ago
The 08/27/2025 17:49, Jakub Kicinski wrote:
> 
> On Tue, 26 Aug 2025 09:10:59 +0200 Horatiu Vultur wrote:
> > -static int lan8814_ptp_probe_once(struct phy_device *phydev)
> > +static int __lan8814_ptp_probe_once(struct phy_device *phydev, char *pin_name,
> > +                                 size_t gpios)
> 
> nit: size_t for gpios seems excessive, n_pins is an int. I'm guessing
> you chose it based on kmalloc_array() arg type but, yeah, not sure it
> makes sense within this context..

Yes, that is why I have chosen size_t. But I will update it in the next
version.


-- 
/Horatiu