---
name: "idr_alloc"
section: "9"
platform: "linux"
package: "linux-manual-4.9"
version: "4.9.228-1"
release: "Debian 9 (Stretch)"
platforms: ["linux"]
url: "https://new.carta.tech/idr_alloc"
---

# idr\_alloc(9)

allocate new idr entry

## NAME

idr\_alloc - allocate new idr entry

## SYNOPSIS

**int idr\_alloc(struct idr \*** *idr***, void \*** *ptr***, int** *start***, int** *end***, gfp\_t** *gfp\_mask***);**

## ARGUMENTS

*idr*

the (initialized) idr

*ptr*

pointer to be associated with the new id

*start*

the minimum id (inclusive)

*end*

the maximum id (exclusive, \<= 0 for max)

*gfp\_mask*

memory allocation flags

## DESCRIPTION

Allocate an id in \[start, end) and associate it with *ptr*. If no ID is available in the specified range, returns -ENOSPC. On memory allocation failure, returns -ENOMEM.

Note that *end* is treated as max when \<= 0. This is to always allow using *start* + N as *end* as long as N is inside integer range.

The user is responsible for exclusively synchronizing all operations which may modify *idr*. However, read-only accesses such as **idr\_find** or iteration can be performed under RCU read lock provided the user destroys *ptr* in RCU-safe way after removal from idr.

## COPYRIGHT
