pps: simplify conditions a bit
[firefly-linux-kernel-4.4.55.git] / drivers / pps / kapi.c
index e8847c118ea38d5fd0631ea1636e8c2d12fc204e..ebf33746c37ca4f0c4b35082df0479184e49c39c 100644 (file)
 #include <linux/sched.h>
 #include <linux/time.h>
 #include <linux/spinlock.h>
-#include <linux/idr.h>
 #include <linux/fs.h>
 #include <linux/pps_kernel.h>
 #include <linux/slab.h>
 
-/*
- * Local variables
- */
-
-static DEFINE_SPINLOCK(pps_idr_lock);
-static DEFINE_IDR(pps_idr);
-
 /*
  * Local functions
  */
@@ -76,7 +68,6 @@ struct pps_device *pps_register_source(struct pps_source_info *info,
                int default_params)
 {
        struct pps_device *pps;
-       int id;
        int err;
 
        /* Sanity checks */
@@ -117,54 +108,18 @@ struct pps_device *pps_register_source(struct pps_source_info *info,
        init_waitqueue_head(&pps->queue);
        spin_lock_init(&pps->lock);
 
-       /* Get new ID for the new PPS source */
-       if (idr_pre_get(&pps_idr, GFP_KERNEL) == 0) {
-               err = -ENOMEM;
-               goto kfree_pps;
-       }
-
-       spin_lock_irq(&pps_idr_lock);
-
-       /* Now really allocate the PPS source.
-        * After idr_get_new() calling the new source will be freely available
-        * into the kernel.
-        */
-       err = idr_get_new(&pps_idr, pps, &id);
-       if (err < 0) {
-               spin_unlock_irq(&pps_idr_lock);
-               goto kfree_pps;
-       }
-
-       id = id & MAX_ID_MASK;
-       if (id >= PPS_MAX_SOURCES) {
-               spin_unlock_irq(&pps_idr_lock);
-
-               pr_err("%s: too many PPS sources in the system\n",
-                                       info->name);
-               err = -EBUSY;
-               goto free_idr;
-       }
-       pps->id = id;
-
-       spin_unlock_irq(&pps_idr_lock);
-
        /* Create the char device */
        err = pps_register_cdev(pps);
        if (err < 0) {
                pr_err("%s: unable to create char device\n",
                                        info->name);
-               goto free_idr;
+               goto kfree_pps;
        }
 
        dev_info(pps->dev, "new PPS source %s\n", info->name);
 
        return pps;
 
-free_idr:
-       spin_lock_irq(&pps_idr_lock);
-       idr_remove(&pps_idr, id);
-       spin_unlock_irq(&pps_idr_lock);
-
 kfree_pps:
        kfree(pps);
 
@@ -184,15 +139,10 @@ EXPORT_SYMBOL(pps_register_source);
 
 void pps_unregister_source(struct pps_device *pps)
 {
-       unsigned int id = pps->id;
-
        pps_unregister_cdev(pps);
 
-       spin_lock_irq(&pps_idr_lock);
-       idr_remove(&pps_idr, pps->id);
-       spin_unlock_irq(&pps_idr_lock);
-
-       kfree(pps);
+       /* don't have to kfree(pps) here because it will be done on
+        * device destruction */
 }
 EXPORT_SYMBOL(pps_unregister_source);
 
@@ -216,10 +166,8 @@ void pps_event(struct pps_device *pps, struct pps_event_time *ts, int event,
        int captured = 0;
        struct pps_ktime ts_real;
 
-       if ((event & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR)) == 0) {
-               dev_err(pps->dev, "unknown event (%x)\n", event);
-               return;
-       }
+       /* check event type */
+       BUG_ON((event & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR)) == 0);
 
        dev_dbg(pps->dev, "PPS event at %ld.%09ld\n",
                        ts->ts_real.tv_sec, ts->ts_real.tv_nsec);
@@ -234,8 +182,7 @@ void pps_event(struct pps_device *pps, struct pps_event_time *ts, int event,
 
        /* Check the event */
        pps->current_mode = pps->params.mode;
-       if ((event & PPS_CAPTUREASSERT) &
-                       (pps->params.mode & PPS_CAPTUREASSERT)) {
+       if (event & pps->params.mode & PPS_CAPTUREASSERT) {
                /* We have to add an offset? */
                if (pps->params.mode & PPS_OFFSETASSERT)
                        pps_add_offset(&ts_real,
@@ -249,8 +196,7 @@ void pps_event(struct pps_device *pps, struct pps_event_time *ts, int event,
 
                captured = ~0;
        }
-       if ((event & PPS_CAPTURECLEAR) &
-                       (pps->params.mode & PPS_CAPTURECLEAR)) {
+       if (event & pps->params.mode & PPS_CAPTURECLEAR) {
                /* We have to add an offset? */
                if (pps->params.mode & PPS_OFFSETCLEAR)
                        pps_add_offset(&ts_real,