From: Ahmad Byagowi <ahmadexp@gmail.com>
To: netdev@vger.kernel.org
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, richardcochran@gmail.com,
rmk+kernel@armlinux.org.uk, vadim.fedorenko@linux.dev,
vladimir.oltean@nxp.com
Subject: [PATCH net v7 2/2] ptp: shut down enabled unassigned EXTTS channels on unregister
Date: Fri, 27 Nov 2026 11:20:37 -0800 [thread overview]
Message-ID: <20261127-timecard-core-v7-2-ahmadexp@gmail.com> (raw)
In-Reply-To: <20261127-timecard-core-v7-0-ahmadexp@gmail.com>
EXTTS requests can enable a channel without an assigned pin. The
unregister path only disables assigned EXTTS pins, so an enabled
unassigned channel can remain armed when resources are released.
Track successful ioctl and sysfs enables under pincfg_mux. Clear the
bit on successful disable, including when changing a pin assignment.
On unregister keep the existing assigned-pin cleanup and send one
disable for each tracked channel, before disabling PPS. Do not send
requests to unassigned channels that were never enabled. This avoids
calling drivers that can change the pin mux on an EXTTS disable.
The calls still follow POSIX clock unregister and precede PPS source
release. This patch does not change any driver or any pin assignment.
Developed with coding-assistant support using the v5 and v6 review.
Fixes: a60fc3294a37 ("ptp: rework ptp_clock_unregister() to disable events")
Link: https://lore.kernel.org/r/179579937848.3135.14198689317939903929@kernel.org
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
drivers/ptp/ptp_chardev.c | 53 +++++++++++++++++++++++++++++++--------
drivers/ptp/ptp_clock.c | 11 ++++++++
drivers/ptp/ptp_private.h | 7 +++++-
drivers/ptp/ptp_sysfs.c | 2 +-
4 files changed, 61 insertions(+), 12 deletions(-)
diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
index f63b45f5ee6a..b2e198c65e7e 100644
--- a/drivers/ptp/ptp_chardev.c
+++ b/drivers/ptp/ptp_chardev.c
@@ -17,9 +17,28 @@
#include "ptp_private.h"
-static int ptp_disable_pinfunc(struct ptp_clock_info *ops,
+int ptp_extts_enable(struct ptp_clock *ptp, struct ptp_clock_request *req,
+ bool enable)
+{
+ struct ptp_clock_info *info = ptp->info;
+ unsigned int chan = req->extts.index;
+ int err;
+
+ lockdep_assert_held(&ptp->pincfg_mux);
+ if (info->n_ext_ts <= 0 || chan >= info->n_ext_ts)
+ return -EINVAL;
+
+ err = info->enable(info, req, enable);
+ if (!err)
+ __assign_bit(chan, ptp->extts_enabled, enable);
+
+ return err;
+}
+
+static int ptp_disable_pinfunc(struct ptp_clock *ptp,
enum ptp_pin_function func, unsigned int chan)
{
+ struct ptp_clock_info *ops = ptp->info;
struct ptp_clock_request rq;
int err = 0;
@@ -31,7 +50,7 @@ static int ptp_disable_pinfunc(struct ptp_clock_info *ops,
case PTP_PF_EXTTS:
rq.type = PTP_CLK_REQ_EXTTS;
rq.extts.index = chan;
- err = ops->enable(ops, &rq, 0);
+ err = ptp_extts_enable(ptp, &rq, false);
break;
case PTP_PF_PEROUT:
rq.type = PTP_CLK_REQ_PEROUT;
@@ -50,14 +69,28 @@ static int ptp_disable_pinfunc(struct ptp_clock_info *ops,
void ptp_disable_all_events(struct ptp_clock *ptp)
{
struct ptp_clock_info *info = ptp->info;
+ struct ptp_clock_request req = { .type = PTP_CLK_REQ_EXTTS };
+ unsigned long chan;
unsigned int i;
mutex_lock(&ptp->pincfg_mux);
- /* Disable any pins that may raise EXTTS events */
- for (i = 0; i < info->n_pins; i++)
- if (info->pin_config[i].func == PTP_PF_EXTTS)
- ptp_disable_pinfunc(info, info->pin_config[i].func,
- info->pin_config[i].chan);
+ /* Retain existing cleanup for assigned pins not tracked below. */
+ for (i = 0; i < info->n_pins; i++) {
+ const struct ptp_pin_desc *pin = &info->pin_config[i];
+
+ if (pin->func == PTP_PF_EXTTS && info->n_ext_ts > 0 &&
+ pin->chan < info->n_ext_ts &&
+ !test_bit(pin->chan, ptp->extts_enabled))
+ ptp_disable_pinfunc(ptp, pin->func, pin->chan);
+ }
+
+ /* A successful EXTTS request need not have an assigned pin. */
+ if (info->n_ext_ts > 0) {
+ for_each_set_bit(chan, ptp->extts_enabled, info->n_ext_ts) {
+ req.extts.index = chan;
+ info->enable(info, &req, 0);
+ }
+ }
/* Disable the PPS event if the driver has PPS support */
if (info->pps) {
@@ -115,7 +148,7 @@ int ptp_set_pinfunc(struct ptp_clock *ptp, unsigned int pin,
* channel.
*/
if (pin1) {
- ptp_disable_pinfunc(info, func, chan);
+ ptp_disable_pinfunc(ptp, func, chan);
pin1->func = PTP_PF_NONE;
pin1->chan = 0;
}
@@ -123,7 +156,7 @@ int ptp_set_pinfunc(struct ptp_clock *ptp, unsigned int pin,
/* Disable whatever function was previously assigned to the requested
* pin.
*/
- ptp_disable_pinfunc(info, pin2->func, pin2->chan);
+ ptp_disable_pinfunc(ptp, pin2->func, pin2->chan);
pin2->func = func;
pin2->chan = chan;
@@ -241,7 +274,7 @@ static long ptp_extts_request(struct ptp_clock *ptp, unsigned int cmd, void __us
return -EOPNOTSUPP;
scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &ptp->pincfg_mux)
- return ops->enable(ops, &req, req.extts.flags & PTP_ENABLE_FEATURE ? 1 : 0);
+ return ptp_extts_enable(ptp, &req, req.extts.flags & PTP_ENABLE_FEATURE);
}
static long ptp_perout_request(struct ptp_clock *ptp, unsigned int cmd, void __user *arg)
diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index 47ffc773065a..10f8dccdea4f 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -219,6 +219,7 @@ static void ptp_clock_release(struct device *dev)
ptp_cleanup_pin_groups(ptp);
kfree(ptp->vclock_index);
+ bitmap_free(ptp->extts_enabled);
mutex_destroy(&ptp->pincfg_mux);
mutex_destroy(&ptp->n_vclocks_mux);
/* Delete first entry */
@@ -346,6 +347,14 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
goto no_memory;
}
+ if (info->n_ext_ts > 0) {
+ ptp->extts_enabled = bitmap_zalloc(info->n_ext_ts, GFP_KERNEL);
+ if (!ptp->extts_enabled) {
+ err = -ENOMEM;
+ goto no_extts_bitmap;
+ }
+ }
+
err = xa_alloc(&ptp_clocks_map, &index, ptp, xa_limit_31b,
GFP_KERNEL);
if (err)
@@ -492,6 +501,8 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
no_memory_queue:
xa_erase(&ptp_clocks_map, index);
no_slot:
+ bitmap_free(ptp->extts_enabled);
+no_extts_bitmap:
kfree(ptp);
no_memory:
return ERR_PTR(err);
diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
index 99e7eb241336..0ad8b53405af 100644
--- a/drivers/ptp/ptp_private.h
+++ b/drivers/ptp/ptp_private.h
@@ -51,7 +51,8 @@ struct ptp_clock {
long dialed_frequency; /* remembers the frequency adjustment */
struct list_head tsevqs; /* timestamp fifo list */
spinlock_t tsevqs_lock; /* protects tsevqs from concurrent access */
- struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
+ struct mutex pincfg_mux; /* protects pin configuration and enable state */
+ unsigned long *extts_enabled;
wait_queue_head_t tsev_wq;
int defunct; /* tells readers to go away when clock is being removed */
struct device_attribute *pin_dev_attr;
@@ -148,6 +149,10 @@ extern const struct class ptp_class;
void ptp_disable_all_events(struct ptp_clock *ptp);
+/* Caller must hold pincfg_mux. */
+int ptp_extts_enable(struct ptp_clock *ptp, struct ptp_clock_request *req,
+ bool enable);
+
/* caller must hold pincfg_mux */
int ptp_set_pinfunc(struct ptp_clock *ptp, unsigned int pin,
enum ptp_pin_function func, unsigned int chan);
diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
index 90fdddc1e6a7..1583f8d75907 100644
--- a/drivers/ptp/ptp_sysfs.c
+++ b/drivers/ptp/ptp_sysfs.c
@@ -62,7 +62,7 @@ static ssize_t extts_enable_store(struct device *dev,
if (mutex_lock_interruptible(&ptp->pincfg_mux))
return -ERESTARTSYS;
- err = ops->enable(ops, &req, enable ? 1 : 0);
+ err = ptp_extts_enable(ptp, &req, enable);
mutex_unlock(&ptp->pincfg_mux);
if (err)
goto out;
--
2.54.0 (Apple Git-157)
next prev parent reply other threads:[~2026-11-27 19:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 19:20 [PATCH net v7 0/2] ptp: serialize requests and stop active EXTTS Ahmad Byagowi
2026-11-27 19:20 ` [PATCH net v7 1/2] ptp: serialize sysfs enable requests with ioctl paths Ahmad Byagowi
2026-11-27 19:20 ` Ahmad Byagowi [this message]
2026-11-27 19:24 ` [PATCH net v7 0/2] ptp: serialize requests and stop active EXTTS netdev-bot+sinfo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261127-timecard-core-v7-2-ahmadexp@gmail.com \
--to=ahmadexp@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=rmk+kernel@armlinux.org.uk \
--cc=vadim.fedorenko@linux.dev \
--cc=vladimir.oltean@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox