All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Roskin <proski@gnu.org>
To: The development of GRUB 2 <grub-devel@gnu.org>
Cc: Bean <bean123ch@gmail.com>
Subject: [PATCH] Warning fix in raid6_recover
Date: Tue, 05 May 2009 18:46:27 -0400	[thread overview]
Message-ID: <1241563587.2871.69.camel@mj> (raw)

Hello!

This is an fix for this warning:

disk/raid6_recover.c: In function 'grub_raid6_recover':
disk/raid6_recover.c:95: warning: 'err[1]' may be used uninitialized in this function
disk/raid6_recover.c:95: warning: 'err[0]' may be used uninitialized in this function

The warning about err[0] appears to be legitimate.  For some values of
disknr err[0] will never be set.  Namely, it will happen if disknr is
equal p or p+1, for negative disknr and for disknr being more or equal
array->total_devs.  It's better to have a check for that case.

The warning about err[1] is incorrect and can be easily eliminated once
we realize that err[nerr++] is always err[1].

Since both err[0] and err[1] are only assigned positive values, we can
initialize them with -1.  This would also eliminate nerr, as we can
check err[1] instead.

It would be great to give better names to most variables.  err[0] and
err[1] could become separate variables.  There is no need for them to be
an array.  And they are not error codes, despite what their names imply.
Unfortunately, I'm not familiar enough with RAID6 to suggest better
names.

ChangeLog:
	* disk/raid6_recover.c (grub_raid6_recover): Fix warnings about
	uninitialized err[0] and err[1].  Initialize them with -1.  Add
	sanity check for err[0].  Eliminate nerr variable.

Index: disk/raid6_recover.c
===================================================================
--- disk/raid6_recover.c	(revision 2191)
+++ disk/raid6_recover.c	(working copy)
@@ -92,7 +92,7 @@
                     char *buf, grub_disk_addr_t sector, int size)
 {
   int i, q, pos;
-  int err[2], nerr;
+  int err[2] = { -1, -1 };
   char *pbuf = 0, *qbuf = 0;
 
   size <<= GRUB_DISK_SECTOR_BITS;
@@ -115,7 +115,6 @@
   if (pos == (int) array->total_devs)
     pos = 0;
 
-  nerr = 1;
   for (i = 0; i < (int) array->total_devs - 2; i++)
     {
       if (pos == disknr)
@@ -131,10 +130,11 @@
             }
           else
             {
-              if (nerr >= 2)
+              /* Too many bad devices */
+              if (err[1] >= 0)
                 goto quit;
 
-              err[nerr++] = i;
+              err[1] = i;
               grub_errno = GRUB_ERR_NONE;
             }
         }
@@ -144,8 +144,13 @@
         pos = 0;
     }
 
-  if (nerr == 1)
+  /* Invalid disknr or p */
+  if (err[0] < 0)
+    goto quit;
+
+  if (err[1] < 0)
     {
+      /* One bad device */
       if ((array->device[p]) &&
           (! grub_disk_read (array->device[p], sector, 0, size, buf)))
         {
@@ -169,6 +174,7 @@
     }
   else
     {
+      /* Two bad devices */
       grub_uint8_t c;
 
       if ((! array->device[p]) || (! array->device[q]))


-- 
Regards,
Pavel Roskin



                 reply	other threads:[~2009-05-05 22:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1241563587.2871.69.camel@mj \
    --to=proski@gnu.org \
    --cc=bean123ch@gmail.com \
    --cc=grub-devel@gnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.