netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] ptp: ocp: A fix and refactoring
@ 2025-11-24  8:45 Andy Shevchenko
  2025-11-24  8:45 ` [PATCH net-next v2 1/4] ptp: ocp: Refactor signal_show() and fix %ptT misuse Andy Shevchenko
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Andy Shevchenko @ 2025-11-24  8:45 UTC (permalink / raw)
  To: Vadim Fedorenko, Andy Shevchenko, netdev, linux-kernel
  Cc: Jonathan Lemon, Richard Cochran, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni

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: <20251111165232.1198222-1-andriy.shevchenko@linux.intel.com>

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(-)

-- 
2.50.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net-next v2 1/4] ptp: ocp: Refactor signal_show() and fix %ptT misuse
  2025-11-24  8:45 [PATCH v2 0/4] ptp: ocp: A fix and refactoring Andy Shevchenko
@ 2025-11-24  8:45 ` Andy Shevchenko
  2025-11-24  8:45 ` [PATCH net-next v2 2/4] ptp: ocp: Make ptp_ocp_unregister_ext() NULL-aware Andy Shevchenko
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2025-11-24  8:45 UTC (permalink / raw)
  To: Vadim Fedorenko, Andy Shevchenko, netdev, linux-kernel
  Cc: Jonathan Lemon, Richard Cochran, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni

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.

Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/ptp/ptp_ocp.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 21a8109fae34..49bad0f83779 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -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);
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next v2 2/4] ptp: ocp: Make ptp_ocp_unregister_ext() NULL-aware
  2025-11-24  8:45 [PATCH v2 0/4] ptp: ocp: A fix and refactoring Andy Shevchenko
  2025-11-24  8:45 ` [PATCH net-next v2 1/4] ptp: ocp: Refactor signal_show() and fix %ptT misuse Andy Shevchenko
@ 2025-11-24  8:45 ` Andy Shevchenko
  2025-11-24  8:45 ` [PATCH net-next v2 3/4] ptp: ocp: Apply standard pattern for cleaning up loop Andy Shevchenko
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2025-11-24  8:45 UTC (permalink / raw)
  To: Vadim Fedorenko, Andy Shevchenko, netdev, linux-kernel
  Cc: Jonathan Lemon, Richard Cochran, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni

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

Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/ptp/ptp_ocp.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 49bad0f83779..1fd2243e0f9f 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -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);
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next v2 3/4] ptp: ocp: Apply standard pattern for cleaning up loop
  2025-11-24  8:45 [PATCH v2 0/4] ptp: ocp: A fix and refactoring Andy Shevchenko
  2025-11-24  8:45 ` [PATCH net-next v2 1/4] ptp: ocp: Refactor signal_show() and fix %ptT misuse Andy Shevchenko
  2025-11-24  8:45 ` [PATCH net-next v2 2/4] ptp: ocp: Make ptp_ocp_unregister_ext() NULL-aware Andy Shevchenko
@ 2025-11-24  8:45 ` Andy Shevchenko
  2025-11-24  8:45 ` [PATCH net-next v2 4/4] ptp: ocp: Reuse META's PCI vendor ID Andy Shevchenko
  2025-11-26  3:20 ` [PATCH v2 0/4] ptp: ocp: A fix and refactoring patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2025-11-24  8:45 UTC (permalink / raw)
  To: Vadim Fedorenko, Andy Shevchenko, netdev, linux-kernel
  Cc: Jonathan Lemon, Richard Cochran, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni

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

Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/ptp/ptp_ocp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 1fd2243e0f9f..63c73a5909f2 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -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);
 	}
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next v2 4/4] ptp: ocp: Reuse META's PCI vendor ID
  2025-11-24  8:45 [PATCH v2 0/4] ptp: ocp: A fix and refactoring Andy Shevchenko
                   ` (2 preceding siblings ...)
  2025-11-24  8:45 ` [PATCH net-next v2 3/4] ptp: ocp: Apply standard pattern for cleaning up loop Andy Shevchenko
@ 2025-11-24  8:45 ` Andy Shevchenko
  2025-11-26  3:20 ` [PATCH v2 0/4] ptp: ocp: A fix and refactoring patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2025-11-24  8:45 UTC (permalink / raw)
  To: Vadim Fedorenko, Andy Shevchenko, netdev, linux-kernel
  Cc: Jonathan Lemon, Richard Cochran, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni

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

Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/ptp/ptp_ocp.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 63c73a5909f2..65fe05cac8c4 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -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) },
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/4] ptp: ocp: A fix and refactoring
  2025-11-24  8:45 [PATCH v2 0/4] ptp: ocp: A fix and refactoring Andy Shevchenko
                   ` (3 preceding siblings ...)
  2025-11-24  8:45 ` [PATCH net-next v2 4/4] ptp: ocp: Reuse META's PCI vendor ID Andy Shevchenko
@ 2025-11-26  3:20 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-11-26  3:20 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: vadim.fedorenko, netdev, linux-kernel, jonathan.lemon,
	richardcochran, andrew+netdev, davem, edumazet, kuba, pabeni

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-11-26  3:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-24  8:45 [PATCH v2 0/4] ptp: ocp: A fix and refactoring Andy Shevchenko
2025-11-24  8:45 ` [PATCH net-next v2 1/4] ptp: ocp: Refactor signal_show() and fix %ptT misuse Andy Shevchenko
2025-11-24  8:45 ` [PATCH net-next v2 2/4] ptp: ocp: Make ptp_ocp_unregister_ext() NULL-aware Andy Shevchenko
2025-11-24  8:45 ` [PATCH net-next v2 3/4] ptp: ocp: Apply standard pattern for cleaning up loop Andy Shevchenko
2025-11-24  8:45 ` [PATCH net-next v2 4/4] ptp: ocp: Reuse META's PCI vendor ID Andy Shevchenko
2025-11-26  3:20 ` [PATCH v2 0/4] ptp: ocp: A fix and refactoring patchwork-bot+netdevbpf

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).