mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: "barebox@lists.infradead.org" <barebox@lists.infradead.org>
Subject: Re: [PATCH] firmware: socfpga: Fix a bug in fpgamgr_program_write_buf()
Date: Tue, 14 Apr 2015 12:46:26 -0700	[thread overview]
Message-ID: <CAHQ1cqE5HqKvOzMia1JjjLNjgS7hgNSZxHR2ikDB+F9uv+7qRw@mail.gmail.com> (raw)
In-Reply-To: <20150414184631.GD9742@pengutronix.de>

On Tue, Apr 14, 2015 at 11:46 AM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> Hi Andrey,
>
> On Mon, Apr 13, 2015 at 05:11:50AM -0700, Andrey Smirnov wrote:
>> Fix a bug in fpgamgr_program_write_buf() where .rbf file whose length
>> is not a multiple of 4 would cause an integer overflow which would
>> result in infinite loop.
>>
>> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
>> ---
>>  drivers/firmware/socfpga.c | 26 ++++++++++++++++++++++----
>>  1 file changed, 22 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/firmware/socfpga.c b/drivers/firmware/socfpga.c
>> index a5dc607..75fb050 100644
>> --- a/drivers/firmware/socfpga.c
>> +++ b/drivers/firmware/socfpga.c
>> @@ -321,14 +321,32 @@ static int fpgamgr_program_write_buf(struct firmware_handler *fh, const void *bu
>>               size_t size)
>>  {
>>       struct fpgamgr *mgr = container_of(fh, struct fpgamgr, fh);
>> -     const uint32_t *buf32 = buf;
>> +     const uint8_t *buffer = buf;
>> +     uint32_t word;
>> +     size_t chunk_size;
>> +     size_t offset = 0;
>>
>>       /* write to FPGA Manager AXI data */
>>       while (size) {
>
> This code probably looks better when you change this loop to
> while (size >= sizeof(uint32_t)){} followed by a if (size) {}

Yeah, I agree. I'll update it in the next version of the patch.

>
>> -             writel(*buf32, mgr->regs_data);
>> +             chunk_size = min(size, sizeof(uint32_t));
>> +             size -= chunk_size;
>> +
>> +             if (likely(chunk_size == sizeof(uint32_t))) {
>> +                     word = *(uint32_t *)(buffer + offset);
>> +                     offset += sizeof(uint32_t);
>> +             } else {
>> +                     word = buffer[offset++];
>> +                     word <<= 8;
>> +                     chunk_size--;
>> +
>> +                     while (chunk_size--) {
>> +                             word |= buffer[offset++];
>> +                             word <<= 8;
>> +                     }
>
> Isn't this the same as:
>
>                         word = 0;
>                         while (chunk_size--) {
>                                 word |= buffer[offset++];
>                                 word <<= 8;
>                         }
>

That's how I originally wrote it, but then the "unnecessary"
assignment to zero started to bother me for some reason and I
un-rolled one iteration of the loop. I can change it back in the next
version of the patch


>
> Sascha
>
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      reply	other threads:[~2015-04-14 19:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-13 12:11 Andrey Smirnov
2015-04-14 18:46 ` Sascha Hauer
2015-04-14 19:46   ` Andrey Smirnov [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=CAHQ1cqE5HqKvOzMia1JjjLNjgS7hgNSZxHR2ikDB+F9uv+7qRw@mail.gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /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