From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754408Ab0IETXo (ORCPT ); Sun, 5 Sep 2010 15:23:44 -0400 Received: from mail-ey0-f174.google.com ([209.85.215.174]:61727 "EHLO mail-ey0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752211Ab0IETXn (ORCPT ); Sun, 5 Sep 2010 15:23:43 -0400 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent; b=BwFoy9nFt4M4RgiarxA1Zz3Ov8H6G4Vj1SMSoocNuxhlJX2hZB56dP3+7IBOVRAr4z w/SDMjo1FJZDjCt8U15lhM7ChcK3i6XHsw2MlUryAHVJKM++/8Y9ZlUNqCb8o2sI+/z2 zfmNUCTur3dqScmpwMDF+fosJrrlrNnDTuFjQ= Date: Sun, 5 Sep 2010 23:23:35 +0400 From: Kulikov Vasiliy To: Sam Ravnborg Cc: kernel-janitors@vger.kernel.org, Neil Brown , Jens Axboe , linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] md: do not use ++ in rcu_dereference() argument Message-ID: <20100905192335.GA8140@albatros> References: <1283711539-7123-1-git-send-email-segooon@gmail.com> <20100905190139.GA3163@merkur.ravnborg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20100905190139.GA3163@merkur.ravnborg.org> User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Sep 05, 2010 at 21:01 +0200, Sam Ravnborg wrote: > On Sun, Sep 05, 2010 at 10:32:18PM +0400, Kulikov Vasiliy wrote: > > From: Vasiliy Kulikov > > > > rcu_dereference() is macro, so it might use its argument twice. > > Argument must not has side effects. > > > > It was found by compiler warning: > > drivers/md/raid1.c: In function ‘read_balance’: > > drivers/md/raid1.c:445: warning: operation on ‘new_disk’ may be undefined > > This change looks wrong. > In the original implementation new_disk is incremented and > then we do the array lookup. > With your implementation it looks like we increment it after > the array lookup. No, the original code increments new_disk and then dereferences mirrors. The full code: for (rdev = rcu_dereference(conf->mirrors[new_disk].rdev); r1_bio->bios[new_disk] == IO_BLOCKED || !rdev || !test_bit(In_sync, &rdev->flags) || test_bit(WriteMostly, &rdev->flags); rdev = rcu_dereference(conf->mirrors[++new_disk].rdev)) { if (rdev && test_bit(In_sync, &rdev->flags) && r1_bio->bios[new_disk] != IO_BLOCKED) wonly_disk = new_disk; if (new_disk == conf->raid_disks - 1) { new_disk = wonly_disk; break; } } so, for (a; b; c = f(++g)) { ... } == a; while (b) { ... l_continue: c = f(++g); } == a; while (b) { ... l_continue: g++; c = f(g); } == for (a; b; c = f(g)) { ... g++; } Or you mean smth more? -- Vasiliy