]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/write.c
The use of chip->chip_data is unnecessary, chip->hostdevice points to corresponding...
[lincan.git] / lincan / src / write.c
index e3809b0ebe90e393a1bf5efef9a812d9f831f6a1..4b65a1462f04d5f57e5218eb96566a246a09227c 100644 (file)
@@ -4,12 +4,13 @@
  * Rewritten for new CAN queues by Pavel Pisa - OCERA team member
  * email:pisa@cmp.felk.cvut.cz
  * This software is released under the GPL-License.
- * Version lincan-0.2  9 Jul 2003
+ * Version lincan-0.3  17 Jun 2004
  */
 
 #include "../include/can.h"
 #include "../include/can_sysdep.h"
 #include "../include/main.h"
+#include "../include/write.h"
 
 ssize_t can_write(struct file *file, const char *buffer, size_t length, loff_t *offset)
 {
@@ -19,7 +20,7 @@ ssize_t can_write(struct file *file, const char *buffer, size_t length, loff_t *
        struct canque_ends_t *qends;
        struct canque_edge_t *qedge;
        struct canque_slot_t *slot;
-       int ret = 0;
+       int ret;
        unsigned bytes_to_copy;
 
        if(!canuser || (canuser->magic != CAN_USER_MAGIC)){
@@ -52,7 +53,8 @@ ssize_t can_write(struct file *file, const char *buffer, size_t length, loff_t *
 
 
        /* Prepare first message */
-       copy_from_user(&msg_buff, buffer, sizeof(struct canmsg_t));
+       ret = copy_from_user(&msg_buff, buffer, sizeof(struct canmsg_t));
+       if(ret) return -EFAULT;
 
        /* Automatic selection of extended format if ID>2047 */
        if (msg_buff.id & ~0x7ffl & MSG_ID_MASK ) msg_buff.flags |= MSG_EXT;
@@ -90,7 +92,8 @@ ssize_t can_write(struct file *file, const char *buffer, size_t length, loff_t *
        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));
+               ret = copy_from_user(&msg_buff, buffer, sizeof(struct canmsg_t));
+               if(ret) return -EFAULT;
 
                /* Automatic selection of extended format if ID>2047 */
                if (msg_buff.id & ~0x7ffl & MSG_ID_MASK ) msg_buff.flags |= MSG_EXT;