1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>device_add</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Linux Device Drivers"><link rel="up" href="ch02s02.html" title="Device Drivers Base"><link rel="prev" href="API-dev-set-name.html" title="dev_set_name"><link rel="next" href="API-device-register.html" title="device_register"></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">device_add</span></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="API-dev-set-name.html">Prev</a> </td><th width="60%" align="center">Device Drivers Base</th><td width="20%" align="right"> <a accesskey="n" href="API-device-register.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="API-device-add"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>device_add — 2 add device to device hierarchy. 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">device_add </b>(</code></td><td>struct device * <var class="pdparam">dev</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idp1109309532"></a><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>dev</code></em></span></dt><dd><p> 4 device. 5 </p></dd></dl></div></div><div class="refsect1"><a name="idp1109311116"></a><h2>Description</h2><p> 6 This is part 2 of <code class="function">device_register</code>, though may be called 7 separately _iff_ <code class="function">device_initialize</code> has been called separately. 8 </p><p> 9 10 This adds <em class="parameter"><code>dev</code></em> to the kobject hierarchy via <code class="function">kobject_add</code>, adds it 11 to the global and sibling lists for the device, then 12 adds it to the other relevant subsystems of the driver model. 13 </p><p> 14 15 Do not call this routine or <code class="function">device_register</code> more than once for 16 any device structure. The driver model core is not designed to work 17 with devices that get unregistered and then spring back to life. 18 (Among other things, it's very hard to guarantee that all references 19 to the previous incarnation of <em class="parameter"><code>dev</code></em> have been dropped.) Allocate 20 and register a fresh new struct device instead. 21</p></div><div class="refsect1"><a name="idp1109314748"></a><h2>NOTE</h2><p> 22 _Never_ directly free <em class="parameter"><code>dev</code></em> after calling this function, even 23 if it returned an error! Always use <code class="function">put_device</code> to give up your 24 reference instead. 25</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="API-dev-set-name.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch02s02.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="API-device-register.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="phrase">dev_set_name</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">device_register</span></td></tr></table></div></body></html> 26