[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b11a19b6-9fb3-4fdc-b94e-33ff01a634b3@rowland.harvard.edu>
Date: Tue, 12 Aug 2025 16:06:35 -0400
From: Alan Stern <stern@...land.harvard.edu>
To: Thorsten Blum <thorsten.blum@...ux.dev>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-usb@...r.kernel.org, usb-storage@...ts.one-eyed-alien.net,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] usb: storage: realtek_cr: Simplify
rts51x_bulk_transport()
On Tue, Aug 12, 2025 at 04:43:58PM +0200, Thorsten Blum wrote:
> Change the function parameter 'buf_len' from 'int' to 'unsigned int' and
> only update the local variable 'residue' if needed.
>
> Update the rts51x_read_status() function signature accordingly.
That last part isn't really necessary, is it? It doesn't make the code
any clearer, less buggy, or quicker to execute.
> Signed-off-by: Thorsten Blum <thorsten.blum@...ux.dev>
> ---
> drivers/usb/storage/realtek_cr.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
> index 7dea28c2b8ee..8a4d7c0f2662 100644
> --- a/drivers/usb/storage/realtek_cr.c
> +++ b/drivers/usb/storage/realtek_cr.c
> @@ -199,7 +199,8 @@ static const struct us_unusual_dev realtek_cr_unusual_dev_list[] = {
> #undef UNUSUAL_DEV
>
> static int rts51x_bulk_transport(struct us_data *us, u8 lun,
> - u8 *cmd, int cmd_len, u8 *buf, int buf_len,
> + u8 *cmd, int cmd_len, u8 *buf,
> + unsigned int buf_len,
> enum dma_data_direction dir, int *act_len)
> {
> struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *)us->iobuf;
> @@ -260,8 +261,8 @@ static int rts51x_bulk_transport(struct us_data *us, u8 lun,
> * try to compute the actual residue, based on how much data
> * was really transferred and what the device tells us
> */
> - if (residue)
> - residue = residue < buf_len ? residue : buf_len;
> + if (residue > buf_len)
> + residue = buf_len;
This really has nothing at all to do with whether buf_len is a signed
quantity -- it should never be negative. (And I have no idea why the
original code includes that test for residue being nonzero.)
Much more serious is something you didn't change: Just above these lines
it says:
residue = bcs->Residue;
It should say:
residue = le32_to_cpu(bcs->Residue);
Alan Stern
Powered by blists - more mailing lists