All of lore.kernel.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: David Laight <David.Laight@aculab.com>,
	Arnd Bergmann <arnd@kernel.org>,
	"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
	Arnd Bergmann <arnd@arndb.de>,
	"llvm@lists.linux.dev" <llvm@lists.linux.dev>,
	Nick Desaulniers <ndesaulniers@google.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Bill Wendling <morbo@google.com>,
	"linux-serial@vger.kernel.org" <linux-serial@vger.kernel.org>,
	Justin Stitt <justinstitt@google.com>,
	Jiri Slaby <jirislaby@kernel.org>
Subject: Re: [PATCH] tty: hvc-iucv: fix function pointer casts
Date: Wed, 14 Feb 2024 06:36:24 -0600	[thread overview]
Message-ID: <20240214123624.GB19790@gate.crashing.org> (raw)
In-Reply-To: <2024021426-unleveled-unhearing-8021@gregkh>

On Wed, Feb 14, 2024 at 11:37:21AM +0100, Greg Kroah-Hartman wrote:
> On Wed, Feb 14, 2024 at 09:46:33AM +0000, David Laight wrote:
> > From: Segher Boessenkool
> > > Sent: 13 February 2024 19:13
> > > 
> > > On Tue, Feb 13, 2024 at 11:17:49AM +0100, Arnd Bergmann wrote:
> > > > clang warns about explicitly casting between incompatible function
> > > > pointers:
> > > >
> > > > drivers/tty/hvc/hvc_iucv.c:1100:23: error: cast from 'void (*)(const void *)' to 'void (*)(struct
> > > device *)' converts to incompatible function type [-Werror,-Wcast-function-type-strict]
> > > >  1100 |         priv->dev->release = (void (*)(struct device *)) kfree;
> > > >       |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > > 
> > > Such a cast of course is explicitly allowed by 6.3.2.3/8, only calling a
> > > function using a non-compatible type is UB.  This warning message is
> > > quite misleading.  Doubly so because of the -Werror, as always.
> > 
> > But it will get called using the wrong type.
> > And (is it) fine-ibt will reject the incorrect call.
> 
> And rightfully so, this type of casting abuse is just that, abuse.
> 
> Almost no one should be just calling kfree() on a device pointer, I'll
> look at the surrounding code as odds are something odd is going on.  But
> for now, this patch is correct.

Yes, and I said so.  My point is that the warning message pretends the
cast is bad or dangerous.  It is not, similar casts are the only way in
C to do certain things (yes, you can always avoid it completely, by
writing completely different code, like the patch does, and that
sometimes is a better idea even).

But the warning message is misleading and does more damage than it helps
avoid.


Segher

WARNING: multiple messages have this Message-ID (diff)
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Arnd Bergmann <arnd@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
	Jiri Slaby <jirislaby@kernel.org>,
	"llvm@lists.linux.dev" <llvm@lists.linux.dev>,
	Nick Desaulniers <ndesaulniers@google.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	David Laight <David.Laight@aculab.com>,
	Bill Wendling <morbo@google.com>,
	"linux-serial@vger.kernel.org" <linux-serial@vger.kernel.org>,
	Justin Stitt <justinstitt@google.com>,
	"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>
Subject: Re: [PATCH] tty: hvc-iucv: fix function pointer casts
Date: Wed, 14 Feb 2024 06:36:24 -0600	[thread overview]
Message-ID: <20240214123624.GB19790@gate.crashing.org> (raw)
In-Reply-To: <2024021426-unleveled-unhearing-8021@gregkh>

On Wed, Feb 14, 2024 at 11:37:21AM +0100, Greg Kroah-Hartman wrote:
> On Wed, Feb 14, 2024 at 09:46:33AM +0000, David Laight wrote:
> > From: Segher Boessenkool
> > > Sent: 13 February 2024 19:13
> > > 
> > > On Tue, Feb 13, 2024 at 11:17:49AM +0100, Arnd Bergmann wrote:
> > > > clang warns about explicitly casting between incompatible function
> > > > pointers:
> > > >
> > > > drivers/tty/hvc/hvc_iucv.c:1100:23: error: cast from 'void (*)(const void *)' to 'void (*)(struct
> > > device *)' converts to incompatible function type [-Werror,-Wcast-function-type-strict]
> > > >  1100 |         priv->dev->release = (void (*)(struct device *)) kfree;
> > > >       |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > > 
> > > Such a cast of course is explicitly allowed by 6.3.2.3/8, only calling a
> > > function using a non-compatible type is UB.  This warning message is
> > > quite misleading.  Doubly so because of the -Werror, as always.
> > 
> > But it will get called using the wrong type.
> > And (is it) fine-ibt will reject the incorrect call.
> 
> And rightfully so, this type of casting abuse is just that, abuse.
> 
> Almost no one should be just calling kfree() on a device pointer, I'll
> look at the surrounding code as odds are something odd is going on.  But
> for now, this patch is correct.

Yes, and I said so.  My point is that the warning message pretends the
cast is bad or dangerous.  It is not, similar casts are the only way in
C to do certain things (yes, you can always avoid it completely, by
writing completely different code, like the patch does, and that
sometimes is a better idea even).

But the warning message is misleading and does more damage than it helps
avoid.


Segher

  reply	other threads:[~2024-02-14 12:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-13 10:17 [PATCH] tty: hvc-iucv: fix function pointer casts Arnd Bergmann
2024-02-13 10:17 ` Arnd Bergmann
2024-02-13 19:12 ` Segher Boessenkool
2024-02-13 19:12   ` Segher Boessenkool
2024-02-14  9:46   ` David Laight
2024-02-14  9:46     ` David Laight
2024-02-14 10:37     ` Greg Kroah-Hartman
2024-02-14 10:37       ` Greg Kroah-Hartman
2024-02-14 12:36       ` Segher Boessenkool [this message]
2024-02-14 12:36         ` Segher Boessenkool
2024-02-14  6:25 ` Jiri Slaby
2024-02-14  6:25   ` Jiri Slaby

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=20240214123624.GB19790@gate.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=David.Laight@aculab.com \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=justinstitt@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    /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.