]> rtime.felk.cvut.cz Git - lincan.git/commitdiff
Use inode open argument to obtain minor number.
authorPavel Pisa <pisa@cmp.felk.cvut.cz>
Sat, 25 Jul 2015 20:49:44 +0000 (22:49 +0200)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Sat, 25 Jul 2015 20:49:44 +0000 (22:49 +0200)
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
lincan/include/can_sysdep.h
lincan/src/open.c

index a2a82180431e8523612f7a240bd639132545389b..165d4a12e1fb37dc3cbb82a61b3e7ce000ca9844 100644 (file)
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,7)) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
 
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,7)) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
 
-#define MINOR_NR \
-       (MINOR(file->f_dentry->d_inode->i_rdev))
+#define INODE2MINOR_NR(inode) \
+       (MINOR(inode->i_rdev))
 
 #else /* Linux kernel < 2.5.7 or >= 2.6.0 */
 
 
 #else /* Linux kernel < 2.5.7 or >= 2.6.0 */
 
-#define MINOR_NR \
-       (minor(file->f_dentry->d_inode->i_rdev))
+#define INODE2MINOR_NR(inode) \
+       (minor(inode->i_rdev))
 
 #endif /* Linux kernel < 2.5.7 or >= 2.6.0 */
 
 
 #endif /* Linux kernel < 2.5.7 or >= 2.6.0 */
 
index f785e2c17efe5212b1680d1b2ababec2512122c9..219aab96787bb618e0febb8cc0578ee321266b1f 100644 (file)
@@ -50,15 +50,21 @@ int can_open(struct inode *inode, struct file *file)
        struct canque_edge_t *edge;
        can_spin_irqflags_t iflags;
        char openflag;          // Martin Petera: Object already opened
        struct canque_edge_t *edge;
        can_spin_irqflags_t iflags;
        char openflag;          // Martin Petera: Object already opened
+       int minor_nr = INODE2MINOR_NR(inode);
 
 
-       if ( ((obj=objects_p[MINOR_NR]) == NULL) ||
-                       ((chip=objects_p[MINOR_NR]->hostchip) == NULL) ) {
-               CANMSG("There is no hardware support for the device file with minor nr.: %d\n",MINOR_NR);
+       if ((minor_nr < 0) || (minor_nr >= MAX_TOT_MSGOBJS)) {
+               CANMSG("can_open: bad minor %d\n", minor_nr);
+               return -ENODEV;
+       }
+
+       if ( ((obj=objects_p[minor_nr]) == NULL) ||
+           ((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;
        }
 
        atomic_inc(&obj->obj_used);
                return -ENODEV;
        }
 
        atomic_inc(&obj->obj_used);
-       DEBUGMSG("Device %d opened %d times.\n", MINOR_NR, atomic_read(&obj->obj_used));
+       DEBUGMSG("Device %d opened %d times.\n", minor_nr, atomic_read(&obj->obj_used));
        openflag = can_msgobj_test_fl(obj,OPENED);      // Martin Petera: store previous status
        can_msgobj_set_fl(obj,OPENED);
 
        openflag = can_msgobj_test_fl(obj,OPENED);      // Martin Petera: store previous status
        can_msgobj_set_fl(obj,OPENED);