From: Lee Jones <lee@kernel.org>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] usb: fotg210-hcd: delete an incorrect bounds test
Date: Wed, 13 Dec 2023 11:49:06 +0000 [thread overview]
Message-ID: <20231213114906.GL111411@google.com> (raw)
In-Reply-To: <87dfa523-1882-417d-97b5-f606ff0099f9@moroto.mountain>
On Fri, 08 Dec 2023, Dan Carpenter wrote:
> Here "temp" is the number of characters that we have written and "size"
> is the size of the buffer. The intent was clearly to say that if we have
> written to the end of the buffer then stop.
>
> However, for that to work the comparison should have been done on the
> original "size" value instead of the "size -= temp" value. Not only
> will that not trigger when we want to, but there is a small chance that
> it will trigger incorrectly before we want it to and we break from the
> loop slightly earlier than intended.
>
> This code was recently changed from using snprintf() to scnprintf(). With
> snprintf() we likely would have continued looping and passed a negative
> size parameter to snprintf(). This would have triggered an annoying
> WARN(). Now that we have converted to scnprintf() "size" will never
> drop below 1 and there is no real need for this test. We could change
> the condition to "if (temp <= 1) goto done;" but just deleting the test
> is cleanest.
>
> Fixes: 1dd33a9f1b95 ("usb: fotg210: Collect pieces of dual mode controller")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> drivers/usb/fotg210/fotg210-hcd.c | 3 ---
> 1 file changed, 3 deletions(-)
Super additional clean-up, thanks.
Reviewed-by: Lee Jones <lee@kernel.org>
> diff --git a/drivers/usb/fotg210/fotg210-hcd.c b/drivers/usb/fotg210/fotg210-hcd.c
> index b2f8b53cc8ef..8c5aaf860635 100644
> --- a/drivers/usb/fotg210/fotg210-hcd.c
> +++ b/drivers/usb/fotg210/fotg210-hcd.c
> @@ -426,8 +426,6 @@ static void qh_lines(struct fotg210_hcd *fotg210, struct fotg210_qh *qh,
> td->urb);
> size -= temp;
> next += temp;
> - if (temp == size)
> - goto done;
> }
>
> temp = scnprintf(next, size, "\n");
> @@ -435,7 +433,6 @@ static void qh_lines(struct fotg210_hcd *fotg210, struct fotg210_qh *qh,
> size -= temp;
> next += temp;
>
> -done:
> *sizep = size;
> *nextp = next;
> }
> --
> 2.42.0
>
--
Lee Jones [李琼斯]
prev parent reply other threads:[~2023-12-13 11:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-08 9:23 [PATCH] usb: fotg210-hcd: delete an incorrect bounds test Dan Carpenter
2023-12-10 19:46 ` Linus Walleij
2023-12-13 11:49 ` Lee Jones [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231213114906.GL111411@google.com \
--to=lee@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox