]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/write.c
Added full RT-Linux POSIX interface to LinCAN driver, needs preparation of RT tests.
[lincan.git] / lincan / src / write.c
index 1869c9750940d8ad13b329315bf444d819e5c80c..1760bc2fdba740085e9b4f876414dfe4771010c7 100644 (file)
@@ -20,10 +20,10 @@ ssize_t can_write(struct file *file, const char *buffer, size_t length, loff_t *
        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;
        }
 
@@ -32,7 +32,7 @@ ssize_t can_write(struct file *file, const char *buffer, size_t length, loff_t *
                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;
        }
@@ -85,7 +85,8 @@ ssize_t can_write(struct file *file, const char *buffer, size_t length, loff_t *
        /* 
         * 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 */
@@ -96,7 +97,6 @@ ssize_t can_write(struct file *file, const char *buffer, size_t length, loff_t *
                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) {