Commit 0b49ec37a20bc7eb7178105aadaa8d1ecba825f8
Committed by
Jesse Barnes
1 parent
37bed90094
Exists in
master
and in
7 other branches
PCI/MSI: fix msi_mask() shift fix
Hidetoshi Seto points out that commit bffac3c593eba1f9da3efd0199e49ea6558a40ce 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: Matthew Wilcox <willy@linux.intel.com> Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Showing 1 changed file with 4 additions and 6 deletions Side-by-side Diff
drivers/pci/msi.c
... | ... | @@ -103,14 +103,12 @@ |
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | -/* | |
107 | - * Essentially, this is ((1 << (1 << x)) - 1), but without the | |
108 | - * undefinedness of a << 32. | |
109 | - */ | |
110 | 106 | static inline __attribute_const__ u32 msi_mask(unsigned x) |
111 | 107 | { |
112 | - static const u32 mask[] = { 1, 2, 4, 0xf, 0xff, 0xffff, 0xffffffff }; | |
113 | - return mask[x]; | |
108 | + /* Don't shift by >= width of type */ | |
109 | + if (x >= 5) | |
110 | + return 0xffffffff; | |
111 | + return (1 << (1 << x)) - 1; | |
114 | 112 | } |
115 | 113 | |
116 | 114 | static void msix_flush_writes(struct irq_desc *desc) |