Skip to contentSkip to conversation

drm/mediatek: dsi: fix error codes in mtk_dsi_host_transfer()

PATCH In review Dan Carpenter 3 participants 3 messages Feb 27, 2023 – Mar 1, 2023

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

PATCH 1/1 drm/mediatek: dsi: fix error codes in mtk_dsi_host_transfer()

There is a type bug because the return statement:

	return ret < 0 ? ret : recv_cnt;

will not return negatives on 64bit systems. The problem is that the function returns ssize_t types, while "ret" is int and "recv_cnt" is a u32. The negative values are type promoted to u32 and returned as positive values instead of negative error codes.

Fixes 81cc7e51c4f1 ("drm/mediatek: Allow commands to be sent during video mode")
---
 drivers/gpu/drm/mediatek/mtk_dsi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/mediatek/mtk_dsi.c +3 -3
index 7d5250351193..8e99981ca0e1 100644
@@ -1016,12 +1016,12 @@ static ssize_t mtk_dsi_host_transfer(struct mipi_dsi_host *host,
 				     const struct mipi_dsi_msg *msg)
 {
 	struct mtk_dsi *dsi = host_to_dsi(host);
-	u32 recv_cnt, i;
+	ssize_t recv_cnt;
 	u8 read_data[16];
 	void *src_addr;
 	u8 irq_flag = CMD_DONE_INT_FLAG;
 	u32 dsi_mode;
-	int ret;
+	int ret, i;
 
 	dsi_mode = readl(dsi->regs + DSI_MODE_CTRL);
 	if (dsi_mode & MODE) {
@@ -1070,7 +1070,7 @@ static ssize_t mtk_dsi_host_transfer(struct mipi_dsi_host *host,
 	if (recv_cnt)
 		memcpy(msg->rx_buf, src_addr, recv_cnt);
 
-	DRM_INFO("dsi get %d byte data from the panel address(0x%x)\n",
+	DRM_INFO("dsi get %zd byte data from the panel address(0x%x)\n",
 		 recv_cnt, *((u8 *)(msg->tx_buf)));
 
 restore_dsi_mode:
Signature · 1 line
2.39.1
Reviewed-by on v1 1/1
#1 lore raw

Dear Dan,

Thank you for your patch.

Quoted 11 lines · Dan Carpenter

There is a type bug because the return statement:

	return ret < 0 ? ret : recv_cnt;

will not return negatives on 64bit systems. The problem is that the function returns ssize_t types, while "ret" is int and "recv_cnt" is a u32. The negative values are type promoted to u32 and returned as positive values instead of negative error codes.

Fixes 81cc7e51c4f1 ("drm/mediatek: Allow commands to be sent during video mode")
Quoted 34 lines
---
 drivers/gpu/drm/mediatek/mtk_dsi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/mediatek/mtk_dsi.c +3 -3
index 7d5250351193..8e99981ca0e1 100644
@@ -1016,12 +1016,12 @@ static ssize_t mtk_dsi_host_transfer(struct mipi_dsi_host *host,
 				     const struct mipi_dsi_msg *msg)
 {
 	struct mtk_dsi *dsi = host_to_dsi(host);
-	u32 recv_cnt, i;
+	ssize_t recv_cnt;
 	u8 read_data[16];
 	void *src_addr;
 	u8 irq_flag = CMD_DONE_INT_FLAG;
 	u32 dsi_mode;
-	int ret;
+	int ret, i;
 
 	dsi_mode = readl(dsi->regs + DSI_MODE_CTRL);
 	if (dsi_mode & MODE) {
@@ -1070,7 +1070,7 @@ static ssize_t mtk_dsi_host_transfer(struct mipi_dsi_host *host,
 	if (recv_cnt)
 		memcpy(msg->rx_buf, src_addr, recv_cnt);
 
-	DRM_INFO("dsi get %d byte data from the panel address(0x%x)\n",
+	DRM_INFO("dsi get %zd byte data from the panel address(0x%x)\n",
 		 recv_cnt, *((u8 *)(msg->tx_buf)));
 
 restore_dsi_mode:
Signature · 1 line
2.39.1
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Dan Carpenter

Il 27/02/23 11:08, Dan Carpenter ha scritto:

Quoted 11 lines

There is a type bug because the return statement:

	return ret < 0 ? ret : recv_cnt;

will not return negatives on 64bit systems. The problem is that the function returns ssize_t types, while "ret" is int and "recv_cnt" is a u32. The negative values are type promoted to u32 and returned as positive values instead of negative error codes.

Fixes 81cc7e51c4f1 ("drm/mediatek: Allow commands to be sent during video mode")