]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/close.c
Use inode argument to obtain minor number even in extended close function.
[lincan.git] / lincan / src / close.c
index 2e0090d83aae8143ef5cd99e5e13b02482112d9f..6a0ca6e0190578fc18b8adf5119a2bd525920ece 100644 (file)
 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;
+       int minor_nr = INODE2MINOR_NR(inode);
 
        if(!canuser || (canuser->magic != CAN_USER_MAGIC)){
                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 +86,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;
 }