All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Dave Chinner <david@fromorbit.com>
Cc: "Darrick J . Wong" <djwong@kernel.org>, linux-xfs@vger.kernel.org
Subject: Re: [PATCH] xfs: Add const qualifiers
Date: Wed, 14 Dec 2022 16:54:02 +0000	[thread overview]
Message-ID: <Y5n/qtvzXJrND6ZN@casper.infradead.org> (raw)
In-Reply-To: <20221214005237.GA3600936@dread.disaster.area>

On Wed, Dec 14, 2022 at 11:52:37AM +1100, Dave Chinner wrote:
> On Tue, Dec 13, 2022 at 08:54:45PM +0000, Matthew Wilcox (Oracle) wrote:
> > With a container_of() that preserves const, the compiler warns about
> > all these places which are currently casting away the const.  For
> > the IUL_ITEM() helper, we want to also make it const-preserving,
> > and in every other case, we want to just add a const qualifier.
> 
> ....
> 
> > diff --git a/fs/xfs/xfs_iunlink_item.c b/fs/xfs/xfs_iunlink_item.c
> > index 43005ce8bd48..ff82a93f8a24 100644
> > --- a/fs/xfs/xfs_iunlink_item.c
> > +++ b/fs/xfs/xfs_iunlink_item.c
> > @@ -20,10 +20,7 @@
> >  
> >  struct kmem_cache	*xfs_iunlink_cache;
> >  
> > -static inline struct xfs_iunlink_item *IUL_ITEM(struct xfs_log_item *lip)
> > -{
> > -	return container_of(lip, struct xfs_iunlink_item, item);
> > -}
> > +#define IUL_ITEM(lip) container_of(lip, struct xfs_iunlink_item, item)
> 
> I think this is somewhat of a step backwards. We moved these log
> item type conversions from macros to static inlines to add type
> checking so the compiler would catch the type conversion bugs we
> found that the macros didn't warn about....

But container_of() does warn about bad types.  It doesn't check that
'lip' is an xfs_log_item pointer, of course, but it does check that
either lip has the same type as the member 'item' in
struct xfs_iunlink_item, or lip is a void pointer, which is the
same check that the compiler is going to do with a static inline
function.

> Which makes me ask: why do we even care about const here? What
> actual real world problem are you trying to fix with these changes?

Why do we care about const anywhere?  container_of() is an unintended
way to drop the constness of a pointer, so it's a code hygeine issue.

      reply	other threads:[~2022-12-14 16:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-13 20:54 [PATCH] xfs: Add const qualifiers Matthew Wilcox (Oracle)
2022-12-14  0:52 ` Dave Chinner
2022-12-14 16:54   ` Matthew Wilcox [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y5n/qtvzXJrND6ZN@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=david@fromorbit.com \
    --cc=djwong@kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.