On Tue, Jan 27, 2026 at 07:00:39AM +0100, Christoph Hellwig wrote:
> > -   if (PTR_ERR(folio) == -ENOENT ||
> > -       !(IS_ERR(folio) && !folio_test_uptodate(folio))) {
> > +   if (folio == ERR_PTR(-ENOENT) ||
> > +       (!IS_ERR(folio) && !folio_test_uptodate(folio))) {
> > 
> > (Note that PTR_ERR() shouldn't be used before it's known that the
> > pointer is an error pointer.)
> 
> That's new to me, and I can't find anything in the documentation or
> implementation suggesting that.  Your example code above also does
> this as does plenty of code in the kernel elsewhere.

Not sure why this is controversial.  The documentation for PTR_ERR() is
clear that it's for error pointers:

/**
 * PTR_ERR - Extract the error code from an error pointer.
 * @ptr: An error pointer.
 * Return: The error code within @ptr.
 */
static inline long __must_check PTR_ERR(__force const void *ptr)
{
        return (long) ptr;
}

Yes, it's really just a cast, and 'PTR_ERR(folio) == -ENOENT' actually
still works when folio isn't necessarily an error pointer.  But normally
it would be written as a pointer comparison as I suggested.

- Eric


_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to