Skip to content

Commit 555a05d

Browse files
vladimirolteankuba-moo
authored andcommitted
net: dpaa: avoid on-stack arrays of NR_CPUS elements
The dpaa-eth driver is written for PowerPC and Arm SoCs which have 1-24 CPUs. It depends on CONFIG_NR_CPUS having a reasonably small value in Kconfig. Otherwise, there are 2 functions which allocate on-stack arrays of NR_CPUS elements, and these can quickly explode in size, leading to warnings such as: drivers/net/ethernet/freescale/dpaa/dpaa_eth.c:3280:12: warning: stack frame size (16664) exceeds limit (2048) in 'dpaa_eth_probe' [-Wframe-larger-than] The problem is twofold: - Reducing the array size to the boot-time num_possible_cpus() (rather than the compile-time NR_CPUS) creates a variable-length array, which should be avoided in the Linux kernel. - Using NR_CPUS as an array size makes the driver blow up in stack consumption with generic, as opposed to hand-crafted, .config files. A simple solution is to use dynamic allocation for num_possible_cpus() elements (aka a small number determined at runtime). Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Vladimir Oltean <[email protected]> Reviewed-by: Breno Leitao <[email protected]> Acked-by: Madalin Bucur <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 62fdd17 commit 555a05d

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

drivers/net/ethernet/freescale/dpaa/dpaa_eth.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -931,14 +931,18 @@ static inline void dpaa_setup_egress(const struct dpaa_priv *priv,
931931
}
932932
}
933933

934-
static void dpaa_fq_setup(struct dpaa_priv *priv,
935-
const struct dpaa_fq_cbs *fq_cbs,
936-
struct fman_port *tx_port)
934+
static int dpaa_fq_setup(struct dpaa_priv *priv,
935+
const struct dpaa_fq_cbs *fq_cbs,
936+
struct fman_port *tx_port)
937937
{
938938
int egress_cnt = 0, conf_cnt = 0, num_portals = 0, portal_cnt = 0, cpu;
939939
const cpumask_t *affine_cpus = qman_affine_cpus();
940-
u16 channels[NR_CPUS];
941940
struct dpaa_fq *fq;
941+
u16 *channels;
942+
943+
channels = kcalloc(num_possible_cpus(), sizeof(u16), GFP_KERNEL);
944+
if (!channels)
945+
return -ENOMEM;
942946

943947
for_each_cpu_and(cpu, affine_cpus, cpu_online_mask)
944948
channels[num_portals++] = qman_affine_channel(cpu);
@@ -997,6 +1001,10 @@ static void dpaa_fq_setup(struct dpaa_priv *priv,
9971001
break;
9981002
}
9991003
}
1004+
1005+
kfree(channels);
1006+
1007+
return 0;
10001008
}
10011009

10021010
static inline int dpaa_tx_fq_to_id(const struct dpaa_priv *priv,
@@ -3416,7 +3424,9 @@ static int dpaa_eth_probe(struct platform_device *pdev)
34163424
*/
34173425
dpaa_eth_add_channel(priv->channel, &pdev->dev);
34183426

3419-
dpaa_fq_setup(priv, &dpaa_fq_cbs, priv->mac_dev->port[TX]);
3427+
err = dpaa_fq_setup(priv, &dpaa_fq_cbs, priv->mac_dev->port[TX]);
3428+
if (err)
3429+
goto free_dpaa_bps;
34203430

34213431
/* Create a congestion group for this netdev, with
34223432
* dynamically-allocated CGR ID.

drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,16 @@ static int dpaa_set_coalesce(struct net_device *dev,
457457
struct netlink_ext_ack *extack)
458458
{
459459
const cpumask_t *cpus = qman_affine_cpus();
460-
bool needs_revert[NR_CPUS] = {false};
461460
struct qman_portal *portal;
462461
u32 period, prev_period;
463462
u8 thresh, prev_thresh;
463+
bool *needs_revert;
464464
int cpu, res;
465465

466+
needs_revert = kcalloc(num_possible_cpus(), sizeof(bool), GFP_KERNEL);
467+
if (!needs_revert)
468+
return -ENOMEM;
469+
466470
period = c->rx_coalesce_usecs;
467471
thresh = c->rx_max_coalesced_frames;
468472

@@ -485,6 +489,8 @@ static int dpaa_set_coalesce(struct net_device *dev,
485489
needs_revert[cpu] = true;
486490
}
487491

492+
kfree(needs_revert);
493+
488494
return 0;
489495

490496
revert_values:
@@ -498,6 +504,8 @@ static int dpaa_set_coalesce(struct net_device *dev,
498504
qman_dqrr_set_ithresh(portal, prev_thresh);
499505
}
500506

507+
kfree(needs_revert);
508+
501509
return res;
502510
}
503511

0 commit comments

Comments
 (0)