]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/open.c
Merge branch 'master' into can-usb1
[lincan.git] / lincan / src / open.c
index 942225a8fbaa4c726340e98a5fc6753d6b311a59..266aed414743109592a41cfade17c54f15332bd4 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
+       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);
-       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);