From: Michal Nazarewicz <mina86@mina86.com>
To: kernel-janitors@vger.kernel.org
Subject: Re: [patch] usb: f_fs: off by one bug in _ffs_func_bind()
Date: Fri, 27 May 2016 12:23:09 +0000 [thread overview]
Message-ID: <xa1t8tyvpu4y.fsf@mina86.com> (raw)
In-Reply-To: <20160527112311.GC3255@mwanda>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="windows-1254", Size: 2053 bytes --]
On Fri, May 27 2016, Dan Carpenter wrote:
> This loop is supposed to set all the .num values to -1 but it's doesn't
> set the first element and it sets one element beyond the end of the
> array. Really there is no reason for it to be done backwards. And
> "ret" is the wrong variable to use for an iterator.
>
> Fixes: ddf8abd25994 ('USB: f_fs: the FunctionFS driver')
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Michal Nazarewicz <mina86@mina86.com>
How on Earth could I have made that mistake is beyond my
comprehension. O_o On second thought, things being beyond one’s
comprehension is probably how bugs are introduced…
> ---
> I just spotted this reviewing the code, I have not tested it. Please
> review carefully, the vla_ptr() macro is difficult to understand.
Yeah. In retrospect I’m not sure savings in memory those macros bring
offset time engineers spent trying to understand them. Damn you clang!
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index 73515d5..7fff81a 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -2777,11 +2777,11 @@ static int _ffs_func_bind(struct usb_configuration *c,
> ffs->raw_descs_length);
>
> memset(vla_ptr(vlabuf, d, inums), 0xff, d_inums__sz);
> - for (ret = ffs->eps_count; ret; --ret) {
> + for (i = 0; i < ffs->eps_count; i++) {
> struct ffs_ep *ptr;
>
> ptr = vla_ptr(vlabuf, d, eps);
As pointed by Walter, this could be moved outside. Maybe
i = ffs->eps_count;
for (struct ffs_ep *ptr = vla_ptr(vlabuf, d, eps); i; ++ptr, --i)
ptr->num = -1;
> - ptr[ret].num = -1;
> + ptr[i].num = -1;
> }
>
> /* Save pointers
--
Best regards
ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ
«If at first you don’t succeed, give up skydiving»
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2016-05-27 12:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-27 11:23 [patch] usb: f_fs: off by one bug in _ffs_func_bind() Dan Carpenter
2016-05-27 11:45 ` walter harms
2016-05-27 12:23 ` Michal Nazarewicz [this message]
2016-05-27 17:25 ` walter harms
2016-05-28 4:46 ` Dan Carpenter
2016-05-28 4:48 ` [patch v2] " Dan Carpenter
2016-05-28 9:05 ` walter harms
2016-05-28 10:16 ` Michal Nazarewicz
2016-05-28 10:15 ` [patch] " Michal Nazarewicz
2016-05-28 10:53 ` Dan Carpenter
2016-05-28 11:05 ` Dan Carpenter
2016-05-28 12:01 ` Michal Nazarewicz
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=xa1t8tyvpu4y.fsf@mina86.com \
--to=mina86@mina86.com \
--cc=kernel-janitors@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