Re: [PATCH] netfs: Use container_of() for offset casting

From: Kees Cook
Date: Wed May 18 2022 - 16:21:15 EST


On Wed, May 18, 2022 at 09:05:14AM +0100, David Howells wrote:
> [...]
> I don't want to do the following, say:
>
>
> struct afs_vnode {
> struct netfs_i_c_pair ni;
> ...
> };
>
> as that would then require a lot of s/->vfs_inode/->ni.vfs_inode/, but maybe
> it would be better to include a struct inode in struct netfs_i_context, and

Right; that's why I kept the struct internal -- the implicit ordering of
inode and netfs_i_context is already present in all the users.

> On the other hand:
>
> warthog>git grep '[>.]vfs_inode' -- fs/{9p,afs,ceph,cifs,nfs} | wc -l
> 181

That seems painful. Maybe _new_ users of netfs could be written to use
the proposed netfs_inode:

> so maybe a mass change to, say:
>
> struct netfs_inode {
> struct inode vfs_inode;
> ...
> };

Better yet, netfs can define a macro helper. I'll send a v2...

--
Kees Cook