]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/rtc/rtc-dev.c
Merge git://git.infradead.org/~dwmw2/cafe-2.6
[linux-2.6-omap-h63xx.git] / drivers / rtc / rtc-dev.c
index 07387c99df0dbb73b8eec88e1ece8c576ef49965..583789c66cdb9d2404157f0cda029c9e8dfc7c60 100644 (file)
@@ -24,7 +24,7 @@ static int rtc_dev_open(struct inode *inode, struct file *file)
        int err;
        struct rtc_device *rtc = container_of(inode->i_cdev,
                                        struct rtc_device, char_dev);
-       struct rtc_class_ops *ops = rtc->ops;
+       const struct rtc_class_ops *ops = rtc->ops;
 
        /* We keep the lock as long as the device is in use
         * and return immediately if busy
@@ -209,11 +209,33 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
        int err = 0;
        struct class_device *class_dev = file->private_data;
        struct rtc_device *rtc = to_rtc_device(class_dev);
-       struct rtc_class_ops *ops = rtc->ops;
+       const struct rtc_class_ops *ops = rtc->ops;
        struct rtc_time tm;
        struct rtc_wkalrm alarm;
        void __user *uarg = (void __user *) arg;
 
+       /* check that the calles has appropriate permissions
+        * for certain ioctls. doing this check here is useful
+        * to avoid duplicate code in each driver.
+        */
+       switch (cmd) {
+       case RTC_EPOCH_SET:
+       case RTC_SET_TIME:
+               if (!capable(CAP_SYS_TIME))
+                       return -EACCES;
+               break;
+
+       case RTC_IRQP_SET:
+               if (arg > rtc->max_user_freq && !capable(CAP_SYS_RESOURCE))
+                       return -EACCES;
+               break;
+
+       case RTC_PIE_ON:
+               if (!capable(CAP_SYS_RESOURCE))
+                       return -EACCES;
+               break;
+       }
+
        /* avoid conflicting IRQ users */
        if (cmd == RTC_PIE_ON || cmd == RTC_PIE_OFF || cmd == RTC_IRQP_SET) {
                spin_lock(&rtc->irq_task_lock);
@@ -272,9 +294,6 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
                break;
 
        case RTC_SET_TIME:
-               if (!capable(CAP_SYS_TIME))
-                       return -EACCES;
-
                if (copy_from_user(&tm, uarg, sizeof(tm)))
                        return -EFAULT;
 
@@ -290,10 +309,6 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
                        err = -EINVAL;
                        break;
                }
-               if (!capable(CAP_SYS_TIME)) {
-                       err = -EACCES;
-                       break;
-               }
                rtc_epoch = arg;
                err = 0;
 #endif
@@ -391,7 +406,6 @@ static int rtc_dev_add_device(struct class_device *class_dev,
        rtc->char_dev.owner = rtc->owner;
 
        if (cdev_add(&rtc->char_dev, MKDEV(MAJOR(rtc_devt), rtc->id), 1)) {
-               cdev_del(&rtc->char_dev);
                dev_err(class_dev->dev,
                        "failed to add char device %d:%d\n",
                        MAJOR(rtc_devt), rtc->id);
@@ -481,7 +495,7 @@ static void __exit rtc_dev_exit(void)
        unregister_chrdev_region(rtc_devt, RTC_DEV_MAX);
 }
 
-module_init(rtc_dev_init);
+subsys_initcall(rtc_dev_init);
 module_exit(rtc_dev_exit);
 
 MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");