diff options
Diffstat (limited to 'drivers/pps/clients/pps-ldisc.c')
| -rw-r--r-- | drivers/pps/clients/pps-ldisc.c | 73 | 
1 files changed, 41 insertions, 32 deletions
diff --git a/drivers/pps/clients/pps-ldisc.c b/drivers/pps/clients/pps-ldisc.c index 8e1932d29fd..73bd3bb4d93 100644 --- a/drivers/pps/clients/pps-ldisc.c +++ b/drivers/pps/clients/pps-ldisc.c @@ -19,38 +19,37 @@   *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +  #include <linux/module.h>  #include <linux/serial_core.h>  #include <linux/tty.h>  #include <linux/pps_kernel.h> +#include <linux/bug.h>  #define PPS_TTY_MAGIC		0x0001 -static void pps_tty_dcd_change(struct tty_struct *tty, unsigned int status, -				struct timespec *ts) +static void pps_tty_dcd_change(struct tty_struct *tty, unsigned int status)  { -	int id = (long)tty->disc_data; -	struct timespec __ts; -	struct pps_ktime pps_ts; - -	/* First of all we get the time stamp... */ -	getnstimeofday(&__ts); - -	/* Does caller give us a timestamp? */ -	if (ts) {	/* Yes. Let's use it! */ -		pps_ts.sec = ts->tv_sec; -		pps_ts.nsec = ts->tv_nsec; -	} else {	/* No. Do it ourself! */ -		pps_ts.sec = __ts.tv_sec; -		pps_ts.nsec = __ts.tv_nsec; -	} +	struct pps_device *pps; +	struct pps_event_time ts; + +	pps_get_ts(&ts); + +	pps = pps_lookup_dev(tty); +	/* +	 * This should never fail, but the ldisc locking is very +	 * convoluted, so don't crash just in case. +	 */ +	if (WARN_ON_ONCE(pps == NULL)) +		return;  	/* Now do the PPS event report */ -	pps_event(id, &pps_ts, status ? PPS_CAPTUREASSERT : PPS_CAPTURECLEAR, -			NULL); +	pps_event(pps, &ts, status ? PPS_CAPTUREASSERT : +			PPS_CAPTURECLEAR, NULL); -	pr_debug("PPS %s at %lu on source #%d\n", -			status ? "assert" : "clear", jiffies, id); +	dev_dbg(pps->dev, "PPS %s at %lu\n", +			status ? "assert" : "clear", jiffies);  }  static int (*alias_n_tty_open)(struct tty_struct *tty); @@ -60,6 +59,7 @@ static int pps_tty_open(struct tty_struct *tty)  	struct pps_source_info info;  	struct tty_driver *drv = tty->driver;  	int index = tty->index + drv->name_base; +	struct pps_device *pps;  	int ret;  	info.owner = THIS_MODULE; @@ -70,34 +70,43 @@ static int pps_tty_open(struct tty_struct *tty)  			PPS_OFFSETASSERT | PPS_OFFSETCLEAR | \  			PPS_CANWAIT | PPS_TSFMT_TSPEC; -	ret = pps_register_source(&info, PPS_CAPTUREBOTH | \ +	pps = pps_register_source(&info, PPS_CAPTUREBOTH | \  				PPS_OFFSETASSERT | PPS_OFFSETCLEAR); -	if (ret < 0) { +	if (pps == NULL) {  		pr_err("cannot register PPS source \"%s\"\n", info.path); -		return ret; +		return -ENOMEM;  	} -	tty->disc_data = (void *)(long)ret; +	pps->lookup_cookie = tty; -	/* Should open N_TTY ldisc too */ +	/* Now open the base class N_TTY ldisc */  	ret = alias_n_tty_open(tty); -	if (ret < 0) -		pps_unregister_source((long)tty->disc_data); +	if (ret < 0) { +		pr_err("cannot open tty ldisc \"%s\"\n", info.path); +		goto err_unregister; +	} -	pr_info("PPS source #%d \"%s\" added\n", ret, info.path); +	dev_info(pps->dev, "source \"%s\" added\n", info.path);  	return 0; + +err_unregister: +	pps_unregister_source(pps); +	return ret;  }  static void (*alias_n_tty_close)(struct tty_struct *tty);  static void pps_tty_close(struct tty_struct *tty)  { -	int id = (long)tty->disc_data; +	struct pps_device *pps = pps_lookup_dev(tty); -	pps_unregister_source(id);  	alias_n_tty_close(tty); -	pr_info("PPS source #%d removed\n", id); +	if (WARN_ON(!pps)) +		return; + +	dev_info(pps->dev, "removed\n"); +	pps_unregister_source(pps);  }  static struct tty_ldisc_ops pps_ldisc_ops;  | 
