[PATCH v2 4/4] pps: generators: wake up PPS_GEN_FETCHEVENT readers on unregister
From: Danish Khateeb
Date: Tue Sep 29 2026 - 08:58:13 EST
A reader sleeping in PPS_GEN_FETCHEVENT waits for the next event, but
no event comes after pps_gen_unregister_source(), so the reader sleeps
until it gets a signal. A PPS_GEN_FETCHEVENT issued after the
unregister sleeps the same way.
Wake up the readers on unregister, and make PPS_GEN_FETCHEVENT fail
with -ENODEV once the generator is gone, like the other ioctls. The
wait checks info without info_lock, so clear it with WRITE_ONCE().
Fixes: 86b525bed275 ("drivers pps: add PPS generators support")
Suggested-by: Rodolfo Giometti <giometti@xxxxxxxxxxxx>
Assisted-by: LLM
Signed-off-by: Danish Khateeb <danishkhateeb03@xxxxxxxxx>
---
Notes:
Tested in the same setup. With a reader asleep in PPS_GEN_FETCHEVENT,
unbinding the test driver used to leave it asleep until its alarm(5)
fired (-EINTR after 5 s), and a PPS_GEN_FETCHEVENT after the unbind
did the same. With this patch both return -ENODEV right away. Normal
use of pps_gen-dummy, including PPS_GEN_FETCHEVENT, is unchanged.
drivers/pps/generators/pps_gen.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/pps/generators/pps_gen.c b/drivers/pps/generators/pps_gen.c
index 452cc12a96f2..474e17c36458 100644
--- a/drivers/pps/generators/pps_gen.c
+++ b/drivers/pps/generators/pps_gen.c
@@ -103,11 +103,14 @@ static long pps_gen_cdev_ioctl(struct file *file,
dev_dbg(&pps_gen->dev, "PPS_GEN_FETCHEVENT\n");
ret = wait_event_interruptible(pps_gen->queue,
- ev != pps_gen->last_ev);
+ ev != pps_gen->last_ev ||
+ !READ_ONCE(pps_gen->info));
if (ret == -ERESTARTSYS) {
dev_dbg(&pps_gen->dev, "pending signal caught\n");
return -EINTR;
}
+ if (!READ_ONCE(pps_gen->info))
+ return -ENODEV;
spin_lock_irq(&pps_gen->lock);
info.sequence = pps_gen->sequence;
@@ -238,9 +241,12 @@ static void pps_gen_unregister_cdev(struct pps_gen_device *pps_gen)
pps_gen->info->enable(pps_gen, false);
pps_gen->enabled = false;
}
- pps_gen->info = NULL;
+ WRITE_ONCE(pps_gen->info, NULL);
}
+ /* Wake up the readers in PPS_GEN_FETCHEVENT, they fail now as well */
+ wake_up_interruptible_all(&pps_gen->queue);
+
put_device(&pps_gen->dev);
}
--
2.55.0