All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: Stefan Richter <stefanr@s5r6.in-berlin.de>
Cc: Arnd Bergmann <arnd@arndb.de>,
	linux1394-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: [PATCH] [RESEND] firewire: fix function type cast warning
Date: Mon, 27 Sep 2021 16:47:55 +0200	[thread overview]
Message-ID: <20210927144807.2759586-1-arnd@kernel.org> (raw)

From: Arnd Bergmann <arnd@arndb.de>

gcc -Wextra complains about a suspicious cast:

rivers/firewire/core-cdev.c:985:8: warning: cast between incompatible function types from ‘void (*)(struct fw_iso_context *, dma_addr_t,  void *)’ {aka ‘void (*)(struct fw_iso_context *, long long unsigned int,  void *)’} to ‘void (*)(struct fw_iso_context *, u32,  size_t,  void *, void *)’ {aka ‘void (*)(struct fw_iso_context *, unsigned int,  long unsigned int,  void *, void *)’} [-Wcast-function-type]

The behavior is correct in the end, but this is more clearly
expressed using a transparent union.

Fixes: 872e330e3880 ("firewire: add isochronous multichannel reception")
Link: https://lore.kernel.org/lkml/20200530090839.7895-1-oscar.carter@gmx.com/
Link: https://lore.kernel.org/all/20210924105733.GA78013@embeddedor/
Link: https://lore.kernel.org/all/20201026215138.3893732-1-arnd@kernel.org/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
At least three people have submitted a version of this patch, but none
of them has made it into the kernel. I don't care which version gets
picked up, but I think we want it to get fixed.
---
 drivers/firewire/core-cdev.c |  6 +++---
 drivers/firewire/core-iso.c  |  2 +-
 include/linux/firewire.h     | 17 ++++++++---------
 3 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
index fb6c651214f3..8d85d52b02ca 100644
--- a/drivers/firewire/core-cdev.c
+++ b/drivers/firewire/core-cdev.c
@@ -970,7 +970,7 @@ static int ioctl_create_iso_context(struct client *client, union ioctl_arg *arg)
 		if (a->speed > SCODE_3200 || a->channel > 63)
 			return -EINVAL;
 
-		cb = iso_callback;
+		cb.sc = iso_callback;
 		break;
 
 	case FW_ISO_CONTEXT_RECEIVE:
@@ -978,11 +978,11 @@ static int ioctl_create_iso_context(struct client *client, union ioctl_arg *arg)
 		    a->channel > 63)
 			return -EINVAL;
 
-		cb = iso_callback;
+		cb.sc = iso_callback;
 		break;
 
 	case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL:
-		cb = (fw_iso_callback_t)iso_mc_callback;
+		cb.mc = iso_mc_callback;
 		break;
 
 	default:
diff --git a/drivers/firewire/core-iso.c b/drivers/firewire/core-iso.c
index af70e74f9a7e..ddada648775a 100644
--- a/drivers/firewire/core-iso.c
+++ b/drivers/firewire/core-iso.c
@@ -145,7 +145,7 @@ struct fw_iso_context *fw_iso_context_create(struct fw_card *card,
 	ctx->channel = channel;
 	ctx->speed = speed;
 	ctx->header_size = header_size;
-	ctx->callback.sc = callback;
+	ctx->callback = callback;
 	ctx->callback_data = callback_data;
 
 	return ctx;
diff --git a/include/linux/firewire.h b/include/linux/firewire.h
index aec8f30ab200..59b5e02a6d42 100644
--- a/include/linux/firewire.h
+++ b/include/linux/firewire.h
@@ -431,11 +431,13 @@ void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer, struct fw_card *card);
 size_t fw_iso_buffer_lookup(struct fw_iso_buffer *buffer, dma_addr_t completed);
 
 struct fw_iso_context;
-typedef void (*fw_iso_callback_t)(struct fw_iso_context *context,
-				  u32 cycle, size_t header_length,
-				  void *header, void *data);
-typedef void (*fw_iso_mc_callback_t)(struct fw_iso_context *context,
-				     dma_addr_t completed, void *data);
+typedef union {
+	void (*sc)(struct fw_iso_context *context, u32 cycle,
+		   size_t header_length, void *header, void *data);
+	void (*mc)(struct fw_iso_context *context, dma_addr_t completed,
+		   void *data);
+} __attribute__ ((__transparent_union__)) fw_iso_callback_t;
+
 struct fw_iso_context {
 	struct fw_card *card;
 	int type;
@@ -443,10 +445,7 @@ struct fw_iso_context {
 	int speed;
 	bool drop_overflow_headers;
 	size_t header_size;
-	union {
-		fw_iso_callback_t sc;
-		fw_iso_mc_callback_t mc;
-	} callback;
+	fw_iso_callback_t callback;
 	void *callback_data;
 };
 
-- 
2.29.2


                 reply	other threads:[~2021-09-27 14:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210927144807.2759586-1-arnd@kernel.org \
    --to=arnd@kernel.org \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux1394-devel@lists.sourceforge.net \
    --cc=stefanr@s5r6.in-berlin.de \
    /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.