Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is idr_alloc()

In the source code implementation it says idr_alloc() is used to allocate new idr entry. I couldn't find the man page and want to know why it is used especially when writing drivers for MTD devices.

like image 463
manav m-n Avatar asked Apr 02 '13 08:04

manav m-n


1 Answers

The idr library is used in the kernel to manage assigning integer IDs to objects and looking up objects by id. See this LWN net article for a full introduction; the basic idea is that you have the following operations:

  • idr_get_new(struct idr *idp, void *ptr, int *id) -- assign a new ID for the pointer ptr and return it via id

  • void *idr_find(struct idr *idp, int id) -- return the pointer corresponding to id

  • void idr_remove(struct idr *idp, int id) -- clear the entry for id

This is useful anywhere a small integer ID that maps to a kernel object is useful -- eg minor numbers or other indexes that are returned to userspace.

like image 91
Roland Avatar answered Sep 21 '22 10:09

Roland