Commit ee4fccbe authored by Kees Cook's avatar Kees Cook Committed by David S. Miller

net/ibm/emac: Remove VLA usage

In the quest to remove all stack VLA usage from the kernel[1], this
removes the VLA used for the emac xaht registers size. Since the size
of registers can only ever be 4 or 8, as detected in emac_init_config(),
the max can be hardcoded and a runtime test added for robustness.

[1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.com

Cc: "David S. Miller" <davem@davemloft.net>
Cc: Christian Lamparter <chunkeey@gmail.com>
Cc: Ivan Mikhaylov <ivan@de.ibm.com>
Cc: netdev@vger.kernel.org
Co-developed-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f91845da
...@@ -423,7 +423,7 @@ static void emac_hash_mc(struct emac_instance *dev) ...@@ -423,7 +423,7 @@ static void emac_hash_mc(struct emac_instance *dev)
{ {
const int regs = EMAC_XAHT_REGS(dev); const int regs = EMAC_XAHT_REGS(dev);
u32 *gaht_base = emac_gaht_base(dev); u32 *gaht_base = emac_gaht_base(dev);
u32 gaht_temp[regs]; u32 gaht_temp[EMAC_XAHT_MAX_REGS];
struct netdev_hw_addr *ha; struct netdev_hw_addr *ha;
int i; int i;
...@@ -2964,6 +2964,10 @@ static int emac_init_config(struct emac_instance *dev) ...@@ -2964,6 +2964,10 @@ static int emac_init_config(struct emac_instance *dev)
dev->xaht_width_shift = EMAC4_XAHT_WIDTH_SHIFT; dev->xaht_width_shift = EMAC4_XAHT_WIDTH_SHIFT;
} }
/* This should never happen */
if (WARN_ON(EMAC_XAHT_REGS(dev) > EMAC_XAHT_MAX_REGS))
return -ENXIO;
DBG(dev, "features : 0x%08x / 0x%08x\n", dev->features, EMAC_FTRS_POSSIBLE); DBG(dev, "features : 0x%08x / 0x%08x\n", dev->features, EMAC_FTRS_POSSIBLE);
DBG(dev, "tx_fifo_size : %d (%d gige)\n", dev->tx_fifo_size, dev->tx_fifo_size_gige); DBG(dev, "tx_fifo_size : %d (%d gige)\n", dev->tx_fifo_size, dev->tx_fifo_size_gige);
DBG(dev, "rx_fifo_size : %d (%d gige)\n", dev->rx_fifo_size, dev->rx_fifo_size_gige); DBG(dev, "rx_fifo_size : %d (%d gige)\n", dev->rx_fifo_size, dev->rx_fifo_size_gige);
......
...@@ -390,6 +390,9 @@ static inline int emac_has_feature(struct emac_instance *dev, ...@@ -390,6 +390,9 @@ static inline int emac_has_feature(struct emac_instance *dev,
#define EMAC4SYNC_XAHT_SLOTS_SHIFT 8 #define EMAC4SYNC_XAHT_SLOTS_SHIFT 8
#define EMAC4SYNC_XAHT_WIDTH_SHIFT 5 #define EMAC4SYNC_XAHT_WIDTH_SHIFT 5
/* The largest span between slots and widths above is 3 */
#define EMAC_XAHT_MAX_REGS (1 << 3)
#define EMAC_XAHT_SLOTS(dev) (1 << (dev)->xaht_slots_shift) #define EMAC_XAHT_SLOTS(dev) (1 << (dev)->xaht_slots_shift)
#define EMAC_XAHT_WIDTH(dev) (1 << (dev)->xaht_width_shift) #define EMAC_XAHT_WIDTH(dev) (1 << (dev)->xaht_width_shift)
#define EMAC_XAHT_REGS(dev) (1 << ((dev)->xaht_slots_shift - \ #define EMAC_XAHT_REGS(dev) (1 << ((dev)->xaht_slots_shift - \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment