Don't you need a kref_get_unless_zero here since we only destroy the idr entry after the refcount dropped to zero? Or is there some magic thing that prevents this like another mutex (in which case some mutex assert in get/put would be good)?
This does all happen under mode_config.mutex but I think I'd rather use get_unless_zero.
And kerneldoc for the non-exported functions please, preferrably with some overview DOC: section to pull it all together.
I'm posting v2, advice on kerneldoc required, so the functions end up in the right place, I don't really wnat to add a new C file for this.
Dave.