lkml.org 
[lkml]   [2012]   [May]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [patch] iommu: off by one in dmar_get_fault_reason()
On Sat, May 12, 2012 at 02:36:42PM +0200, walter harms wrote:
>
>
> Am 12.05.2012 12:59, schrieb Dan Carpenter:
> > fault_reason == ARRAY_SIZE(irq_remap_fault_reasons) + 0x20 - 0x20 is one
> > past the end of the array.
> >
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> >
> > diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
> > index 5ef65cf..9390f3f 100644
> > --- a/drivers/iommu/dmar.c
> > +++ b/drivers/iommu/dmar.c
> > @@ -1057,7 +1057,7 @@ static const char *irq_remap_fault_reasons[] =
> >
> > const char *dmar_get_fault_reason(u8 fault_reason, int *fault_type)
> > {
> > - if (fault_reason >= 0x20 && (fault_reason <= 0x20 +
> > + if (fault_reason >= 0x20 && (fault_reason < 0x20 +
> > ARRAY_SIZE(irq_remap_fault_reasons))) {
> > *fault_type = INTR_REMAP;
> > return irq_remap_fault_reasons[fault_reason - 0x20];
>
> perhaps this is more readable:
> if (fault_reason >= 0x20 && (fault_reason - 0x20 < ARRAY_SIZE(irq_remap_fault_reasons)))
>

Yeah. Probably you're way is nicer.

regards,
dan carpenter



\
 
 \ /
  Last update: 2012-05-13 19:41    [from the cache]
©2003-2011 Jasper Spaans