From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Reto Schneider <code@reto-schneider.ch>
Cc: devicetree@vger.kernel.org, linux-mediatek@lists.infradead.org,
netdev@vger.kernel.org, Stefan Roese <sr@denx.de>,
Reto Schneider <reto.schneider@husqvarnagroup.com>,
"David S. Miller" <davem@davemloft.net>,
Felix Fietkau <nbd@nbd.name>, Jakub Kicinski <kuba@kernel.org>,
John Crispin <john@phrozen.org>,
Mark Lee <Mark-MC.Lee@mediatek.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
Sean Wang <sean.wang@mediatek.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 2/2] net: ethernet: mtk_eth_soc: Support custom ifname
Date: Sun, 13 Jun 2021 13:20:43 +0100 [thread overview]
Message-ID: <20210613122043.GP22278@shell.armlinux.org.uk> (raw)
In-Reply-To: <20210613115820.1525478-2-code@reto-schneider.ch>
On Sun, Jun 13, 2021 at 01:58:19PM +0200, Reto Schneider wrote:
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 64adfd24e134..8bb09801918f 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -2948,6 +2948,7 @@ static const struct net_device_ops mtk_netdev_ops = {
> static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
> {
> const __be32 *_id = of_get_property(np, "reg", NULL);
> + const char *const name = of_get_property(np, "label", NULL);
> phy_interface_t phy_mode;
> struct phylink *phylink;
> struct mtk_mac *mac;
> @@ -3020,6 +3021,9 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
>
> mac->phylink = phylink;
>
> + if (name)
> + strncpy(eth->netdev[id]->name, name, IFNAMSIZ);
Please don't use strncpy() - this is a good example why strncpy() is bad
news.
* strncpy - Copy a length-limited, C-string
* @dest: Where to copy the string to
* @src: Where to copy the string from
* @count: The maximum number of bytes to copy
*
* The result is not %NUL-terminated if the source exceeds
* @count bytes.
Consequently, if "name" is IFNAMSIZ bytes or longer,
eth->netdev[id]->name will not be NUL terminated, and subsequent use
will run off the end of the string. strscpy() is safer to use here.
Thanks.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
next prev parent reply other threads:[~2021-06-13 12:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-13 11:58 [PATCH v1 1/2] dt-bindings: net: mediatek: Support custom ifname Reto Schneider
2021-06-13 11:58 ` [PATCH v1 2/2] net: ethernet: mtk_eth_soc: " Reto Schneider
2021-06-13 12:20 ` Russell King (Oracle) [this message]
2021-06-13 13:53 ` Reto Schneider
2021-06-14 19:48 ` David Miller
2021-06-13 14:58 ` [PATCH v2 1/2] dt-bindings: net: mediatek: " Reto Schneider
2021-06-13 14:59 ` [PATCH v2 2/2] net: ethernet: mtk_eth_soc: " Reto Schneider
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210613122043.GP22278@shell.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=Mark-MC.Lee@mediatek.com \
--cc=code@reto-schneider.ch \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=john@phrozen.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=nbd@nbd.name \
--cc=netdev@vger.kernel.org \
--cc=reto.schneider@husqvarnagroup.com \
--cc=sean.wang@mediatek.com \
--cc=sr@denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).