Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: ucsi: stm32: Use min() to improve ucsi_stm32g0_fw_cb()

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>
Link: https://lore.kernel.org/r/20250830110426.10007-2-thorsten.blum@linux.dev
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thorsten Blum and committed by
Greg Kroah-Hartman
91709d2c 3474a197

+2 -5
+2 -5
drivers/usb/typec/ucsi/ucsi_stm32g0.c
··· 10 10 #include <linux/firmware.h> 11 11 #include <linux/i2c.h> 12 12 #include <linux/interrupt.h> 13 + #include <linux/minmax.h> 13 14 #include <linux/module.h> 14 15 #include <linux/platform_device.h> 15 16 #include <linux/unaligned.h> ··· 524 523 data = fw->data; 525 524 end = fw->data + fw->size; 526 525 while (data < end) { 527 - if ((end - data) < STM32G0_I2C_BL_SZ) 528 - size = end - data; 529 - else 530 - size = STM32G0_I2C_BL_SZ; 531 - 526 + size = min(end - data, STM32G0_I2C_BL_SZ); 532 527 ret = ucsi_stm32g0_bl_write(g0->ucsi, addr, data, size); 533 528 if (ret) { 534 529 dev_err(g0->dev, "Write failed %d\n", ret);