struct canque_edge_t *qedge;
struct canque_slot_t *slot;
int ret = 0;
- int bytes_to_copy = 0;
+ unsigned bytes_to_copy;
if(!canuser || (canuser->magic != CAN_USER_MAGIC)){
- CANMSG("can_close: bad canuser magic\n");
+ CANMSG("can_write: bad canuser magic\n");
return -ENODEV;
}
DEBUGMSG("this will always return 0 !\n");
return 0;
}
- if (length > 8 * sizeof(struct canmsg_t)) {
+ if (length > INT_MAX) {
CANMSG("Trying to write more than is supported.\n");
return -1;
}
/*
* Try to send more messages
*/
- while (bytes_to_copy > 0) {
+ while (bytes_to_copy >= sizeof(struct canmsg_t)) {
+ bytes_to_copy -= sizeof(struct canmsg_t);
/* Prepare first message */
copy_from_user(&msg_buff, buffer, sizeof(struct canmsg_t));
/* Automatic selection of extended format if "extended" set and ID>2047 */
slot->msg=msg_buff;
canque_put_inslot(qends, qedge, slot);
buffer += sizeof(struct canmsg_t);
- bytes_to_copy -= sizeof(struct canmsg_t);
}
if(file->f_flags & O_SYNC) {