Skip to contentSkip to conversation

drm/dsi: Fix improper use of mipi_dsi_device_transfer() return value

PATCH Applied Philippe Cornu 3 participants 4 messages Jan 12, 2018 – Jan 16, 2018

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

PATCH 1/1 drm/dsi: Fix improper use of mipi_dsi_device_transfer() return value

The function mipi_dsi_device_transfer() returns the number of transmitted or received bytes on success or a negative error code on failure.

The functions mipi_dsi_shutdown_peripheral(), mipi_dsi_turn_on_peripheral() & mipi_dsi_set_maximum_return_packet_size() use improperly this returned value in case of success: 0 should be returned instead of the number of transmitted bytes.

---
 drivers/gpu/drm/drm_mipi_dsi.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_mipi_dsi.c +6 -3
index 4b47226b90d4..bc73b7f5b9fc 100644
@@ -498,8 +498,9 @@ int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi)
 		.tx_buf = (u8 [2]) { 0, 0 },
 		.tx_len = 2,
 	};
+	int ret = mipi_dsi_device_transfer(dsi, &msg);
 
-	return mipi_dsi_device_transfer(dsi, &msg);
+	return (ret < 0) ? ret : 0;
 }
 EXPORT_SYMBOL(mipi_dsi_shutdown_peripheral);
 
@@ -517,8 +518,9 @@ int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi)
 		.tx_buf = (u8 [2]) { 0, 0 },
 		.tx_len = 2,
 	};
+	int ret = mipi_dsi_device_transfer(dsi, &msg);
 
-	return mipi_dsi_device_transfer(dsi, &msg);
+	return (ret < 0) ? ret : 0;
 }
 EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral);
 
@@ -541,8 +543,9 @@ int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
 		.tx_len = sizeof(tx),
 		.tx_buf = tx,
 	};
+	int ret = mipi_dsi_device_transfer(dsi, &msg);
 
-	return mipi_dsi_device_transfer(dsi, &msg);
+	return (ret < 0) ? ret : 0;
 }
 EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
 
Signature · 6 lines
2.15.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Philippe Cornu

The function mipi_dsi_device_transfer() returns the number of transmitted or received bytes on success or a negative error code on failure.

The functions mipi_dsi_shutdown_peripheral(), mipi_dsi_turn_on_peripheral() & mipi_dsi_set_maximum_return_packet_size() use improperly this returned value in case of success: 0 should be returned instead of the number of transmitted bytes.

I guess, the best would be to create and use some helper similar to PTR_ERR_OR_ZERO,
but this is also OK.

 --
Regards
Andrzej

Quoted 31 lines
---
 drivers/gpu/drm/drm_mipi_dsi.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_mipi_dsi.c +4 -2
index 4b47226b90d4..bc73b7f5b9fc 100644
@@ -498,8 +498,9 @@ int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi)
 		.tx_buf = (u8 [2]) { 0, 0 },
 		.tx_len = 2,
 	};
+	int ret = mipi_dsi_device_transfer(dsi, &msg);
 
-	return mipi_dsi_device_transfer(dsi, &msg);
+	return (ret < 0) ? ret : 0;
 }
 EXPORT_SYMBOL(mipi_dsi_shutdown_peripheral);
 
@@ -517,8 +518,9 @@ int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi)
 		.tx_buf = (u8 [2]) { 0, 0 },
 		.tx_len = 2,
 	};
+	int ret = mipi_dsi_device_transfer(dsi, &msg);
 
-	return mipi_dsi_device_transfer(dsi, &msg);
+	return (ret < 0) ? ret : 0;
 }
 EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral);
 

drivers/gpu/drm/drm_mipi_dsi.c int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi, · line 551

Quoted 10 lines
drivers/gpu/drm/drm_mipi_dsi.c +2 -1
@@ -541,8 +543,9 @@ int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
 		.tx_len = sizeof(tx),
 		.tx_buf = tx,
 	};
+	int ret = mipi_dsi_device_transfer(dsi, &msg);
 
-	return mipi_dsi_device_transfer(dsi, &msg);
+	return (ret < 0) ? ret : 0;
 }
 EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw

Hi Andrzej,

Quoted 9 lines · Andrzej Hajda
Quoted 8 lines · Philippe Cornu

The function mipi_dsi_device_transfer() returns the number of transmitted or received bytes on success or a negative error code on failure.

The functions mipi_dsi_shutdown_peripheral(), mipi_dsi_turn_on_peripheral() & mipi_dsi_set_maximum_return_packet_size() use improperly this returned value in case of success: 0 should be returned instead of the number of transmitted bytes.

