2024-06-06 09:13:26

by Javier Carrasco

[permalink] [raw]
Subject: [PATCH 3/3] usb: typec: tipd: use min() to set tps6598x firmware packet size

Simplify the current firmware packet size check in the tps6598x
implementation by means of a single call to min(), which is what the
current code does in a more verbose, less elegant way.

This patch fixes a cocci warning ("WARNING opportunity for min()").

Suggested-by: Julia Lawall <[email protected]>
Signed-off-by: Javier Carrasco <[email protected]>
---
drivers/usb/typec/tipd/core.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
index 58f6eeffd070..ea768b19a7f1 100644
--- a/drivers/usb/typec/tipd/core.c
+++ b/drivers/usb/typec/tipd/core.c
@@ -1165,10 +1165,7 @@ static int tps6598x_apply_patch(struct tps6598x *tps)

bytes_left = fw->size;
while (bytes_left) {
- if (bytes_left < TPS_MAX_LEN)
- in_len = bytes_left;
- else
- in_len = TPS_MAX_LEN;
+ in_len = min(bytes_left, TPS_MAX_LEN);
ret = tps6598x_exec_cmd(tps, "PTCd", in_len,
fw->data + copied_bytes,
TPS_PTCD_OUT_BYTES, out);

--
2.40.1



2024-06-06 13:51:52

by Heikki Krogerus

[permalink] [raw]
Subject: Re: [PATCH 3/3] usb: typec: tipd: use min() to set tps6598x firmware packet size

On Thu, Jun 06, 2024 at 11:03:57AM +0200, Javier Carrasco wrote:
> Simplify the current firmware packet size check in the tps6598x
> implementation by means of a single call to min(), which is what the
> current code does in a more verbose, less elegant way.
>
> This patch fixes a cocci warning ("WARNING opportunity for min()").
>
> Suggested-by: Julia Lawall <[email protected]>
> Signed-off-by: Javier Carrasco <[email protected]>

Reviewed-by: Heikki Krogerus <[email protected]>

> ---
> drivers/usb/typec/tipd/core.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
> index 58f6eeffd070..ea768b19a7f1 100644
> --- a/drivers/usb/typec/tipd/core.c
> +++ b/drivers/usb/typec/tipd/core.c
> @@ -1165,10 +1165,7 @@ static int tps6598x_apply_patch(struct tps6598x *tps)
>
> bytes_left = fw->size;
> while (bytes_left) {
> - if (bytes_left < TPS_MAX_LEN)
> - in_len = bytes_left;
> - else
> - in_len = TPS_MAX_LEN;
> + in_len = min(bytes_left, TPS_MAX_LEN);
> ret = tps6598x_exec_cmd(tps, "PTCd", in_len,
> fw->data + copied_bytes,
> TPS_PTCD_OUT_BYTES, out);
>
> --
> 2.40.1

--
heikki