Re: [GIT PULL] block drivers for 2.6.39-rc

From: Linus Torvalds
Date: Mon Mar 28 2011 - 19:07:51 EST


On Sat, Mar 26, 2011 at 11:56 AM, Jens Axboe <jaxboe@xxxxxxxxxxxx> wrote:
> Hi Linus,
>
> This is the pull request for the block driver updates for 2.6.39. Two
> things here:
>
> - Big drbd update, as per usual...
> - cciss update.

Btw, that cciss thing causes a very annoying compiler warning:

drivers/block/cciss.c: In function ‘dev_show_unique_id’:
drivers/block/cciss.c:617:7: warning: ‘sn[0]’ may be used
uninitialized in this function
drivers/block/cciss.c:617:7: warning: ‘sn[1]’ may be used
uninitialized in this function
drivers/block/cciss.c:617:7: warning: ‘sn[2]’ may be used
uninitialized in this function
drivers/block/cciss.c:617:7: warning: ‘sn[3]’ may be used
uninitialized in this function
drivers/block/cciss.c:617:7: warning: ‘sn[4]’ may be used
uninitialized in this function
drivers/block/cciss.c:617:7: warning: ‘sn[5]’ may be used
uninitialized in this function
drivers/block/cciss.c:617:7: warning: ‘sn[6]’ may be used
uninitialized in this function
drivers/block/cciss.c:617:7: warning: ‘sn[7]’ may be used
uninitialized in this function
drivers/block/cciss.c:617:7: warning: ‘sn[8]’ may be used
uninitialized in this function
drivers/block/cciss.c:617:7: warning: ‘sn[9]’ may be used
uninitialized in this function
drivers/block/cciss.c:617:7: warning: ‘sn[10]’ may be used
uninitialized in this function
drivers/block/cciss.c:617:7: warning: ‘sn[11]’ may be used
uninitialized in this function
drivers/block/cciss.c:617:7: warning: ‘sn[12]’ may be used
uninitialized in this function
drivers/block/cciss.c:617:7: warning: ‘sn[13]’ may be used
uninitialized in this function
drivers/block/cciss.c:617:7: warning: ‘sn[14]’ may be used
uninitialized in this function
drivers/block/cciss.c:617:7: warning: ‘sn[15]’ may be used
uninitialized in this function

which is because the compiler doesn't really notice that those things
are only used if the error return isn't being set.

So it's a compiler mis-feature, but the thing is, the warning could
easily be avoided by just writing the code more prettily.

Just do the memcpy() unconditionally: we know that 'drv' is a valid
pointer (we just loaded 'h' off it), and we're talking about a nice
constant 16-byte copy.

IOW, a patch something like the attached.

Untested, but it looks really obvious. Hmm?

Linus
drivers/block/cciss.c | 19 +++++++++----------
1 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 9bf1398..ec69f0c 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -619,22 +619,21 @@ static ssize_t dev_show_unique_id(struct device *dev,
int ret = 0;

spin_lock_irqsave(&h->lock, flags);
+ memcpy(sn, drv->serial_no, sizeof(sn));
if (h->busy_configuring)
ret = -EBUSY;
- else
- memcpy(sn, drv->serial_no, sizeof(sn));
spin_unlock_irqrestore(&h->lock, flags);

if (ret)
return ret;
- else
- return snprintf(buf, 16 * 2 + 2,
- "%02X%02X%02X%02X%02X%02X%02X%02X"
- "%02X%02X%02X%02X%02X%02X%02X%02X\n",
- sn[0], sn[1], sn[2], sn[3],
- sn[4], sn[5], sn[6], sn[7],
- sn[8], sn[9], sn[10], sn[11],
- sn[12], sn[13], sn[14], sn[15]);
+
+ return snprintf(buf, 16 * 2 + 2,
+ "%02X%02X%02X%02X%02X%02X%02X%02X"
+ "%02X%02X%02X%02X%02X%02X%02X%02X\n",
+ sn[0], sn[1], sn[2], sn[3],
+ sn[4], sn[5], sn[6], sn[7],
+ sn[8], sn[9], sn[10], sn[11],
+ sn[12], sn[13], sn[14], sn[15]);
}
static DEVICE_ATTR(unique_id, S_IRUGO, dev_show_unique_id, NULL);