summaryrefslogtreecommitdiffstats
path: root/drivers/net/ipa/ipa_table.c
diff options
context:
space:
mode:
authorAlex Elder <elder@linaro.org>2021-03-22 20:05:05 -0500
committerDavid S. Miller <davem@davemloft.net>2021-03-23 17:15:23 -0700
commit437c78f976f5b39fc4b2a1c65903a229f55912dd (patch)
treea37b648b0968bcdb419dd4e6c8ad33adb53ed45e /drivers/net/ipa/ipa_table.c
parented97143e00982e1cab3544977f33b94a6de2e6fa (diff)
downloadlinux-437c78f976f5b39fc4b2a1c65903a229f55912dd.tar.bz2
net: ipa: avoid 64-bit modulus
It is possible for a 32 bit x86 build to use a 64 bit DMA address. There are two remaining spots where the IPA driver does a modulo operation to check alignment of a DMA address, and under certain conditions this can lead to a build error on i386 (at least). The alignment checks we're doing are for power-of-2 values, and this means the lower 32 bits of the DMA address can be used. This ensures both operands to the modulo operator are 32 bits wide. Reported-by: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Alex Elder <elder@linaro.org> Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ipa/ipa_table.c')
-rw-r--r--drivers/net/ipa/ipa_table.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/drivers/net/ipa/ipa_table.c b/drivers/net/ipa/ipa_table.c
index 988f2c2886b9..4236a50ff03a 100644
--- a/drivers/net/ipa/ipa_table.c
+++ b/drivers/net/ipa/ipa_table.c
@@ -658,10 +658,13 @@ int ipa_table_init(struct ipa *ipa)
return -ENOMEM;
/* We put the "zero rule" at the base of our table area. The IPA
- * hardware requires rules to be aligned on a 128-byte boundary.
- * Make sure the allocation satisfies this constraint.
+ * hardware requires route and filter table rules to be aligned
+ * on a 128-byte boundary. As long as the alignment constraint
+ * is a power of 2, we can check alignment using just the bottom
+ * 32 bits for a DMA address of any size.
*/
- if (addr % IPA_TABLE_ALIGN) {
+ BUILD_BUG_ON(!is_power_of_2(IPA_TABLE_ALIGN));
+ if (lower_32_bits(addr) % IPA_TABLE_ALIGN) {
dev_err(dev, "table address %pad not %u-byte aligned\n",
&addr, IPA_TABLE_ALIGN);
dma_free_coherent(dev, size, virt, addr);