Skip to contentSkip to conversation

mtk_mdp_vpu: fix build with COMPILE_TEST for 32 bits

PATCH New Mauro Carvalho Chehab 2 participants 9 messages Oct 21, 2016 – Oct 24, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 mtk_mdp_vpu: fix build with COMPILE_TEST for 32 bits

When building on i386 in 32 bits, several new warnings appear:

drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c: In function 'mtk_mdp_vpu_handle_init_ack':
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c:28:28: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

  struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)msg->ap_inst;
                            ^
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c: In function 'mtk_mdp_vpu_ipi_handler':
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c:40:28: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)msg->ap_inst;
                            ^
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c: In function 'mtk_mdp_vpu_send_ap_ipi':
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c:111:16: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  msg.ap_inst = (uint64_t)vpu;
                ^
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c: In function 'mtk_mdp_vpu_init':
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c:129:16: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  msg.ap_inst = (uint64_t)vpu;
                ^

That's because the driver assumes that it will be built only on 64 bits. As we don't want extra warnings when building with 32 bits, we need to double-cast.

---
 drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c +4 -4
index fb07bf3dbd8b..b38d29e99f7a 100644
@@ -25,7 +25,7 @@ static inline struct mtk_mdp_ctx *vpu_to_ctx(struct mtk_mdp_vpu *vpu)
 
 static void mtk_mdp_vpu_handle_init_ack(struct mdp_ipi_comm_ack *msg)
 {
-	struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)msg->ap_inst;
+	struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)(long)msg->ap_inst;
 
 	/* mapping VPU address to kernel virtual address */
 	vpu->vsi = (struct mdp_process_vsi *)
@@ -37,7 +37,7 @@ static void mtk_mdp_vpu_ipi_handler(void *data, unsigned int len, void *priv)
 {
 	unsigned int msg_id = *(unsigned int *)data;
 	struct mdp_ipi_comm_ack *msg = (struct mdp_ipi_comm_ack *)data;
-	struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)msg->ap_inst;
+	struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)(long)msg->ap_inst;
 	struct mtk_mdp_ctx *ctx;
 
 	vpu->failure = msg->status;
@@ -108,7 +108,7 @@ static int mtk_mdp_vpu_send_ap_ipi(struct mtk_mdp_vpu *vpu, uint32_t msg_id)
 	msg.msg_id = msg_id;
 	msg.ipi_id = IPI_MDP;
 	msg.vpu_inst_addr = vpu->inst_addr;
-	msg.ap_inst = (uint64_t)vpu;
+	msg.ap_inst = (uint64_t)(long)vpu;
 	err = mtk_mdp_vpu_send_msg((void *)&msg, sizeof(msg), vpu, IPI_MDP);
 	if (!err && vpu->failure)
 		err = -EINVAL;
@@ -126,7 +126,7 @@ int mtk_mdp_vpu_init(struct mtk_mdp_vpu *vpu)
 
 	msg.msg_id = AP_MDP_INIT;
 	msg.ipi_id = IPI_MDP;
-	msg.ap_inst = (uint64_t)vpu;
+	msg.ap_inst = (uint64_t)(long)vpu;
 	err = mtk_mdp_vpu_send_msg((void *)&msg, sizeof(msg), vpu, IPI_MDP);
 	if (!err && vpu->failure)
 		err = -EINVAL;
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/4 mtk_mdp_vpu: remove a double unlock at the error path

As warned by smatch:

	drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c:98 mtk_mdp_vpu_send_msg() error: double unlock 'mutex:&ctx->mdp_dev->vpulock'
