media: mediatek: vcodec: avoid -Wcast-function-type-strict warning

Message ID 20240224121059.1806691-1-arnd@kernel.org
State New
Headers
Series media: mediatek: vcodec: avoid -Wcast-function-type-strict warning |

Commit Message

Arnd Bergmann Feb. 24, 2024, 12:10 p.m. UTC
  From: Arnd Bergmann <arnd@arndb.de>

The ipi handler here tries hard to maintain const-ness of its argument,
but by doing that causes a warning about function type casts:

drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c:38:32: error: cast from 'mtk_vcodec_ipi_handler' (aka 'void (*)(void *, unsigned int, void *)') to 'ipi_handler_t' (aka 'void (*)(const void *, unsigned int, void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
   38 |         ipi_handler_t handler_const = (ipi_handler_t)handler;
      |                                       ^~~~~~~~~~~~~~~~~~~~~~

Remove the hack and just use a non-const argument.

Fixes: bf1d556ad4e0 ("media: mtk-vcodec: abstract firmware interface")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/media/platform/mediatek/mdp/mtk_mdp_vpu.c      |  2 +-
 .../mediatek/vcodec/common/mtk_vcodec_fw_vpu.c         | 10 +---------
 drivers/media/platform/mediatek/vpu/mtk_vpu.c          |  2 +-
 drivers/media/platform/mediatek/vpu/mtk_vpu.h          |  2 +-
 4 files changed, 4 insertions(+), 12 deletions(-)
  

Comments

Ricardo Ribalda Delgado Feb. 27, 2024, 11:38 a.m. UTC | #1
Hi Arnd

Thanks for the patch

On Sat, Feb 24, 2024 at 1:11 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> The ipi handler here tries hard to maintain const-ness of its argument,
> but by doing that causes a warning about function type casts:

I worked on the same issue, but in instead of removing the const, I
tried to constify everything:
https://patchwork.linuxtv.org/project/linux-media/patch/20240226-fix-clang-warnings-v2-3-fa1bc931d17e@chromium.org/

My main goal is to remove the warning, so any patch is OK for me ;)

