From: Ian Campbell Subject: Re: [PATCH] only use legitimate shift counts in bitmap shifting Date: Wed, 23 Apr 2014 10:01:15 +0100 Message-ID: <1398243675.4880.112.camel@kazak.uk.xensource.com> References: <53577EC9020000780000B223@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Wct3P-00065a-SF for xen-devel@lists.xenproject.org; Wed, 23 Apr 2014 09:01:20 +0000 In-Reply-To: <53577EC9020000780000B223@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich Cc: xen-devel , Keir Fraser , Ian Jackson , Tim Deegan List-Id: xen-devel@lists.xenproject.org On Wed, 2014-04-23 at 07:50 +0100, Jan Beulich wrote: > An alternative would be to remove these implicitly unused functions. Why "implicitly"? Looks like we got this file from Linux, which I suppose is a reason to keep it intact even if we aren't using these particular functions. It does look like the same fix applies to Linux though. Can you be explicit about which thing is illegitimate? I have inferred it is when rem == 0, which leads to "upper << BITS_PER_LONG"? If you make that clear in the commit message then: Acked-by: Ian Campbell > > Coverity ID 1192174 (__bitmap_shift_right) > Coverity ID 1192175 (__bitmap_shift_left) > > Signed-off-by: Jan Beulich > > --- a/xen/common/bitmap.c > +++ b/xen/common/bitmap.c > @@ -144,7 +144,9 @@ void __bitmap_shift_right(unsigned long > lower = src[off + k]; > if (left && off + k == lim - 1) > lower &= mask; > - dst[k] = upper << (BITS_PER_LONG - rem) | lower >> rem; > + dst[k] = rem > + ? (upper << (BITS_PER_LONG - rem)) | (lower >> rem) > + : lower; > if (left && k == lim - 1) > dst[k] &= mask; > } > @@ -185,7 +187,9 @@ void __bitmap_shift_left(unsigned long * > upper = src[k]; > if (left && k == lim - 1) > upper &= (1UL << left) - 1; > - dst[k + off] = lower >> (BITS_PER_LONG - rem) | upper << rem; > + dst[k + off] = rem ? (lower >> (BITS_PER_LONG - rem)) > + | (upper << rem) > + : upper; > if (left && k + off == lim - 1) > dst[k + off] &= (1UL << left) - 1; > } > > >