]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/close.c
reference count for device opens added (helps while asynchronous remove
[lincan.git] / lincan / src / close.c
index a69247c6bc14cca1e234c68c0d6cf89601002aa7..157acfaff99033f510929720a14fdfc37e1f4204 100644 (file)
@@ -45,6 +45,7 @@
 int can_close(struct inode *inode, struct file *file)
 {
        struct canuser_t *canuser = (struct canuser_t*)(file->private_data);
+       struct canchip_t *chip;
        struct canque_ends_t *qends;
        struct msgobj_t *obj;
        can_spin_irqflags_t iflags;
@@ -53,6 +54,10 @@ int can_close(struct inode *inode, struct file *file)
                CANMSG("can_close: bad canuser magic\n");
                return -ENODEV;
        }
+       if ((chip=objects_p[MINOR_NR]->hostchip) == NULL) {
+               CANMSG("There is no hardware support for the device file with minor nr.: %d\n",MINOR_NR);
+               return -ENODEV;
+       }
        
        obj = canuser->msgobj;
        qends = canuser->qends;
@@ -80,5 +85,10 @@ int can_close(struct inode *inode, struct file *file)
     #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,50))
        MOD_DEC_USE_COUNT;
     #endif
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10))
+       if (chip->hostdevice->hwspecops->release_device)
+               kref_put(&chip->hostdevice->refcount,chip->hostdevice->hwspecops->release_device);
+#endif
        return 0;
 }