]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net/ibm/emac: Remove VLA usage
authorKees Cook <keescook@chromium.org>
Thu, 13 Sep 2018 21:23:56 +0000 (14:23 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 13 Sep 2018 23:53:24 +0000 (16:53 -0700)
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>
drivers/net/ethernet/ibm/emac/core.c
drivers/net/ethernet/ibm/emac/core.h

index 3726646863095dc145e8df1ccc5d082f9fd802bd..7410a1de8f1d45c2e7b98851c21efdb109cad6c8 100644 (file)
@@ -423,7 +423,7 @@ static void emac_hash_mc(struct emac_instance *dev)
 {
        const int regs = EMAC_XAHT_REGS(dev);
        u32 *gaht_base = emac_gaht_base(dev);
-       u32 gaht_temp[regs];
+       u32 gaht_temp[EMAC_XAHT_MAX_REGS];
        struct netdev_hw_addr *ha;
        int i;
 
@@ -2964,6 +2964,10 @@ static int emac_init_config(struct emac_instance *dev)
                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, "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);
index 369de2cfb15bad65010dfd77ae59023f7cc0654c..84caa4a3fc52c103f52cb0b47e8f897ea262f026 100644 (file)
@@ -390,6 +390,9 @@ static inline int emac_has_feature(struct emac_instance *dev,
 #define        EMAC4SYNC_XAHT_SLOTS_SHIFT      8
 #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_WIDTH(dev)            (1 << (dev)->xaht_width_shift)
 #define        EMAC_XAHT_REGS(dev)             (1 << ((dev)->xaht_slots_shift - \