* [PATCH] usb: ucsi: stm32: Use min() to improve ucsi_stm32g0_fw_cb()
@ 2025-08-30 11:04 Thorsten Blum
2025-09-05 10:59 ` Heikki Krogerus
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-08-30 11:04 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman, Maxime Coquelin,
Alexandre Torgue, Fedor Pchelkin, Christian A. Ehrhardt, Al Viro
Cc: Thorsten Blum, linux-usb, linux-stm32, linux-arm-kernel,
linux-kernel
Use min() to improve ucsi_stm32g0_fw_cb() and avoid calculating
'end - data' twice.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
drivers/usb/typec/ucsi/ucsi_stm32g0.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/typec/ucsi/ucsi_stm32g0.c b/drivers/usb/typec/ucsi/ucsi_stm32g0.c
index 57ef7d83a412..838ac0185082 100644
--- a/drivers/usb/typec/ucsi/ucsi_stm32g0.c
+++ b/drivers/usb/typec/ucsi/ucsi_stm32g0.c
@@ -10,6 +10,7 @@
#include <linux/firmware.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
+#include <linux/minmax.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/unaligned.h>
@@ -523,11 +524,7 @@ static void ucsi_stm32g0_fw_cb(const struct firmware *fw, void *context)
data = fw->data;
end = fw->data + fw->size;
while (data < end) {
- if ((end - data) < STM32G0_I2C_BL_SZ)
- size = end - data;
- else
- size = STM32G0_I2C_BL_SZ;
-
+ size = min(end - data, STM32G0_I2C_BL_SZ);
ret = ucsi_stm32g0_bl_write(g0->ucsi, addr, data, size);
if (ret) {
dev_err(g0->dev, "Write failed %d\n", ret);
--
2.50.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] usb: ucsi: stm32: Use min() to improve ucsi_stm32g0_fw_cb()
2025-08-30 11:04 [PATCH] usb: ucsi: stm32: Use min() to improve ucsi_stm32g0_fw_cb() Thorsten Blum
@ 2025-09-05 10:59 ` Heikki Krogerus
0 siblings, 0 replies; 2+ messages in thread
From: Heikki Krogerus @ 2025-09-05 10:59 UTC (permalink / raw)
To: Thorsten Blum
Cc: Greg Kroah-Hartman, Maxime Coquelin, Alexandre Torgue,
Fedor Pchelkin, Christian A. Ehrhardt, Al Viro, linux-usb,
linux-stm32, linux-arm-kernel, linux-kernel
On Sat, Aug 30, 2025 at 01:04:20PM +0200, Thorsten Blum wrote:
> Use min() to improve ucsi_stm32g0_fw_cb() and avoid calculating
> 'end - data' twice.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> drivers/usb/typec/ucsi/ucsi_stm32g0.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/usb/typec/ucsi/ucsi_stm32g0.c b/drivers/usb/typec/ucsi/ucsi_stm32g0.c
> index 57ef7d83a412..838ac0185082 100644
> --- a/drivers/usb/typec/ucsi/ucsi_stm32g0.c
> +++ b/drivers/usb/typec/ucsi/ucsi_stm32g0.c
> @@ -10,6 +10,7 @@
> #include <linux/firmware.h>
> #include <linux/i2c.h>
> #include <linux/interrupt.h>
> +#include <linux/minmax.h>
> #include <linux/module.h>
> #include <linux/platform_device.h>
> #include <linux/unaligned.h>
> @@ -523,11 +524,7 @@ static void ucsi_stm32g0_fw_cb(const struct firmware *fw, void *context)
> data = fw->data;
> end = fw->data + fw->size;
> while (data < end) {
> - if ((end - data) < STM32G0_I2C_BL_SZ)
> - size = end - data;
> - else
> - size = STM32G0_I2C_BL_SZ;
> -
> + size = min(end - data, STM32G0_I2C_BL_SZ);
> ret = ucsi_stm32g0_bl_write(g0->ucsi, addr, data, size);
> if (ret) {
> dev_err(g0->dev, "Write failed %d\n", ret);
> --
> 2.50.1
--
heikki
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-05 14:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-30 11:04 [PATCH] usb: ucsi: stm32: Use min() to improve ucsi_stm32g0_fw_cb() Thorsten Blum
2025-09-05 10:59 ` Heikki Krogerus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).