The "Invalid Address" error message comes from the EFAULT error code that occurs when you pass an address to the kernel that is not a valid virtual address in the virtual address space of your process. The address of your tr structure is clearly valid, so the problem must be in one of its members.
According to the definition of struct spi_ioc_transfer , the .tx_buf and .rx_buf must be pointers to user space buffers or null. You set .tx_buf to the integer 254, which is not a valid pointer to user space, so the wrong address is coming from.
I am not familiar with this IOCTL, so I prefer that you need to process the data in binary. One way to do this would be as follows:
struct spi_ioc_transfer tr = { .len = sizeof(msg),
If you need to send it as ASCII instead, you should use a function like snprintf(3) to convert the integer to an ASCII string, and then point the TX buffer to that string and set the length accordingly.
source share