1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>idr_alloc</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="The Linux Kernel API"><link rel="up" href="idr.html" title="idr/ida Functions"><link rel="prev" href="API-idr-preload.html" title="idr_preload"><link rel="next" href="API-idr-alloc-cyclic.html" title="idr_alloc_cyclic"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"><span class="phrase">idr_alloc</span></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="API-idr-preload.html">Prev</a> </td><th width="60%" align="center">idr/ida Functions</th><td width="20%" align="right"> <a accesskey="n" href="API-idr-alloc-cyclic.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="API-idr-alloc"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>idr_alloc — 2 allocate new idr entry 3 </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">idr_alloc </b>(</code></td><td>struct idr * <var class="pdparam">idr</var>, </td></tr><tr><td> </td><td>void * <var class="pdparam">ptr</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">start</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">end</var>, </td></tr><tr><td> </td><td>gfp_t <var class="pdparam">gfp_mask</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idp1123580116"></a><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>idr</code></em></span></dt><dd><p> 4 the (initialized) idr 5 </p></dd><dt><span class="term"><em class="parameter"><code>ptr</code></em></span></dt><dd><p> 6 pointer to be associated with the new id 7 </p></dd><dt><span class="term"><em class="parameter"><code>start</code></em></span></dt><dd><p> 8 the minimum id (inclusive) 9 </p></dd><dt><span class="term"><em class="parameter"><code>end</code></em></span></dt><dd><p> 10 the maximum id (exclusive, <= 0 for max) 11 </p></dd><dt><span class="term"><em class="parameter"><code>gfp_mask</code></em></span></dt><dd><p> 12 memory allocation flags 13 </p></dd></dl></div></div><div class="refsect1"><a name="idp1123585844"></a><h2>Description</h2><p> 14 Allocate an id in [start, end) and associate it with <em class="parameter"><code>ptr</code></em>. If no ID is 15 available in the specified range, returns -ENOSPC. On memory allocation 16 failure, returns -ENOMEM. 17 </p><p> 18 19 Note that <em class="parameter"><code>end</code></em> is treated as max when <= 0. This is to always allow 20 using <em class="parameter"><code>start</code></em> + N as <em class="parameter"><code>end</code></em> as long as N is inside integer range. 21 </p><p> 22 23 The user is responsible for exclusively synchronizing all operations 24 which may modify <em class="parameter"><code>idr</code></em>. However, read-only accesses such as <code class="function">idr_find</code> 25 or iteration can be performed under RCU read lock provided the user 26 destroys <em class="parameter"><code>ptr</code></em> in RCU-safe way after removal from idr. 27</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="API-idr-preload.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="idr.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="API-idr-alloc-cyclic.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="phrase">idr_preload</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <span class="phrase">idr_alloc_cyclic</span></td></tr></table></div></body></html> 28