1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>try_module_get()/module_put() include/linux/module.h</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Unreliable Guide To Hacking The Linux Kernel"><link rel="up" href="common-routines.html" title="Chapter 6. Common Routines"><link rel="prev" href="routines-moduleexit.html" title="module_exit() include/linux/init.h"><link rel="next" href="queues.html" title="Chapter 7. Wait Queues include/linux/wait.h"></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"> <code class="function">try_module_get()</code>/<code class="function">module_put()</code> 2 <code class="filename">include/linux/module.h</code></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="routines-moduleexit.html">Prev</a> </td><th width="60%" align="center">Chapter 6. Common Routines</th><td width="20%" align="right"> <a accesskey="n" href="queues.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="routines-module-use-counters"></a> <code class="function">try_module_get()</code>/<code class="function">module_put()</code> 3 <code class="filename">include/linux/module.h</code></h2></div></div></div><p> 4 These manipulate the module usage count, to protect against 5 removal (a module also can't be removed if another module uses one 6 of its exported symbols: see below). Before calling into module 7 code, you should call <code class="function">try_module_get()</code> on 8 that module: if it fails, then the module is being removed and you 9 should act as if it wasn't there. Otherwise, you can safely enter 10 the module, and call <code class="function">module_put()</code> when you're 11 finished. 12 </p><p> 13 Most registerable structures have an 14 <em class="structfield"><code>owner</code></em> field, such as in the 15 <span class="structname">file_operations</span> structure. Set this field 16 to the macro <span class="symbol">THIS_MODULE</span>. 17 </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="routines-moduleexit.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="common-routines.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="queues.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"> <code class="function">module_exit()</code> 18 <code class="filename">include/linux/init.h</code>  </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 7. Wait Queues 19 <code class="filename">include/linux/wait.h</code> 20 </td></tr></table></div></body></html> 21