c - valgrind error in ioctl() call, while sending an i2c message -
valgrind giving me following error on ioctl() line: not sure how avert such error.
==2764== error summary: 1 errors 1 contexts (suppressed: 0 0)
==2764==
==2764== 1 errors in context 1 of 1:
==2764== syscall param ioctl(i2c_rdwr).msgs points uninitialised byte(s)
==2764== @ 0x4e08efec: ioctl (syscall-template.s:81)
==2764== 0x871f: imxsend_i2cmsg (imx6qi2c_wrapper.c:54)
==2764== 0x87cb: imxsend_i2cbyte (imx6qi2c_wrapper.c:84)
==2764== 0x86d3: main (imx6qi2c_test.c:30)
==2764== address 0x7db99b82 on thread 1's stack
==2764== uninitialised value created stack allocation
==2764== @ 0x875c: imxsend_i2cbyte (imx6qi2c_wrapper.c:66)
the code in imx6qi2c_wrapper.c following:
int imxsend_i2cmsg(const int i2c_fd, struct i2c_msg *i2cmsgarray, const unsigned int arraysize){ int ret=0; struct i2c_rdwr_ioctl_data ioctl_pack; ioctl_pack.nmsgs=arraysize; ioctl_pack.msgs=i2cmsgarray; ret=ioctl(i2c_fd,i2c_rdwr,&ioctl_pack); return ret; }
and "i2cmsgarray" declared in annother function locally.
int imxsend_i2cbyte(const int i2c_fd, const unsigned char i2caddress, const unsigned char devregister, const unsigned char value){ struct i2c_msg i2cmsg[i2cmsgs_total_wr]; int ret=0,i=0; (i=0;i<i2cmsgs_total_wr;i++){ i2cmsg[i].buf=malloc(2*sizeof(char)); } i2cmsg[0].addr=i2caddress; i2cmsg[0].flags=i2c_m_wr; i2cmsg[0].len=2; i2cmsg[0].buf[0]=devregister; i2cmsg[0].buf[1]=value; ret=imxsend_i2cmsg(i2c_fd,&i2cmsg[0],i2cmsgs_total_wr); if (ret<0){ printf("i2cmsg failed.errno %d, %s\n",errno,strerror(errno)); } (i=0;i<i2cmsgs_total_wr;i++){ free(i2cmsg[i].buf); } return ret; }
where uninitialized byte?
ok completion copy here answer given comment (but never posted answer user knew answer).
memset 0 on i2cmsg solve problem
Comments
Post a Comment