1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Return Conventions</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="conventions.html" title="Chapter 10. Routines and Conventions"><link rel="prev" href="conventions.html" title="Chapter 10. Routines and Conventions"><link rel="next" href="conventions-borkedcompile.html" title="Breaking Compilation"></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">Return Conventions</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="conventions.html">Prev</a> </td><th width="60%" align="center">Chapter 10. Routines and Conventions</th><td width="20%" align="right"> <a accesskey="n" href="conventions-borkedcompile.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="convention-returns"></a>Return Conventions</h2></div></div></div><p> 2 For code called in user context, it's very common to defy C 3 convention, and return <span class="returnvalue">0</span> for success, 4 and a negative error number 5 (eg. <span class="returnvalue">-EFAULT</span>) for failure. This can be 6 unintuitive at first, but it's fairly widespread in the kernel. 7 </p><p> 8 Using <code class="function">ERR_PTR()</code> 9 10 <code class="filename">include/linux/err.h</code>; to 11 encode a negative error number into a pointer, and 12 <code class="function">IS_ERR()</code> and <code class="function">PTR_ERR()</code> 13 to get it back out again: avoids a separate pointer parameter for 14 the error number. Icky, but in a good way. 15 </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="conventions.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="conventions.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="conventions-borkedcompile.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 10. Routines and Conventions </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Breaking Compilation</td></tr></table></div></body></html> 16