[U-Boot] [PATCH] squash build warning in cmd_sf.c
Prabhakar Lad
prabhakar.csengg at gmail.com
Wed Oct 5 06:46:55 CEST 2011
Hi Simon
On Tue, Oct 4, 2011 at 8:45 PM, Simon Glass <sjg at chromium.org> wrote:
> Hi,
>
> On Tue, Oct 4, 2011 at 4:45 AM, <prabhakar.csengg at gmail.com> wrote:
> > From: Prabhakar Lad <prabhakar.csengg at gmail.com>
> >
> > Fix build warning and returning early in case of failure
> >
> > cmd_sf.c: In function 'do_spi_flash':
> > cmd_sf.c:164: warning: 'skipped' may be used uninitialized in this
> function
> > cmd_sf.c:164: note: 'skipped' was declared here
> >
> > Signed-off-by: Prabhakar Lad <prabhakar.csengg at gmail.com>
> > ---
> > common/cmd_sf.c | 20 +++++++++-----------
> > 1 files changed, 9 insertions(+), 11 deletions(-)
> >
> > diff --git a/common/cmd_sf.c b/common/cmd_sf.c
> > index c8c547a..bdf7915 100644
> > --- a/common/cmd_sf.c
> > +++ b/common/cmd_sf.c
> > @@ -164,21 +164,19 @@ static int spi_flash_update(struct spi_flash
> *flash, u32 offset,
> > size_t skipped; /* statistics */
> >
> > cmp_buf = malloc(flash->sector_size);
> > - if (cmp_buf) {
> > - for (skipped = 0; buf < end && !err_oper;
> > - buf += todo, offset += todo) {
> > - todo = min(end - buf, flash->sector_size);
> > - err_oper = spi_flash_update_block(flash, offset,
> todo,
> > - buf, cmp_buf, &skipped);
> > - }
> > - } else {
> > + if (!cmp_buf) {
> > err_oper = "malloc";
> > - }
> > - free(cmp_buf);
> > - if (err_oper) {
> > printf("SPI flash failed in %s step\n", err_oper);
> > return 1;
> > }
> > +
> > + for (skipped = 0; buf < end && !err_oper;
> > + buf += todo, offset += todo) {
> > + todo = min(end - buf, flash->sector_size);
> > + err_oper = spi_flash_update_block(flash, offset, todo,
> > + buf, cmp_buf, &skipped);
> > + }
> > + free(cmp_buf);
>
> Sorry my previous comment was in the wrong place. My comment was that
> here err_oper might be set, but the printf() that uses it is above it!
>
> if the err_oper is set in the loop why isn't it checked in loop each
time
why is it that it is only checked for the last index? Is that a loophole??
Regards
-- Prabhakar Lad
> Regards,
> Simon
>
> > printf("%zu bytes written, %zu bytes skipped\n", len - skipped,
> > skipped);
> > return 0;
> > --
> > 1.7.0.4
> >
> > _______________________________________________
> > U-Boot mailing list
> > U-Boot at lists.denx.de
> > http://lists.denx.de/mailman/listinfo/u-boot
> >
>
More information about the U-Boot
mailing list