tuxedocomputers / tuxedo-keyboard

This repository will no longer get any updates as the code here is now part of tuxedo-drivers https://gitlab.com/tuxedocomputers/development/packages/tuxedo-drivers.
https://gitlab.com/tuxedocomputers/development/packages/tuxedo-drivers
GNU General Public License v3.0
299 stars 93 forks source link

ioctl numbers #123

Closed mbway closed 11 months ago

mbway commented 2 years ago

I'm not that experienced with writing Linux drivers so this could be completely wrong, but I think that the ioctl definitions in tuxedo_io_ioctl.h have incorrect arguments (which results in the ioctl numbers being different from what is expected).

[the third argument of _IOR is] The name of the data type pointed to by the argument

source

So I think that if you want to return an integer from an ioctl then the third argument should be int32_t not int32_t* and if you want to return a string it should be char[SIZE] not char* because the latter does not allow for bounds-checking.

I found an examples of arrays and returning integers in the FAT filesystem driver

#define VFAT_IOCTL_READDIR_SHORT    _IOR('r', 2, struct __fat_dirent[2])
#define FAT_IOCTL_GET_ATTRIBUTES    _IOR('r', 0x10, __u32)

and the SPI driver

#define SPI_IOC_MESSAGE(N) _IOW(SPI_IOC_MAGIC, 0, char[SPI_MSGSIZE(N)])
#define SPI_IOC_RD_MODE    _IOR(SPI_IOC_MAGIC, 1, __u8)

If tuxedo-control-center is the only consumer of the driver then this isn't a major problem because both parties understand what is required but if I'm correct about these arguments then fixing them may be required to upstream the driver.

perhaps the best way to fix the ioctl numbers is to change the definitions in tuxedo_io_ioctl.h but have the driver also respond to R_MOD_VERSION as it is currently defined because conforming users of the driver should be checking that the module is the version that they expect.

tuxedo-bot commented 11 months ago

This repository will no longer get any updates as the code here is now part of tuxedo-drivers https://gitlab.com/tuxedocomputers/development/packages/tuxedo-drivers.

Please open a merge request or issue in the new project on GitLab if you contribution or bug report still applies.