---
 drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c | 1 -
 1 file changed, 1 deletion(-)
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c +0 -1
index b38d29e99f7a..5c8caa864e32 100644
@@ -91,7 +91,6 @@ static int mtk_mdp_vpu_send_msg(void *msg, int len, struct mtk_mdp_vpu *vpu,
 	mutex_lock(&ctx->mdp_dev->vpulock);
 	err = vpu_ipi_send(vpu->pdev, (enum ipi_id)id, msg, len);
 	if (err) {
-		mutex_unlock(&ctx->mdp_dev->vpulock);
 		dev_err(&ctx->mdp_dev->pdev->dev,
 			"vpu_ipi_send fail status %d\n", err);
 	}
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/4 mtk_mdp_vpu: remove a double unlock at the error path

Quoted 13 lines · Mauro Carvalho Chehab

As warned by smatch:

	drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c:98 mtk_mdp_vpu_send_msg() error: double unlock 'mutex:&ctx->mdp_dev->vpulock'
---
 drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c | 1 -
 1 file changed, 1 deletion(-)
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c +0 -0
index b38d29e99f7a..5c8caa864e32 100644

drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c static int mtk_mdp_vpu_send_msg(void *msg, int len, struct mtk_mdp_vpu *vpu, · line 94

Quoted 4 lines
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c +0 -1
@@ -91,7 +91,6 @@ static int mtk_mdp_vpu_send_msg(void *msg, int len, struct mtk_mdp_vpu *vpu,
 	mutex_lock(&ctx->mdp_dev->vpulock);
 	err = vpu_ipi_send(vpu->pdev, (enum ipi_id)id, msg, len);
 	if (err) {
-		mutex_unlock(&ctx->mdp_dev->vpulock);

Hi Mauro,

It has been fixed by Hans in the later patch.

Author: Hans Verkuil <[email protected]>
Date:   Mon Sep 19 05:00:34 2016 -0300

[media] mtk-mdp: fix double mutex_unlock

Fix smatch error:

media-git/drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c:100
mtk_mdp_vpu_send_msg() error: double unlock 'mutex:&ctx->

minghsiu

Quoted 3 lines
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c +0 -0
 		dev_err(&ctx->mdp_dev->pdev->dev,
 			"vpu_ipi_send fail status %d\n", err);
 	}
#3 lore raw

PATCH 3/4 mtk_mdp_m2m: remove an unused struct

In reply to Mauro Carvalho Chehab

drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c:48:33: warning: ?mtk_mdp_size_align? defined but not used [-Wunused-variable]

 static struct mtk_mdp_pix_align mtk_mdp_size_align = {
                                 ^~~~~~~~~~~~~~~~~~
---
 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c +0 -7
index 065502757133..33124a6c9951 100644
@@ -45,13 +45,6 @@ struct mtk_mdp_pix_limit {
 	u16 target_rot_en_h;
 };
 
-static struct mtk_mdp_pix_align mtk_mdp_size_align = {
-	.org_w			= 16,
-	.org_h			= 16,
-	.target_w		= 2,
-	.target_h		= 2,
-};
-
 static const struct mtk_mdp_fmt mtk_mdp_formats[] = {
 	{
 		.pixelformat	= V4L2_PIX_FMT_NV12M,
Signature · 1 line
2.7.4
#4 lore raw

PATCH 3/4 mtk_mdp_m2m: remove an unused struct

Quoted 14 lines · Mauro Carvalho Chehab

drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c:48:33: warning: ?mtk_mdp_size_align? defined but not used [-Wunused-variable]

 static struct mtk_mdp_pix_align mtk_mdp_size_align = {
                                 ^~~~~~~~~~~~~~~~~~
---
 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c +0 -0
index 065502757133..33124a6c9951 100644

drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c struct mtk_mdp_pix_limit { · line 54

Quoted 10 lines
drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c +0 -7
@@ -45,13 +45,6 @@ struct mtk_mdp_pix_limit {
 	u16 target_rot_en_h;
 };
 
-static struct mtk_mdp_pix_align mtk_mdp_size_align = {
-	.org_w			= 16,
-	.org_h			= 16,
-	.target_w		= 2,
-	.target_h		= 2,
-};
-

Hi Mauro,

The structure is used for the format V4L2_PIX_FMT_MT21C which is added in the later patch.
"[media] media: mtk-mdp: support pixelformat V4L2_PIX_FMT_MT21C"

I just know checkpatch should be run patch by patch, so this warning message will be generated without the MT21C patch.

I found all mtk-mdp patches have been merged in media tree, so is this patch still needed?

If yes, remove 'mtk_mdp_size_align' in this patch, and re-added it in the MT21C patch.

minghsiu

Quoted 3 lines
drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c +0 -0
 static const struct mtk_mdp_fmt mtk_mdp_formats[] = {
 	{
 		.pixelformat	= V4L2_PIX_FMT_NV12M,
#5 lore raw

PATCH 3/4 mtk_mdp_m2m: remove an unused struct

In reply to Mauro Carvalho Chehab
Quoted 14 lines · Mauro Carvalho Chehab

drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c:48:33: warning: ?mtk_mdp_size_align? defined but not used [-Wunused-variable]

 static struct mtk_mdp_pix_align mtk_mdp_size_align = {
                                 ^~~~~~~~~~~~~~~~~~
---
 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c +0 -0
index 065502757133..33124a6c9951 100644

drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c struct mtk_mdp_pix_limit { · line 54

Quoted 10 lines
drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c +0 -7
@@ -45,13 +45,6 @@ struct mtk_mdp_pix_limit {
 	u16 target_rot_en_h;
 };
 
-static struct mtk_mdp_pix_align mtk_mdp_size_align = {
-	.org_w			= 16,
-	.org_h			= 16,
-	.target_w		= 2,
-	.target_h		= 2,
-};
-

Hi Mauro,

The structure is used for the format V4L2_PIX_FMT_MT21C which is added in the later patch.
"[media] media: mtk-mdp: support pixelformat V4L2_PIX_FMT_MT21C"

I just know checkpatch should be run patch by patch, so this warning message will be generated without the MT21C patch.

I found all mtk-mdp patches have been merged in media tree, so is this patch still needed?

If yes, remove 'mtk_mdp_size_align' in this patch, and re-added it in the MT21C patch.

minghsiu

Quoted 3 lines
drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c +0 -0
 static const struct mtk_mdp_fmt mtk_mdp_formats[] = {
 	{
 		.pixelformat	= V4L2_PIX_FMT_NV12M,
#6 lore raw

PATCH 4/4 mtk-mdp: fix compilation warnings if !DEBUG

In reply to Mauro Carvalho Chehab

The mtk_mdp_dbg() is empty if !DEBUG. This causes the following warnings:

	drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c: In function ?mtk_mdp_try_fmt_mplane?:
	drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c:231:52: warning: suggest braces around empty body in an ?if? statement [-Wempty-body]
	        org_w, org_h, pix_mp->width, pix_mp->height);
                                                    ^
	drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c: In function ?mtk_mdp_m2m_start_streaming?:
	drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c:414:21: warning: suggest braces around empty body in an ?if? statement [-Wempty-body]
	        ctx->id, ret);
	                     ^

With could actually make the code to do something wrong. So, add an empty block to make it be parsed ok.

---
 drivers/media/platform/mtk-mdp/mtk_mdp_core.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/mtk-mdp/mtk_mdp_core.h +1 -1
index 2e979f97d1df..848569d4ab90 100644
@@ -250,7 +250,7 @@ extern int mtk_mdp_dbg_level;
 
 #else
 
-#define mtk_mdp_dbg(level, fmt, args...)
+#define mtk_mdp_dbg(level, fmt, args...) {}
 #define mtk_mdp_err(fmt, args...)
 #define mtk_mdp_dbg_enter()
 #define mtk_mdp_dbg_leave()
Signature · 1 line
2.7.4
#7 lore raw

PATCH 4/4 mtk-mdp: fix compilation warnings if !DEBUG

Quoted 25 lines · Mauro Carvalho Chehab

The mtk_mdp_dbg() is empty if !DEBUG. This causes the following warnings:

	drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c: In function ?mtk_mdp_try_fmt_mplane?:
	drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c:231:52: warning: suggest braces around empty body in an ?if? statement [-Wempty-body]
	        org_w, org_h, pix_mp->width, pix_mp->height);
                                                    ^
	drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c: In function ?mtk_mdp_m2m_start_streaming?:
	drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c:414:21: warning: suggest braces around empty body in an ?if? statement [-Wempty-body]
	        ctx->id, ret);
	                     ^

With could actually make the code to do something wrong. So, add an empty block to make it be parsed ok.

---
 drivers/media/platform/mtk-mdp/mtk_mdp_core.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/mtk-mdp/mtk_mdp_core.h +0 -0
index 2e979f97d1df..848569d4ab90 100644

drivers/media/platform/mtk-mdp/mtk_mdp_core.h extern int mtk_mdp_dbg_level; · line 254

Quoted 6 lines
drivers/media/platform/mtk-mdp/mtk_mdp_core.h +1 -1
@@ -250,7 +250,7 @@ extern int mtk_mdp_dbg_level;
 
 #else
 
-#define mtk_mdp_dbg(level, fmt, args...)
+#define mtk_mdp_dbg(level, fmt, args...) {}
 
Quoted 3 lines
drivers/media/platform/mtk-mdp/mtk_mdp_core.h +0 -0
 #define mtk_mdp_err(fmt, args...)
 #define mtk_mdp_dbg_enter()

#define mtk_mdp_dbg_leave()

#8 lore raw

PATCH 1/4 mtk_mdp_vpu: fix build with COMPILE_TEST for 32 bits

In reply to Mauro Carvalho Chehab

Hi Mauro,

This issue has been fixed by the patch below and merged in media tree, and also signed by you.

Is it duplicate?

commit 37bf7e34ecc817ce6b8278588aeb22aab5635e1c

Author: Minghsiu Tsai <[email protected]>
Date:   Mon Sep 19 03:34:42 2016 -0300

[media] media: mtk-mdp: fix build warning in arch x86

This patch fix build warning in arch x86

Quoted 68 lines · Mauro Carvalho Chehab

When building on i386 in 32 bits, several new warnings appear:

drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c: In function 'mtk_mdp_vpu_handle_init_ack':
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c:28:28: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

  struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)msg->ap_inst;
                            ^
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c: In function 'mtk_mdp_vpu_ipi_handler':
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c:40:28: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)msg->ap_inst;
                            ^
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c: In function 'mtk_mdp_vpu_send_ap_ipi':
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c:111:16: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  msg.ap_inst = (uint64_t)vpu;
                ^
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c: In function 'mtk_mdp_vpu_init':
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c:129:16: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  msg.ap_inst = (uint64_t)vpu;
                ^

That's because the driver assumes that it will be built only on 64 bits. As we don't want extra warnings when building with 32 bits, we need to double-cast.

---
 drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/platform/mtk-mdp/mtk_mdp_vpu.c +4 -4
index fb07bf3dbd8b..b38d29e99f7a 100644
@@ -25,7 +25,7 @@ static inline struct mtk_mdp_ctx *vpu_to_ctx(struct mtk_mdp_vpu *vpu)
 
 static void mtk_mdp_vpu_handle_init_ack(struct mdp_ipi_comm_ack *msg)
 {
-	struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)msg->ap_inst;
+	struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)(long)msg->ap_inst;
 
 	/* mapping VPU address to kernel virtual address */
 	vpu->vsi = (struct mdp_process_vsi *)
@@ -37,7 +37,7 @@ static void mtk_mdp_vpu_ipi_handler(void *data, unsigned int len, void *priv)
 {
 	unsigned int msg_id = *(unsigned int *)data;
 	struct mdp_ipi_comm_ack *msg = (struct mdp_ipi_comm_ack *)data;
-	struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)msg->ap_inst;
+	struct mtk_mdp_vpu *vpu = (struct mtk_mdp_vpu *)(long)msg->ap_inst;
 	struct mtk_mdp_ctx *ctx;
 
 	vpu->failure = msg->status;
@@ -108,7 +108,7 @@ static int mtk_mdp_vpu_send_ap_ipi(struct mtk_mdp_vpu *vpu, uint32_t msg_id)
 	msg.msg_id = msg_id;
 	msg.ipi_id = IPI_MDP;
 	msg.vpu_inst_addr = vpu->inst_addr;
-	msg.ap_inst = (uint64_t)vpu;
+	msg.ap_inst = (uint64_t)(long)vpu;
 	err = mtk_mdp_vpu_send_msg((void *)&msg, sizeof(msg), vpu, IPI_MDP);
 	if (!err && vpu->failure)
 		err = -EINVAL;
@@ -126,7 +126,7 @@ int mtk_mdp_vpu_init(struct mtk_mdp_vpu *vpu)
 
 	msg.msg_id = AP_MDP_INIT;
 	msg.ipi_id = IPI_MDP;
-	msg.ap_inst = (uint64_t)vpu;
+	msg.ap_inst = (uint64_t)(long)vpu;
 	err = mtk_mdp_vpu_send_msg((void *)&msg, sizeof(msg), vpu, IPI_MDP);
 	if (!err && vpu->failure)
 		err = -EINVAL;