>
> drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c:38:32: error: cast from 'mtk_vcodec_ipi_handler' (aka 'void (*)(void *, unsigned int, void *)') to 'ipi_handler_t' (aka 'void (*)(const void *, unsigned int, void *)') converts to incompatible function type [-Werror,-Wcast-function-type-strict]
>    38 |         ipi_handler_t handler_const = (ipi_handler_t)handler;
>       |                                       ^~~~~~~~~~~~~~~~~~~~~~
>
> Remove the hack and just use a non-const argument.
>
> Fixes: bf1d556ad4e0 ("media: mtk-vcodec: abstract firmware interface")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
>  drivers/media/platform/mediatek/mdp/mtk_mdp_vpu.c      |  2 +-
>  .../mediatek/vcodec/common/mtk_vcodec_fw_vpu.c         | 10 +---------
>  drivers/media/platform/mediatek/vpu/mtk_vpu.c          |  2 +-
>  drivers/media/platform/mediatek/vpu/mtk_vpu.h          |  2 +-
>  4 files changed, 4 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/media/platform/mediatek/mdp/mtk_mdp_vpu.c b/drivers/media/platform/mediatek/mdp/mtk_mdp_vpu.c
> index b065ccd06914..378a1cba0144 100644
> --- a/drivers/media/platform/mediatek/mdp/mtk_mdp_vpu.c
> +++ b/drivers/media/platform/mediatek/mdp/mtk_mdp_vpu.c
> @@ -26,7 +26,7 @@ static void mtk_mdp_vpu_handle_init_ack(const struct mdp_ipi_comm_ack *msg)
>         vpu->inst_addr = msg->vpu_inst_addr;
>  }
>
> -static void mtk_mdp_vpu_ipi_handler(const void *data, unsigned int len,
> +static void mtk_mdp_vpu_ipi_handler(void *data, unsigned int len,
>                                     void *priv)
>  {
>         const struct mdp_ipi_comm_ack *msg = data;
> diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c
> index 9f6e4b59455d..4c34344dc7dc 100644
> --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c
> +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c
> @@ -29,15 +29,7 @@ static int mtk_vcodec_vpu_set_ipi_register(struct mtk_vcodec_fw *fw, int id,
>                                            mtk_vcodec_ipi_handler handler,
>                                            const char *name, void *priv)
>  {
> -       /*
> -        * The handler we receive takes a void * as its first argument. We
> -        * cannot change this because it needs to be passed down to the rproc
> -        * subsystem when SCP is used. VPU takes a const argument, which is
> -        * more constrained, so the conversion below is safe.
> -        */
> -       ipi_handler_t handler_const = (ipi_handler_t)handler;
> -
> -       return vpu_ipi_register(fw->pdev, id, handler_const, name, priv);
> +       return vpu_ipi_register(fw->pdev, id, handler, name, priv);
>  }
>
>  static int mtk_vcodec_vpu_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf,
> diff --git a/drivers/media/platform/mediatek/vpu/mtk_vpu.c b/drivers/media/platform/mediatek/vpu/mtk_vpu.c
> index 7243604a82a5..724ae7c2ab3b 100644
> --- a/drivers/media/platform/mediatek/vpu/mtk_vpu.c
> +++ b/drivers/media/platform/mediatek/vpu/mtk_vpu.c
> @@ -635,7 +635,7 @@ int vpu_load_firmware(struct platform_device *pdev)
>  }
>  EXPORT_SYMBOL_GPL(vpu_load_firmware);
>
> -static void vpu_init_ipi_handler(const void *data, unsigned int len, void *priv)
> +static void vpu_init_ipi_handler(void *data, unsigned int len, void *priv)
>  {
>         struct mtk_vpu *vpu = priv;
>         const struct vpu_run *run = data;
> diff --git a/drivers/media/platform/mediatek/vpu/mtk_vpu.h b/drivers/media/platform/mediatek/vpu/mtk_vpu.h
> index a56053ff135a..da05f3e74081 100644
> --- a/drivers/media/platform/mediatek/vpu/mtk_vpu.h
> +++ b/drivers/media/platform/mediatek/vpu/mtk_vpu.h
> @@ -17,7 +17,7 @@
>   * VPU interfaces with other blocks by share memory and interrupt.
>   */
>
> -typedef void (*ipi_handler_t) (const void *data,
> +typedef void (*ipi_handler_t) (void *data,
>                                unsigned int len,
>                                void *priv);
>
> --
> 2.39.2
>
>
  
Arnd Bergmann Feb. 27, 2024, 12:30 p.m. UTC | #2
On Tue, Feb 27, 2024, at 12:38, Ricardo Ribalda Delgado wrote:
> On Sat, Feb 24, 2024 at 1:11 PM Arnd Bergmann <arnd@kernel.org> wrote:
>>
>> From: Arnd Bergmann <arnd@arndb.de>
>>
>> The ipi handler here tries hard to maintain const-ness of its argument,
>> but by doing that causes a warning about function type casts:
>
> I worked on the same issue, but in instead of removing the const, I
> tried to constify everything:
> https://patchwork.linuxtv.org/project/linux-media/patch/20240226-fix-clang-warnings-v2-3-fa1bc931d17e@chromium.org/

I had almost the same patch originally but ended up not sending
it because I could not figure out what to do about

typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);

which is a generic part of rpmsg that takes a non-const pointer
and gets called by mtk_rpmsg_ipi_handler(), which would now
get a const pointer.

     Arnd
  

Patch

diff --git a/drivers/media/platform/mediatek/mdp/mtk_mdp_vpu.c b/drivers/media/platform/mediatek/mdp/mtk_mdp_vpu.c
index b065ccd06914..378a1cba0144 100644
--- a/drivers/media/platform/mediatek/mdp/mtk_mdp_vpu.c
+++ b/drivers/media/platform/mediatek/mdp/mtk_mdp_vpu.c
@@ -26,7 +26,7 @@  static void mtk_mdp_vpu_handle_init_ack(const struct mdp_ipi_comm_ack *msg)
 	vpu->inst_addr = msg->vpu_inst_addr;
 }
 
-static void mtk_mdp_vpu_ipi_handler(const void *data, unsigned int len,
+static void mtk_mdp_vpu_ipi_handler(void *data, unsigned int len,
 				    void *priv)
 {
 	const struct mdp_ipi_comm_ack *msg = data;
diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c
index 9f6e4b59455d..4c34344dc7dc 100644
--- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c
+++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c
@@ -29,15 +29,7 @@  static int mtk_vcodec_vpu_set_ipi_register(struct mtk_vcodec_fw *fw, int id,
 					   mtk_vcodec_ipi_handler handler,
 					   const char *name, void *priv)
 {
-	/*
-	 * The handler we receive takes a void * as its first argument. We
-	 * cannot change this because it needs to be passed down to the rproc
-	 * subsystem when SCP is used. VPU takes a const argument, which is
-	 * more constrained, so the conversion below is safe.
-	 */
-	ipi_handler_t handler_const = (ipi_handler_t)handler;
-
-	return vpu_ipi_register(fw->pdev, id, handler_const, name, priv);
+	return vpu_ipi_register(fw->pdev, id, handler, name, priv);
 }
 
 static int mtk_vcodec_vpu_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf,
diff --git a/drivers/media/platform/mediatek/vpu/mtk_vpu.c b/drivers/media/platform/mediatek/vpu/mtk_vpu.c
index 7243604a82a5..724ae7c2ab3b 100644
--- a/drivers/media/platform/mediatek/vpu/mtk_vpu.c
+++ b/drivers/media/platform/mediatek/vpu/mtk_vpu.c
@@ -635,7 +635,7 @@  int vpu_load_firmware(struct platform_device *pdev)
 }
 EXPORT_SYMBOL_GPL(vpu_load_firmware);
 
-static void vpu_init_ipi_handler(const void *data, unsigned int len, void *priv)
+static void vpu_init_ipi_handler(void *data, unsigned int len, void *priv)
 {
 	struct mtk_vpu *vpu = priv;
 	const struct vpu_run *run = data;
diff --git a/drivers/media/platform/mediatek/vpu/mtk_vpu.h b/drivers/media/platform/mediatek/vpu/mtk_vpu.h
index a56053ff135a..da05f3e74081 100644
--- a/drivers/media/platform/mediatek/vpu/mtk_vpu.h
+++ b/drivers/media/platform/mediatek/vpu/mtk_vpu.h
@@ -17,7 +17,7 @@ 
  * VPU interfaces with other blocks by share memory and interrupt.
  */
 
-typedef void (*ipi_handler_t) (const void *data,
+typedef void (*ipi_handler_t) (void *data,
 			       unsigned int len,
 			       void *priv);