PTR_ERR_OR_ZERO(9)
π PTR_ERR_OR_ZERO
okay bestie, welcome to PTR_ERR_OR_ZERO(9) from the Kernel API Manual β¨ this one is short, sweet, and honestly kind of iconic β it's a tiny helper that saves you from writing the same boring if block over and over.
πΈ NAME πΈ
PTR_ERR_OR_ZERO β Extract the error code from a pointer if it has one. π
β¨ SYNOPSIS β¨
int PTR_ERR_OR_ZERO (__force const void *ptr );
π«Ά ARGUMENTS π«Ά
ptrβ A potential error pointer. literally just a pointer that might be hiding an error code in it π
π DESCRIPTION π
So this is a convenience function, right? It's the one you call inside a function that returns an error code, when you want to propagate errors you received as error pointers. no extra steps, no drama π
Like, instead of writing this whole thing:
if (IS_ERR(ptr))
return PTR_ERR(ptr);
else
return 0;
you just go:
``return PTR_ERR_OR_ZERO(ptr);``
and that's it. it replaces the whole block above. slay β¨
β RETURN β
The error code within ptr if it is an error pointer; 0 otherwise. so either you get the error code or you get a nice little zero, no in-between, no cap π
π¦ SEE ALSO π¦
Kernel file ./include/linux/err.h β and its whole friend group: IS_ERR_VALUE(9), ERR_PTR(9), INIT_ERR_PTR(9), PTR_ERR(9), IS_ERR(9), IS_ERR_OR_NULL(9), ERR_CAST(9) π
that's the whole page bestie, it's giving "small function, big main character energy" π huge thanks to ./include/linux, dated October 2026 β catch you in the next manpage, mwah ππ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms