Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0b49ec37 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Jesse Barnes
Browse files

PCI/MSI: fix msi_mask() shift fix



Hidetoshi Seto points out that commit
bffac3c5 has wrong values in the array.
Rather than correct the array, we can just use a bounds check and
perform the calculation specified in the comment.  As a bonus, this will
not run off the end of the array if the device specifies an illegal
value in the MSI capability.

Signed-off-by: default avatarMatthew Wilcox <willy@linux.intel.com>
Signed-off-by: default avatarHidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent 37bed900
Loading
Loading
Loading
Loading
+4 −6
Original line number Original line Diff line number Diff line
@@ -103,14 +103,12 @@ static void msix_set_enable(struct pci_dev *dev, int enable)
	}
	}
}
}


/*
 * Essentially, this is ((1 << (1 << x)) - 1), but without the
 * undefinedness of a << 32.
 */
static inline __attribute_const__ u32 msi_mask(unsigned x)
static inline __attribute_const__ u32 msi_mask(unsigned x)
{
{
	static const u32 mask[] = { 1, 2, 4, 0xf, 0xff, 0xffff, 0xffffffff };
	/* Don't shift by >= width of type */
	return mask[x];
	if (x >= 5)
		return 0xffffffff;
	return (1 << (1 << x)) - 1;
}
}


static void msix_flush_writes(struct irq_desc *desc)
static void msix_flush_writes(struct irq_desc *desc)