Question: What is HID_MAX_USAGES? What is it used for? And why is the value so small?

(codeline:

#define HID_MAX_USAGES                        12288

in

/usr/src/linux/include/linux/hid.h 

Background info: I need to set the value to 32k and rekompile the kernel. Otherwise my gaming-mouse is not recognized by ubuntu. So I want to know what this value is good for, before changing my system.

I think the HID_MAX_USAGES is so "small" cause a HID-device report descriptor in cases where the hid-devices report the right size, the size is way smaller, and in that case it's descriptor won't exceed the hard coded HID_MAX_USAGES limit.

When you get the issue of your keyboard or mice not working, and after a recompile of the kernel with the increased HID_MAX_USES your device start working. Is that most likely because the lower limit would reject parsing the reported descriptor.

After reading and googling some did I inspect some Linux drivers that seemed to override what the device reported itself. Eg. if the device reported it had 2^15 the driver could override it to the maximum allowed by the HID_MAX_USAGES, or with the device usages actually size.

So short summed, basically what happens, the hid-device report descriptor specifies an excessively large number of consumer usages (eg. 2^15 ), which is more than HID_MAX_USAGES. This prevents proper parsing of the reported descriptor and most likely the device or parts of it won't work.

I have been using the dirty hack of increment the HID_MAX_USAGES myself in a production environment. How dirty it is have I asked with no good answers. But with my knowledge I can see that the hack leaves a bigger memory-footprint, I have not looked into if it might be able to slightly hurt performance a bit. I could not see the hack pose any security risk. (Please correct me if I am wrong.)

I believe incrementing the HID_MAX_USAGES in a bug-report is out of the question for any mainline kernel, it is no optimal solution. Rater I would suggest you to submit a detailed bug-report about your hid- keyboard\mice not working. You can also buzz the manufacture of your product to add proper support in a driver.


Extended (source):

On Tue, 21 May 2013, Christian Ohm wrote:

> Is there any reason why HID_MAX_USAGES shouldn't be more than 12288?  

Well, the reasoning is a mixture of current implementation, and 
reasonability.

- we currently have statically allocated arrays on a per-parser basis, for 
  parsing usages and collection indices. If the number of max usages is 
  going to grow in an uncontrolled manner, we'll have to change the way 
  our parser works (which is not impossible, of course).

- most of the ocurences of huge max usages being presented by the devices 
  have actually turned out to be bogus and could have been fixed by 
  patching the report descriptor in order to reflect the real behavior of 
  the device

Thanks,

-- 
Jiri Kosina
SUSE Labs

The above snippet is from the hid subsystem kernel mantainer.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.