Skip to contentSkip to conversation

ptp: ocp: A fix and refactoring

PATCH Applied Andy Shevchenko 2 participants 6 messages Nov 24, 2025 – Nov 26, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover ptp: ocp: A fix and refactoring

Here is the fix for incorrect use of %ptT with the associated refactoring and additional cleanups.

Note, %ptS, which is introduced in another series that is already applied to PRINTK tree, doesn't fit here, that's why this fix is separated from that series.

Changelog v2:
- dropped patches under discussion (Vadim)
- collected tags (Vadim)

v1: <[email protected]>

Andy Shevchenko (4):
ptp: ocp: Refactor signal_show() and fix %ptT misuse
ptp: ocp: Make ptp_ocp_unregister_ext() NULL-aware
ptp: ocp: Apply standard pattern for cleaning up loop
ptp: ocp: Reuse META's PCI vendor ID

 drivers/ptp/ptp_ocp.c | 46 +++++++++++++++++--------------------------
 1 file changed, 18 insertions(+), 28 deletions(-)
Signature · 1 line
2.50.1
#1 lore raw

PATCH v2 1/4 ptp: ocp: Refactor signal_show() and fix %ptT misuse

Refactor signal_show() to avoid sequential calls to sysfs_emit*() and use the same pattern to get the index of a signal as it's done in signal_store().

While at it, fix wrong use of %ptT against struct timespec64. It's kinda lucky that it worked just because the first member there 64-bit and it's of time64_t type. Now with %ptS it may be used correctly.

---
 drivers/ptp/ptp_ocp.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/ptp/ptp_ocp.c +5 -9
index 21a8109fae34..49bad0f83779 100644
@@ -3250,20 +3250,16 @@ signal_show(struct device *dev, struct device_attribute *attr, char *buf)
 	struct dev_ext_attribute *ea = to_ext_attr(attr);
 	struct ptp_ocp *bp = dev_get_drvdata(dev);
 	struct ptp_ocp_signal *signal;
+	int gen = (uintptr_t)ea->var;
 	struct timespec64 ts;
-	ssize_t count;
-	int i;
 
-	i = (uintptr_t)ea->var;
-	signal = &bp->signal[i];
-
-	count = sysfs_emit(buf, "%llu %d %llu %d", signal->period,
-			   signal->duty, signal->phase, signal->polarity);
+	signal = &bp->signal[gen];
 
 	ts = ktime_to_timespec64(signal->start);
-	count += sysfs_emit_at(buf, count, " %ptT TAI\n", &ts);
 
-	return count;
+	return sysfs_emit(buf, "%llu %d %llu %d %ptT TAI\n",
+			  signal->period, signal->duty, signal->phase, signal->polarity,
+			  &ts.tv_sec);
 }
 static EXT_ATTR_RW(signal, signal, 0);
 static EXT_ATTR_RW(signal, signal, 1);
Signature · 1 line
2.50.1
#2 lore raw

PATCH v2 2/4 ptp: ocp: Make ptp_ocp_unregister_ext() NULL-aware

In reply to Andy Shevchenko

It's a common practice to make resource release functions be NULL-aware. Make ptp_ocp_unregister_ext() NULL-aware.

---
 drivers/ptp/ptp_ocp.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)
