X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/blobdiff_plain/fe719367cdb25978d42261513dd9810c22481960..3c47a7cd435662f7e2daa006596722271f5dd090:/lincan/src/open.c?ds=sidebyside diff --git a/lincan/src/open.c b/lincan/src/open.c index f0c3fd2..266aed4 100644 --- a/lincan/src/open.c +++ b/lincan/src/open.c @@ -50,25 +50,31 @@ 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); - if (chip->flags & CHIP_CONFIGURED) + if (chip->flags & CHIP_CONFIGURED) DEBUGMSG("Device is already configured.\n"); else { if (chip->chipspecops->chip_config(chip)) CANMSG("Error configuring chip.\n"); else - chip->flags |= CHIP_CONFIGURED; + chip->flags |= CHIP_CONFIGURED; } /* End of chip configuration */ @@ -99,7 +105,7 @@ int can_open(struct inode *inode, struct file *file) if(qends == NULL) goto no_qends; canqueue_ends_init_kern(qends); canuser->qends = qends; - + /*required to synchronize with RT-Linux context*/ can_spin_lock_irqsave(&canuser_manipulation_lock, iflags); list_add(&canuser->peers, &obj->obj_users); @@ -116,7 +122,7 @@ int can_open(struct inode *inode, struct file *file) #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,50)) MOD_INC_USE_COUNT; -#endif +#endif return 0;