Core structures and functionalities

Logging

#include <log.h>
pr_fmt(fmt)

Defaul module printk format.

ID allocation

#include <idr_l.h>
struct idr_l

IDR structure wrapper with internal concurrency handling.

Public Members

struct idr idr
IDR_L_INIT(idr_l)

Initialise a IDR.

Parameters
  • idr_l – pointer to the IDR

IDR_L_ALLOC(idr_l, ptr, flags)

Allocate a new ID.

Parameters
  • idr_l – pointer to the IDR

  • ptr[in] pointer to be associated with the new ID

  • flags[in] memory allocation flags

Returns

  • the newly allocated ID

  • -ENOMEM - No memory available

  • -ENOSPC - No free IDs could be found

IDR_L_FIND(idr_l, id)

Return pointer for given ID.

Looks up the pointer associated with this ID. A NULL pointer may indicate that id is not allocated or that the NULL pointer was associated with this ID.

This function can be called under rcu_read_lock().

Parameters
  • idr_l – pointer to the IDR

  • id[in] pointer ID

Returns

the pointer associated with this ID

IDR_L_FOR_EACH(idr_l, func, data)

Iterate through all stored pointers.

The callback function will be called for each entry in idr_l, passing the ID, the entry and data.

If func returns anything other than 0, the iteration stops and that value is returned from this function.

IDR_L_FOR_EACH() can be called concurrently with IDR_L_ALLOC() and IDR_L_REMOVE() if protected by RCU. Newly added entries may not be seen and deleted entries may be seen, but adding and removing entries will not cause other entries to be skipped, nor spurious ones to be seen.

Parameters
  • idr_l – pointer to the IDR

  • func[in] function to be called for each pointer

  • data[in] data passed to callback function

IDR_L_REMOVE(idr_l, id)

Remove an ID from the IDR.

Removes this ID from the IDR. If the ID was not previously in the IDR, this function returns NULL.

Parameters
  • idr_l – pointer to the IDR

  • id[in] pointer ID

Returns

the pointer formerly associated with this ID

IDR_L_DESTROY(idr_l)

Release all internal memory from an IDR.

After this function is called, the IDR is empty, and may be reused or the data structure containing it may be freed.

A typical clean-up sequence for objects stored in an idr tree will use IDR_L_FOR_EACH() to free all objects, if necessary, then IDR_L_DESTROY() to free the memory used to keep track of those objects.

Parameters
  • idr_l – pointer to the IDR