Quoted 6 lines
Quoted 1 line

I guess, the best would be to create and use some helper similar to PTR_ERR_OR_ZERO,
but this is also OK.

Many thanks for your comment and review.

Before sending this patch, I searched for a better way to write these few lines, including searching for such macros but I did not find anything (pointers are largely covered but simple integers are not).

If someone has a better solution (with macros or otherwise), I am happy to learn/implement it.

Many thanks,
Philippe : )

Quoted 42 lines

 --
Regards
Andrzej

Quoted 36 lines
---
  drivers/gpu/drm/drm_mipi_dsi.c | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_mipi_dsi.c +5 -2
index 4b47226b90d4..bc73b7f5b9fc 100644
@@ -498,8 +498,9 @@ int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi)
  		.tx_buf = (u8 [2]) { 0, 0 },
  		.tx_len = 2,
  	};
+	int ret = mipi_dsi_device_transfer(dsi, &msg);
 
-	return mipi_dsi_device_transfer(dsi, &msg);
+	return (ret < 0) ? ret : 0;
  }
  EXPORT_SYMBOL(mipi_dsi_shutdown_peripheral);
 
@@ -517,8 +518,9 @@ int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi)
  		.tx_buf = (u8 [2]) { 0, 0 },
  		.tx_len = 2,
  	};
+	int ret = mipi_dsi_device_transfer(dsi, &msg);
 
-	return mipi_dsi_device_transfer(dsi, &msg);
+	return (ret < 0) ? ret : 0;
  }
  EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral);
 
@@ -541,8 +543,9 @@ int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
  		.tx_len = sizeof(tx),
  		.tx_buf = tx,
  	};
+	int ret = mipi_dsi_device_transfer(dsi, &msg);
 
Quoted 7 lines

drivers/gpu/drm/drm_mipi_dsi.c int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi, · line 551

Quoted 5 lines
drivers/gpu/drm/drm_mipi_dsi.c +1 -1
-	return mipi_dsi_device_transfer(dsi, &msg);
+	return (ret < 0) ? ret : 0;
  }
  EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Applied
#3 lore raw
In reply to Andrzej Hajda
Quoted 9 lines · Andrzej Hajda
Quoted 8 lines · Philippe Cornu

The function mipi_dsi_device_transfer() returns the number of transmitted or received bytes on success or a negative error code on failure.

The functions mipi_dsi_shutdown_peripheral(), mipi_dsi_turn_on_peripheral() & mipi_dsi_set_maximum_return_packet_size() use improperly this returned value in case of success: 0 should be returned instead of the number of transmitted bytes.

Quoted 7 lines
Quoted 1 line

I guess, the best would be to create and use some helper similar to PTR_ERR_OR_ZERO,
but this is also OK.

Applied to drm-misc-next. Thanks for the patch and review

Sean

Quoted 48 lines

 --
Regards
Andrzej

Quoted 41 lines
---
 drivers/gpu/drm/drm_mipi_dsi.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_mipi_dsi.c +6 -3
index 4b47226b90d4..bc73b7f5b9fc 100644
@@ -498,8 +498,9 @@ int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi)
 		.tx_buf = (u8 [2]) { 0, 0 },
 		.tx_len = 2,
 	};
+	int ret = mipi_dsi_device_transfer(dsi, &msg);
 
-	return mipi_dsi_device_transfer(dsi, &msg);
+	return (ret < 0) ? ret : 0;
 }
 EXPORT_SYMBOL(mipi_dsi_shutdown_peripheral);
 
@@ -517,8 +518,9 @@ int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi)
 		.tx_buf = (u8 [2]) { 0, 0 },
 		.tx_len = 2,
 	};
+	int ret = mipi_dsi_device_transfer(dsi, &msg);
 
-	return mipi_dsi_device_transfer(dsi, &msg);
+	return (ret < 0) ? ret : 0;
 }
 EXPORT_SYMBOL(mipi_dsi_turn_on_peripheral);
 
@@ -541,8 +543,9 @@ int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
 		.tx_len = sizeof(tx),
 		.tx_buf = tx,
 	};
+	int ret = mipi_dsi_device_transfer(dsi, &msg);
 
-	return mipi_dsi_device_transfer(dsi, &msg);
+	return (ret < 0) ? ret : 0;
 }
 EXPORT_SYMBOL(mipi_dsi_set_maximum_return_packet_size);
 
Signature · 5 lines
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel