LCOV - code coverage report
Current view: top level - lib - iovec.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 18 20 90.0 %
Date: 2014-02-18 Functions: 2 2 100.0 %
Branches: 9 11 81.8 %

           Branch data     Line data    Source code
       1                 :            : #include <linux/uaccess.h>
       2                 :            : #include <linux/export.h>
       3                 :            : #include <linux/uio.h>
       4                 :            : 
       5                 :            : /*
       6                 :            :  *      Copy iovec to kernel. Returns -EFAULT on error.
       7                 :            :  *
       8                 :            :  *      Note: this modifies the original iovec.
       9                 :            :  */
      10                 :            : 
      11                 :          0 : int memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len)
      12                 :            : {
      13         [ +  + ]:       7862 :         while (len > 0) {
      14         [ +  - ]:       4043 :                 if (iov->iov_len) {
      15                 :       4043 :                         int copy = min_t(unsigned int, len, iov->iov_len);
      16         [ +  - ]:       4043 :                         if (copy_from_user(kdata, iov->iov_base, copy))
      17                 :            :                                 return -EFAULT;
      18                 :       4043 :                         len -= copy;
      19                 :       4043 :                         kdata += copy;
      20                 :       4043 :                         iov->iov_base += copy;
      21                 :       4043 :                         iov->iov_len -= copy;
      22                 :            :                 }
      23                 :       4043 :                 iov++;
      24                 :            :         }
      25                 :            : 
      26                 :            :         return 0;
      27                 :            : }
      28                 :            : EXPORT_SYMBOL(memcpy_fromiovec);
      29                 :            : 
      30                 :            : /*
      31                 :            :  *      Copy kernel to iovec. Returns -EFAULT on error.
      32                 :            :  *
      33                 :            :  *      Note: this modifies the original iovec.
      34                 :            :  */
      35                 :            : 
      36                 :          0 : int memcpy_toiovec(struct iovec *iov, unsigned char *kdata, int len)
      37                 :            : {
      38         [ +  + ]:    1675718 :         while (len > 0) {
      39            [ + ]:     838933 :                 if (iov->iov_len) {
      40                 :     838960 :                         int copy = min_t(unsigned int, iov->iov_len, len);
      41         [ +  + ]:     836815 :                         if (copy_to_user(iov->iov_base, kdata, copy))
      42                 :            :                                 return -EFAULT;
      43                 :     836812 :                         kdata += copy;
      44                 :     836812 :                         len -= copy;
      45                 :     836812 :                         iov->iov_len -= copy;
      46                 :     836812 :                         iov->iov_base += copy;
      47                 :            :                 }
      48                 :     836785 :                 iov++;
      49                 :            :         }
      50                 :            : 
      51                 :            :         return 0;
      52                 :            : }
      53                 :            : EXPORT_SYMBOL(memcpy_toiovec);

Generated by: LCOV version 1.9