pps: generators: wake up PPS_GEN_FETCHEVENT readers on unregister

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: 86b525bed2 ("drivers pps: add PPS generators support")
Suggested-by: Rodolfo Giometti <giometti@enneenne.com>
Assisted-by: LLM
Signed-off-by: Danish Khateeb <danishkhateeb03@gmail.com>
Acked-by: Rodolfo Giometti <giometti@enneenne.com>
Link: https://patch.msgid.link/20260929124937.51114-5-danishkhateeb03@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Danish Khateeb 2026-09-29 07:49:37 -05:00 committed by Greg Kroah-Hartman
parent 3e75af9f41
commit 5b864f8db0

View File

@ -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);
}