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);