clinux-kernellinux-device-driverembedded-linuxusb-hid

Can not compile usbmouse.c : too few arguments to function 'usb_maxpacket'


I am trying to modify and compile usbmouse.c

While compiling it is saying that the function usb_maxpackets requires 3 arguments but the code I copied from the torvald git is passing only 2 arguments to this function

the code can be found here:

https://github.com/torvalds/linux/blob/master/drivers/hid/usbhid/usbmouse.c

I am using debian gnu/linux 10with kernel version 4.19.94-ti-r42


Solution

  • The number of parameters of the usb_maxpacket() function was changed from 3 to 2 in Linux kernel 5.19 onwards. The third parameter indicated the direction of the pipe, but that information was redundant because the direction can be derived from the other two parameters.

    For compatibility with the 4.19 kernel, the new function call maxp = usb_maxpacket(dev, pipe); needs to be changed to maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));. (usb_pipeout(pipe) is the pipe direction.)

    To make the code compatible with old and new kernels, the code can be conditionally compiled according to the kernel version:

    #include <linux/version.h>
    
        /* In the function */
    #if LINUX_VERSION_CODE < KERNEL_VERSION(5,19,0)
        maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
    #else
        maxp = usb_maxpacket(dev, pipe);
    #endif
    

    Alternatively, some compatibility code could be added before the function that calls usb_maxpacket:

    #include <linux/version.h>
    #include <linux/usb.h>
    
    #if LINUX_VERSION_CODE < KERNEL_VERSION(5,19,0)
    #undef usb_maxpacket
    static inline u16 kcompat_usb_maxpacket(struct usb_device *udev, int pipe)
    {
        return usb_maxpacket(udev, pipe, usb_pipeout(pipe));
    }
    #define usb_maxpacket(udev, pipe) kcompat_usb_maxpacket(udev, pipe)
    #endif
    
        /* In the function */
        maxp = usb_maxpacket(dev, pipe);