Skip to content

Commit ee4fccb

Browse files
keesdavem330
authored andcommitted
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: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f91845d commit ee4fccb

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎drivers/net/ethernet/ibm/emac/core.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ static void emac_hash_mc(struct emac_instance *dev)
423423
{
424424
const int regs = EMAC_XAHT_REGS(dev);
425425
u32 *gaht_base = emac_gaht_base(dev);
426-
u32 gaht_temp[regs];
426+
u32 gaht_temp[EMAC_XAHT_MAX_REGS];
427427
struct netdev_hw_addr *ha;
428428
int i;
429429

@@ -2964,6 +2964,10 @@ static int emac_init_config(struct emac_instance *dev)
29642964
dev->xaht_width_shift = EMAC4_XAHT_WIDTH_SHIFT;
29652965
}
29662966

2967+
/* This should never happen */
2968+
if (WARN_ON(EMAC_XAHT_REGS(dev) > EMAC_XAHT_MAX_REGS))
2969+
return -ENXIO;
2970+
29672971
DBG(dev, "features : 0x%08x / 0x%08x\n", dev->features, EMAC_FTRS_POSSIBLE);
29682972
DBG(dev, "tx_fifo_size : %d (%d gige)\n", dev->tx_fifo_size, dev->tx_fifo_size_gige);
29692973
DBG(dev, "rx_fifo_size : %d (%d gige)\n", dev->rx_fifo_size, dev->rx_fifo_size_gige);

‎drivers/net/ethernet/ibm/emac/core.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ static inline int emac_has_feature(struct emac_instance *dev,
390390
#define EMAC4SYNC_XAHT_SLOTS_SHIFT 8
391391
#define EMAC4SYNC_XAHT_WIDTH_SHIFT 5
392392

393+
/* The largest span between slots and widths above is 3 */
394+
#define EMAC_XAHT_MAX_REGS (1 << 3)
395+
393396
#define EMAC_XAHT_SLOTS(dev) (1 << (dev)->xaht_slots_shift)
394397
#define EMAC_XAHT_WIDTH(dev) (1 << (dev)->xaht_width_shift)
395398
#define EMAC_XAHT_REGS(dev) (1 << ((dev)->xaht_slots_shift - \

0 commit comments

Comments
 (0)