PTR_ERR_OR_ZERO(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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