Re: [PATCH v2 3/4] cachestat: implement cachestat syscall

From: Matthew Wilcox
Date: Mon Dec 12 2022 - 11:25:06 EST


On Mon, Dec 12, 2022 at 08:23:31AM -0800, Nhat Pham wrote:
> > It would be easier to read if you inverted the condition here.
>
> Oh I think I tried
>
> if (!f.file)
> return -EBADF;
>
> here, but there are some mixing-code-with-decl warnings.
> If I recall correctly, the problem is with this line:
>
> XA_STATE(xas, &mapping->i_pages, first_index);
>
> which is expanded into a declaration:
>
> #define XA_STATE(name, array, index) \
> struct xa_state name = __XA_STATE(array, index, 0, 0)
>
> It requires a valid mapping though, which is
> obtained from f.file:
>
> struct address_space *mapping = f.file->f_mapping;
>
> so it cannot be moved above the if(!f.file) check either...

Perhaps you're trying to do too much in a single function?