diff options
author | Marek BehĂșn <kabel@kernel.org> | 2024-08-31 12:20:35 +0300 |
---|---|---|
committer | Arnd Bergmann <arnd@arndb.de> | 2024-09-02 12:41:56 +0300 |
commit | 29d258542f900a55791ec2ca8b15e4f9da083a14 (patch) | |
tree | 0f9f8a97e75855953c7e79d469c55a10cb8ac82c /drivers/firmware | |
parent | 47ac09b91befbb6a235ab620c32af719f8208399 (diff) | |
download | linux-29d258542f900a55791ec2ca8b15e4f9da083a14.tar.xz |
firmware: turris-mox-rwtm: Use macro constant instead of hardcoded 4096
The 4096 bytes limit in mox_hwrng_read() is due to the DMA buffer being
allocated to one PAGE_SIZE bytes. Use new local macro constant
RWTM_DMA_BUFFER_SIZE at allocation time and when used in mox_hwrng_read().
Use SZ_4K instead of PAGE_SIZE. Although PAGE_SIZE is never set to a
larger value on Armada 3720, it theoretically could, and this would be a
waste of space.
Signed-off-by: Marek BehĂșn <kabel@kernel.org>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Link: https://lore.kernel.org/r/20240831092050.23093-2-kabel@kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Diffstat (limited to 'drivers/firmware')
-rw-r--r-- | drivers/firmware/turris-mox-rwtm.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c index 3e7f186d239a..67d7b65da174 100644 --- a/drivers/firmware/turris-mox-rwtm.c +++ b/drivers/firmware/turris-mox-rwtm.c @@ -11,14 +11,18 @@ #include <linux/dma-mapping.h> #include <linux/hw_random.h> #include <linux/mailbox_client.h> +#include <linux/minmax.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/of.h> #include <linux/platform_device.h> +#include <linux/sizes.h> #include <linux/slab.h> #define DRIVER_NAME "turris-mox-rwtm" +#define RWTM_DMA_BUFFER_SIZE SZ_4K + /* * The macros and constants below come from Turris Mox's rWTM firmware code. * This firmware is open source and it's sources can be found at @@ -287,8 +291,7 @@ static int mox_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait) struct armada_37xx_rwtm_tx_msg msg; int ret; - if (max > 4096) - max = 4096; + max = min(max, RWTM_DMA_BUFFER_SIZE); msg.command = MBOX_CMD_GET_RANDOM; msg.args[0] = 1; @@ -479,8 +482,8 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) return -ENOMEM; rwtm->dev = dev; - rwtm->buf = dmam_alloc_coherent(dev, PAGE_SIZE, &rwtm->buf_phys, - GFP_KERNEL); + rwtm->buf = dmam_alloc_coherent(dev, RWTM_DMA_BUFFER_SIZE, + &rwtm->buf_phys, GFP_KERNEL); if (!rwtm->buf) return -ENOMEM; |