drivers/ptp/ptp_ocp.c +10 -14
index 49bad0f83779..1fd2243e0f9f 100644
@@ -2225,6 +2225,9 @@ ptp_ocp_ts_enable(void *priv, u32 req, bool enable)
 static void
 ptp_ocp_unregister_ext(struct ptp_ocp_ext_src *ext)
 {
+	if (!ext)
+		return;
+
 	ext->info->enable(ext, ~0, false);
 	pci_free_irq(ext->bp->pdev, ext->irq_vec, ext);
 	kfree(ext);
@@ -4555,21 +4558,14 @@ ptp_ocp_detach(struct ptp_ocp *bp)
 	ptp_ocp_detach_sysfs(bp);
 	ptp_ocp_attr_group_del(bp);
 	timer_delete_sync(&bp->watchdog);
-	if (bp->ts0)
-		ptp_ocp_unregister_ext(bp->ts0);
-	if (bp->ts1)
-		ptp_ocp_unregister_ext(bp->ts1);
-	if (bp->ts2)
-		ptp_ocp_unregister_ext(bp->ts2);
-	if (bp->ts3)
-		ptp_ocp_unregister_ext(bp->ts3);
-	if (bp->ts4)
-		ptp_ocp_unregister_ext(bp->ts4);
-	if (bp->pps)
-		ptp_ocp_unregister_ext(bp->pps);
+	ptp_ocp_unregister_ext(bp->ts0);
+	ptp_ocp_unregister_ext(bp->ts1);
+	ptp_ocp_unregister_ext(bp->ts2);
+	ptp_ocp_unregister_ext(bp->ts3);
+	ptp_ocp_unregister_ext(bp->ts4);
+	ptp_ocp_unregister_ext(bp->pps);
 	for (i = 0; i < 4; i++)
-		if (bp->signal_out[i])
-			ptp_ocp_unregister_ext(bp->signal_out[i]);
+		ptp_ocp_unregister_ext(bp->signal_out[i]);
 	for (i = 0; i < __PORT_COUNT; i++)
 		if (bp->port[i].line != -1)
 			serial8250_unregister_port(bp->port[i].line);
Signature · 1 line
2.50.1
#3 lore raw

PATCH v2 3/4 ptp: ocp: Apply standard pattern for cleaning up loop

In reply to Andy Shevchenko

The while (i--) is a standard pattern for the cleaning up loops. Apply this pattern where it makes sense in the driver.

---
 drivers/ptp/ptp_ocp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/ptp/ptp_ocp.c +1 -2
index 1fd2243e0f9f..63c73a5909f2 100644
@@ -4818,8 +4818,7 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	return 0;
 out_dpll:
-	while (i) {
-		--i;
+	while (i--) {
 		dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]);
 		dpll_pin_put(bp->sma[i].dpll_pin);
 	}
Signature · 1 line
2.50.1
#4 lore raw

PATCH v2 4/4 ptp: ocp: Reuse META's PCI vendor ID

In reply to Andy Shevchenko

The META's PCI vendor ID is listed already in the pci_ids.h. Reuse it here.

---
 drivers/ptp/ptp_ocp.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/ptp/ptp_ocp.c +2 -3
index 63c73a5909f2..65fe05cac8c4 100644
@@ -25,8 +25,7 @@
 #include <linux/crc16.h>
 #include <linux/dpll.h>
 
-#define PCI_VENDOR_ID_FACEBOOK			0x1d9b
-#define PCI_DEVICE_ID_FACEBOOK_TIMECARD		0x0400
+#define PCI_DEVICE_ID_META_TIMECARD		0x0400
 
 #define PCI_VENDOR_ID_CELESTICA			0x18d4
 #define PCI_DEVICE_ID_CELESTICA_TIMECARD	0x1008
@@ -1030,7 +1029,7 @@ static struct ocp_resource ocp_adva_resource[] = {
 };
 
 static const struct pci_device_id ptp_ocp_pcidev_id[] = {
-	{ PCI_DEVICE_DATA(FACEBOOK, TIMECARD, &ocp_fb_resource) },
+	{ PCI_DEVICE_DATA(META, TIMECARD, &ocp_fb_resource) },
 	{ PCI_DEVICE_DATA(CELESTICA, TIMECARD, &ocp_fb_resource) },
 	{ PCI_DEVICE_DATA(OROLIA, ARTCARD, &ocp_art_resource) },
 	{ PCI_DEVICE_DATA(ADVA, TIMECARD, &ocp_adva_resource) },
Signature · 1 line
2.50.1
#5 lore raw
In reply to Andy Shevchenko
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Mon, 24 Nov 2025 09:45:44 +0100 you wrote:

Here is the fix for incorrect use of %ptT with the associated refactoring and additional cleanups.

Note, %ptS, which is introduced in another series that is already applied to PRINTK tree, doesn't fit here, that's why this fix is separated from that series.

[...]

Here is the summary with links:
- [net-next,v2,1/4] ptp: ocp: Refactor signal_show() and fix %ptT misuse

    https://git.kernel.org/netdev/net-next/c/622cc66ed72c
  - [net-next,v2,2/4] ptp: ocp: Make ptp_ocp_unregister_ext() NULL-aware
    https://git.kernel.org/netdev/net-next/c/590f5d1fa6ee
  - [net-next,v2,3/4] ptp: ocp: Apply standard pattern for cleaning up loop
    https://git.kernel.org/netdev/net-next/c/4c84a5c7b095
  - [net-next,v2,4/4] ptp: ocp: Reuse META's PCI vendor ID
    https://git.kernel.org/netdev/net-next/c/648282e2d1e5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html