Identify true error value for kernel API's like kmalloc() and ioremap()
Valdis.Kletnieks at vt.edu
Valdis.Kletnieks at vt.edu
Mon Feb 23 02:36:10 EST 2015
On Mon, 23 Feb 2015 15:37:52 +0900, manty kuma said:
> If the call fails, the return value is NULL. So, how do I know what caused
> the failure? I have looked at examples in the kernel code. They are
> returning a hard-coded value of -ENOMEM if kmalloc() fails.
Well.. say you call kmalloc() and it fails. Does it *matter* what caused
the failure? What are the chances that there is (a) more than one reason
for it to fail, and (b) the error is recoverable in one case but not in
another?
Similarly for ioremap() - under what conditions will the *reason* make a
difference?
Unless you plan to take different action and manage to recover based on
the reason, *it doesn't matter*. And given the semantics of kmalloc()
and ioremap() specifically, if your code's action will differ based on
the reason, you're probably using the wrong API.....
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 848 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150223/f82b16fb/attachment.bin
More information about the Kernelnewbies
mailing list