[LinuxPPS] safe pps_register_source()
Rodolfo Giometti
giometti at enneenne.com
Thu Aug 9 14:24:23 CEST 2007
Hello,
looking at your patch for old LinuxPPS 4.x series I suppose I need to
apply this patch to the new 5.x series...
Please, let me know what do you think about it.
Thanks,
Rodolfo
---
diff --git a/drivers/pps/kapi.c b/drivers/pps/kapi.c
index ccfa123..46ee3ef 100644
--- a/drivers/pps/kapi.c
+++ b/drivers/pps/kapi.c
@@ -119,6 +119,7 @@ int pps_register_source(struct pps_source_info *info, int default_params)
pps->info = *info;
init_waitqueue_head(&pps->queue);
+ init_completion(&pps->event_done);
spin_lock_init(&pps->lock);
/* Create the char device */
@@ -178,6 +179,8 @@ void pps_unregister_source(int source)
idr_remove(&pps_idr, pps->id);
spin_unlock_irq(&idr_lock);
+ wait_for_completion(&pps->event_done);
+
pps_sysfs_remove_source_entry(pps);
pps_unregister_cdev(pps);
kfree(pps);
@@ -251,5 +254,10 @@ void pps_event(int source, int event, void *data)
kill_fasync(&pps->async_queue, SIGIO, POLL_IN);
spin_unlock_irqrestore(&pps->lock, flags);
+
+ /* This should be done as the very last command since after it the
+ * PPS source may be removed safely.
+ */
+ complete(&pps->event_done);
}
EXPORT_SYMBOL(pps_event);
diff --git a/include/linux/pps.h b/include/linux/pps.h
index a513da9..0d66b83 100644
--- a/include/linux/pps.h
+++ b/include/linux/pps.h
@@ -169,6 +169,7 @@ struct pps_device {
struct device *dev;
int devno;
struct fasync_struct *async_queue; /* fasync method */
+ struct completion event_done; /* pps_event() has finished */
spinlock_t lock;
struct class_device class_dev;
--
GNU/Linux Solutions e-mail: giometti at enneenne.com
Linux Device Driver giometti at gnudd.com
Embedded Systems giometti at linux.it
UNIX programming phone: +39 349 2432127
More information about the LinuxPPS
mailing list