Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: stmmac: improve ndev->max_mtu setup readability

Improve the readibility of the code setting ndev->max_mtu. This depends
on the hardware specific maximum defined by the MAC core, and also a
platform provided maximum.

The code was originally checking that the platform specific maximum was
between ndev->min_mtu..MAC core maximum before reducing ndev->max_mtu,
otherwise if the platform specific maximum was less than ndev->min_mtu,
issuing a warning.

Re-order the code to handle the case where the platform specific max is
below ndev->min_mtu, which then means that the subsequent test is
simply reducing ndev->max_mtu.

Update the comment, and add a few blank lines to separate the blocks of
code.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://patch.msgid.link/E1vImWA-0000000DrIl-1HZY@rmk-PC.armlinux.org.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Russell King (Oracle) and committed by
Jakub Kicinski
7e975caa 1479493c

+12 -10
+12 -10
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
··· 1392 1392 return NET_SKB_PAD; 1393 1393 } 1394 1394 1395 - static int stmmac_set_bfsize(int mtu, int bufsize) 1395 + static int stmmac_set_bfsize(int mtu) 1396 1396 { 1397 - int ret = bufsize; 1397 + int ret; 1398 1398 1399 1399 if (mtu >= BUF_SIZE_8KiB) 1400 1400 ret = BUF_SIZE_16KiB; ··· 3958 3958 return ERR_PTR(-ENOMEM); 3959 3959 } 3960 3960 3961 + /* Returns 0 or BUF_SIZE_16KiB if mtu > 8KiB and dwmac4 or ring mode */ 3961 3962 bfsize = stmmac_set_16kib_bfsize(priv, mtu); 3962 3963 if (bfsize < 0) 3963 3964 bfsize = 0; 3964 3965 3965 3966 if (bfsize < BUF_SIZE_16KiB) 3966 - bfsize = stmmac_set_bfsize(mtu, 0); 3967 + bfsize = stmmac_set_bfsize(mtu); 3967 3968 3968 3969 dma_conf->dma_buf_sz = bfsize; 3969 3970 /* Chose the tx/rx size from the already defined one in the ··· 7774 7773 7775 7774 /* MTU range: 46 - hw-specific max */ 7776 7775 ndev->min_mtu = ETH_ZLEN - ETH_HLEN; 7776 + 7777 7777 if (priv->plat->core_type == DWMAC_CORE_XGMAC) 7778 7778 ndev->max_mtu = XGMAC_JUMBO_LEN; 7779 - else if ((priv->plat->enh_desc) || (priv->synopsys_id >= DWMAC_CORE_4_00)) 7779 + else if (priv->plat->enh_desc || priv->synopsys_id >= DWMAC_CORE_4_00) 7780 7780 ndev->max_mtu = JUMBO_LEN; 7781 7781 else 7782 7782 ndev->max_mtu = SKB_MAX_HEAD(NET_SKB_PAD + NET_IP_ALIGN); 7783 - /* Will not overwrite ndev->max_mtu if plat->maxmtu > ndev->max_mtu 7784 - * as well as plat->maxmtu < ndev->min_mtu which is a invalid range. 7783 + 7784 + /* Warn if the platform's maxmtu is smaller than the minimum MTU, 7785 + * otherwise clamp the maximum MTU above to the platform's maxmtu. 7785 7786 */ 7786 - if ((priv->plat->maxmtu < ndev->max_mtu) && 7787 - (priv->plat->maxmtu >= ndev->min_mtu)) 7788 - ndev->max_mtu = priv->plat->maxmtu; 7789 - else if (priv->plat->maxmtu < ndev->min_mtu) 7787 + if (priv->plat->maxmtu < ndev->min_mtu) 7790 7788 dev_warn(priv->device, 7791 7789 "%s: warning: maxmtu having invalid value (%d)\n", 7792 7790 __func__, priv->plat->maxmtu); 7791 + else if (priv->plat->maxmtu < ndev->max_mtu) 7792 + ndev->max_mtu = priv->plat->maxmtu; 7793 7793 7794 7794 ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE; 7795 7795