All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/2] dt-bindings: net: mediatek: Support custom ifname
@ 2021-06-13 11:58 ` Reto Schneider
  0 siblings, 0 replies; 21+ messages in thread
From: Reto Schneider @ 2021-06-13 11:58 UTC (permalink / raw)
  To: devicetree, linux-mediatek, netdev
  Cc: Stefan Roese, Reto Schneider, David S. Miller, Jakub Kicinski,
	Matthias Brugger, Rob Herring, linux-arm-kernel, linux-kernel

From: Reto Schneider <reto.schneider@husqvarnagroup.com>

The (optional) label property allows to specify customized interfaces
names.

The motivation behind this change is to allow embedded devices to keep
their first switch port be named "eth0", even when switching to the DSA
architecture. In order to do so, it must be possible to name the MAC
interface differently from eth0.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
---

 Documentation/devicetree/bindings/net/mediatek-net.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/mediatek-net.txt b/Documentation/devicetree/bindings/net/mediatek-net.txt
index 72d03e07cf7c..93e35f239a0a 100644
--- a/Documentation/devicetree/bindings/net/mediatek-net.txt
+++ b/Documentation/devicetree/bindings/net/mediatek-net.txt
@@ -51,6 +51,9 @@ Required properties:
 	is equal to 0 and the MAC uses fixed-link to connect
 	with internal switch such as MT7530.
 
+Optional properties:
+- label: Name of interface, defaults to ethX if missing
+
 Example:
 
 eth: ethernet@1b100000 {
@@ -76,6 +79,7 @@ eth: ethernet@1b100000 {
 		compatible = "mediatek,eth-mac";
 		reg = <0>;
 		phy-handle = <&phy0>;
+		label = "mac1";
 	};
 
 	gmac2: mac@1 {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v1 1/2] dt-bindings: net: mediatek: Support custom ifname
@ 2021-06-13 11:58 ` Reto Schneider
  0 siblings, 0 replies; 21+ messages in thread
From: Reto Schneider @ 2021-06-13 11:58 UTC (permalink / raw)
  To: devicetree, linux-mediatek, netdev
  Cc: Stefan Roese, Reto Schneider, David S. Miller, Jakub Kicinski,
	Matthias Brugger, Rob Herring, linux-arm-kernel, linux-kernel

From: Reto Schneider <reto.schneider@husqvarnagroup.com>

The (optional) label property allows to specify customized interfaces
names.

The motivation behind this change is to allow embedded devices to keep
their first switch port be named "eth0", even when switching to the DSA
architecture. In order to do so, it must be possible to name the MAC
interface differently from eth0.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
---

 Documentation/devicetree/bindings/net/mediatek-net.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/mediatek-net.txt b/Documentation/devicetree/bindings/net/mediatek-net.txt
index 72d03e07cf7c..93e35f239a0a 100644
--- a/Documentation/devicetree/bindings/net/mediatek-net.txt
+++ b/Documentation/devicetree/bindings/net/mediatek-net.txt
@@ -51,6 +51,9 @@ Required properties:
 	is equal to 0 and the MAC uses fixed-link to connect
 	with internal switch such as MT7530.
 
+Optional properties:
+- label: Name of interface, defaults to ethX if missing
+
 Example:
 
 eth: ethernet@1b100000 {
@@ -76,6 +79,7 @@ eth: ethernet@1b100000 {
 		compatible = "mediatek,eth-mac";
 		reg = <0>;
 		phy-handle = <&phy0>;
+		label = "mac1";
 	};
 
 	gmac2: mac@1 {
-- 
2.30.2


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v1 1/2] dt-bindings: net: mediatek: Support custom ifname
@ 2021-06-13 11:58 ` Reto Schneider
  0 siblings, 0 replies; 21+ messages in thread
From: Reto Schneider @ 2021-06-13 11:58 UTC (permalink / raw)
  To: devicetree, linux-mediatek, netdev
  Cc: Stefan Roese, Reto Schneider, David S. Miller, Jakub Kicinski,
	Matthias Brugger, Rob Herring, linux-arm-kernel, linux-kernel

From: Reto Schneider <reto.schneider@husqvarnagroup.com>

The (optional) label property allows to specify customized interfaces
names.

The motivation behind this change is to allow embedded devices to keep
their first switch port be named "eth0", even when switching to the DSA
architecture. In order to do so, it must be possible to name the MAC
interface differently from eth0.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
---

 Documentation/devicetree/bindings/net/mediatek-net.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/mediatek-net.txt b/Documentation/devicetree/bindings/net/mediatek-net.txt
index 72d03e07cf7c..93e35f239a0a 100644
--- a/Documentation/devicetree/bindings/net/mediatek-net.txt
+++ b/Documentation/devicetree/bindings/net/mediatek-net.txt
@@ -51,6 +51,9 @@ Required properties:
 	is equal to 0 and the MAC uses fixed-link to connect
 	with internal switch such as MT7530.
 
+Optional properties:
+- label: Name of interface, defaults to ethX if missing
+
 Example:
 
 eth: ethernet@1b100000 {
@@ -76,6 +79,7 @@ eth: ethernet@1b100000 {
 		compatible = "mediatek,eth-mac";
 		reg = <0>;
 		phy-handle = <&phy0>;
+		label = "mac1";
 	};
 
 	gmac2: mac@1 {
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v1 2/2] net: ethernet: mtk_eth_soc: Support custom ifname
  2021-06-13 11:58 ` Reto Schneider
  (?)
@ 2021-06-13 11:58   ` Reto Schneider
  -1 siblings, 0 replies; 21+ messages in thread
From: Reto Schneider @ 2021-06-13 11:58 UTC (permalink / raw)
  To: devicetree, linux-mediatek, netdev
  Cc: Stefan Roese, Reto Schneider, David S. Miller, Felix Fietkau,
	Jakub Kicinski, John Crispin, Mark Lee, Matthias Brugger,
	Russell King, Sean Wang, linux-arm-kernel, linux-kernel

From: Reto Schneider <reto.schneider@husqvarnagroup.com>

Name the MAC interface name according to the label property. If the
property is missing, the default name (ethX) gets used.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>

---

 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++++
 1 file changed, 4 insertions(+)

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);
+
 	SET_NETDEV_DEV(eth->netdev[id], eth->dev);
 	eth->netdev[id]->watchdog_timeo = 5 * HZ;
 	eth->netdev[id]->netdev_ops = &mtk_netdev_ops;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v1 2/2] net: ethernet: mtk_eth_soc: Support custom ifname
@ 2021-06-13 11:58   ` Reto Schneider
  0 siblings, 0 replies; 21+ messages in thread
From: Reto Schneider @ 2021-06-13 11:58 UTC (permalink / raw)
  To: devicetree, linux-mediatek, netdev
  Cc: Stefan Roese, Reto Schneider, David S. Miller, Felix Fietkau,
	Jakub Kicinski, John Crispin, Mark Lee, Matthias Brugger,
	Russell King, Sean Wang, linux-arm-kernel, linux-kernel

From: Reto Schneider <reto.schneider@husqvarnagroup.com>

Name the MAC interface name according to the label property. If the
property is missing, the default name (ethX) gets used.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>

---

 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++++
 1 file changed, 4 insertions(+)

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);
+
 	SET_NETDEV_DEV(eth->netdev[id], eth->dev);
 	eth->netdev[id]->watchdog_timeo = 5 * HZ;
 	eth->netdev[id]->netdev_ops = &mtk_netdev_ops;
-- 
2.30.2


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v1 2/2] net: ethernet: mtk_eth_soc: Support custom ifname
@ 2021-06-13 11:58   ` Reto Schneider
  0 siblings, 0 replies; 21+ messages in thread
From: Reto Schneider @ 2021-06-13 11:58 UTC (permalink / raw)
  To: devicetree, linux-mediatek, netdev
  Cc: Stefan Roese, Reto Schneider, David S. Miller, Felix Fietkau,
	Jakub Kicinski, John Crispin, Mark Lee, Matthias Brugger,
	Russell King, Sean Wang, linux-arm-kernel, linux-kernel

From: Reto Schneider <reto.schneider@husqvarnagroup.com>

Name the MAC interface name according to the label property. If the
property is missing, the default name (ethX) gets used.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>

---

 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++++
 1 file changed, 4 insertions(+)

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);
+
 	SET_NETDEV_DEV(eth->netdev[id], eth->dev);
 	eth->netdev[id]->watchdog_timeo = 5 * HZ;
 	eth->netdev[id]->netdev_ops = &mtk_netdev_ops;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 2/2] net: ethernet: mtk_eth_soc: Support custom ifname
  2021-06-13 11:58   ` Reto Schneider
  (?)
@ 2021-06-13 12:20     ` Russell King (Oracle)
  -1 siblings, 0 replies; 21+ messages in thread
From: Russell King (Oracle) @ 2021-06-13 12:20 UTC (permalink / raw)
  To: Reto Schneider
  Cc: devicetree, linux-mediatek, netdev, Stefan Roese, Reto Schneider,
	David S. Miller, Felix Fietkau, Jakub Kicinski, John Crispin,
	Mark Lee, Matthias Brugger, Sean Wang, linux-arm-kernel,
	linux-kernel

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!

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 2/2] net: ethernet: mtk_eth_soc: Support custom ifname
@ 2021-06-13 12:20     ` Russell King (Oracle)
  0 siblings, 0 replies; 21+ messages in thread
From: Russell King (Oracle) @ 2021-06-13 12:20 UTC (permalink / raw)
  To: Reto Schneider
  Cc: devicetree, linux-mediatek, netdev, Stefan Roese, Reto Schneider,
	David S. Miller, Felix Fietkau, Jakub Kicinski, John Crispin,
	Mark Lee, Matthias Brugger, Sean Wang, linux-arm-kernel,
	linux-kernel

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!

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 2/2] net: ethernet: mtk_eth_soc: Support custom ifname
@ 2021-06-13 12:20     ` Russell King (Oracle)
  0 siblings, 0 replies; 21+ messages in thread
From: Russell King (Oracle) @ 2021-06-13 12:20 UTC (permalink / raw)
  To: Reto Schneider
  Cc: devicetree, linux-mediatek, netdev, Stefan Roese, Reto Schneider,
	David S. Miller, Felix Fietkau, Jakub Kicinski, John Crispin,
	Mark Lee, Matthias Brugger, Sean Wang, linux-arm-kernel,
	linux-kernel

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!

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 2/2] net: ethernet: mtk_eth_soc: Support custom ifname
  2021-06-13 12:20     ` Russell King (Oracle)
  (?)
@ 2021-06-13 13:53       ` Reto Schneider
  -1 siblings, 0 replies; 21+ messages in thread
From: Reto Schneider @ 2021-06-13 13:53 UTC (permalink / raw)
  To: Russell King (Oracle)
  Cc: devicetree, linux-mediatek, netdev, Stefan Roese, Reto Schneider,
	David S. Miller, Felix Fietkau, Jakub Kicinski, John Crispin,
	Mark Lee, Matthias Brugger, Sean Wang, linux-arm-kernel,
	linux-kernel

Hi Russell,

On 13.06.21 14:20, Russell King (Oracle) wrote:
> 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 a lot for finding this (embarrassing mistake) and pointing me in 
the right direction (did dot know about strscpy).

Will send v2 soon.

Kind regards,
Reto

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 2/2] net: ethernet: mtk_eth_soc: Support custom ifname
@ 2021-06-13 13:53       ` Reto Schneider
  0 siblings, 0 replies; 21+ messages in thread
From: Reto Schneider @ 2021-06-13 13:53 UTC (permalink / raw)
  To: Russell King (Oracle)
  Cc: devicetree, linux-mediatek, netdev, Stefan Roese, Reto Schneider,
	David S. Miller, Felix Fietkau, Jakub Kicinski, John Crispin,
	Mark Lee, Matthias Brugger, Sean Wang, linux-arm-kernel,
	linux-kernel

Hi Russell,

On 13.06.21 14:20, Russell King (Oracle) wrote:
> 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 a lot for finding this (embarrassing mistake) and pointing me in 
the right direction (did dot know about strscpy).

Will send v2 soon.

Kind regards,
Reto

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 2/2] net: ethernet: mtk_eth_soc: Support custom ifname
@ 2021-06-13 13:53       ` Reto Schneider
  0 siblings, 0 replies; 21+ messages in thread
From: Reto Schneider @ 2021-06-13 13:53 UTC (permalink / raw)
  To: Russell King (Oracle)
  Cc: devicetree, linux-mediatek, netdev, Stefan Roese, Reto Schneider,
	David S. Miller, Felix Fietkau, Jakub Kicinski, John Crispin,
	Mark Lee, Matthias Brugger, Sean Wang, linux-arm-kernel,
	linux-kernel

Hi Russell,

On 13.06.21 14:20, Russell King (Oracle) wrote:
> 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 a lot for finding this (embarrassing mistake) and pointing me in 
the right direction (did dot know about strscpy).

Will send v2 soon.

Kind regards,
Reto

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v2 1/2] dt-bindings: net: mediatek: Support custom ifname
  2021-06-13 11:58 ` Reto Schneider
  (?)
@ 2021-06-13 14:58   ` Reto Schneider
  -1 siblings, 0 replies; 21+ messages in thread
From: Reto Schneider @ 2021-06-13 14:58 UTC (permalink / raw)
  To: devicetree, linux-mediatek, netdev
  Cc: Stefan Roese, Reto Schneider, David S. Miller, Jakub Kicinski,
	Matthias Brugger, Rob Herring, linux-arm-kernel, linux-kernel

From: Reto Schneider <reto.schneider@husqvarnagroup.com>

The (optional) label property allows to specify customized interfaces
names.

The motivation behind this change is to allow embedded devices to keep
their first switch port be named "eth0", even when switching to the DSA
architecture. In order to do so, it must be possible to name the MAC
interface differently from eth0.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
---

(no changes since v1)

 Documentation/devicetree/bindings/net/mediatek-net.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/mediatek-net.txt b/Documentation/devicetree/bindings/net/mediatek-net.txt
index 72d03e07cf7c..93e35f239a0a 100644
--- a/Documentation/devicetree/bindings/net/mediatek-net.txt
+++ b/Documentation/devicetree/bindings/net/mediatek-net.txt
@@ -51,6 +51,9 @@ Required properties:
 	is equal to 0 and the MAC uses fixed-link to connect
 	with internal switch such as MT7530.
 
+Optional properties:
+- label: Name of interface, defaults to ethX if missing
+
 Example:
 
 eth: ethernet@1b100000 {
@@ -76,6 +79,7 @@ eth: ethernet@1b100000 {
 		compatible = "mediatek,eth-mac";
 		reg = <0>;
 		phy-handle = <&phy0>;
+		label = "mac1";
 	};
 
 	gmac2: mac@1 {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 1/2] dt-bindings: net: mediatek: Support custom ifname
@ 2021-06-13 14:58   ` Reto Schneider
  0 siblings, 0 replies; 21+ messages in thread
From: Reto Schneider @ 2021-06-13 14:58 UTC (permalink / raw)
  To: devicetree, linux-mediatek, netdev
  Cc: Stefan Roese, Reto Schneider, David S. Miller, Jakub Kicinski,
	Matthias Brugger, Rob Herring, linux-arm-kernel, linux-kernel

From: Reto Schneider <reto.schneider@husqvarnagroup.com>

The (optional) label property allows to specify customized interfaces
names.

The motivation behind this change is to allow embedded devices to keep
their first switch port be named "eth0", even when switching to the DSA
architecture. In order to do so, it must be possible to name the MAC
interface differently from eth0.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
---

(no changes since v1)

 Documentation/devicetree/bindings/net/mediatek-net.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/mediatek-net.txt b/Documentation/devicetree/bindings/net/mediatek-net.txt
index 72d03e07cf7c..93e35f239a0a 100644
--- a/Documentation/devicetree/bindings/net/mediatek-net.txt
+++ b/Documentation/devicetree/bindings/net/mediatek-net.txt
@@ -51,6 +51,9 @@ Required properties:
 	is equal to 0 and the MAC uses fixed-link to connect
 	with internal switch such as MT7530.
 
+Optional properties:
+- label: Name of interface, defaults to ethX if missing
+
 Example:
 
 eth: ethernet@1b100000 {
@@ -76,6 +79,7 @@ eth: ethernet@1b100000 {
 		compatible = "mediatek,eth-mac";
 		reg = <0>;
 		phy-handle = <&phy0>;
+		label = "mac1";
 	};
 
 	gmac2: mac@1 {
-- 
2.30.2


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 1/2] dt-bindings: net: mediatek: Support custom ifname
@ 2021-06-13 14:58   ` Reto Schneider
  0 siblings, 0 replies; 21+ messages in thread
From: Reto Schneider @ 2021-06-13 14:58 UTC (permalink / raw)
  To: devicetree, linux-mediatek, netdev
  Cc: Stefan Roese, Reto Schneider, David S. Miller, Jakub Kicinski,
	Matthias Brugger, Rob Herring, linux-arm-kernel, linux-kernel

From: Reto Schneider <reto.schneider@husqvarnagroup.com>

The (optional) label property allows to specify customized interfaces
names.

The motivation behind this change is to allow embedded devices to keep
their first switch port be named "eth0", even when switching to the DSA
architecture. In order to do so, it must be possible to name the MAC
interface differently from eth0.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
---

(no changes since v1)

 Documentation/devicetree/bindings/net/mediatek-net.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/mediatek-net.txt b/Documentation/devicetree/bindings/net/mediatek-net.txt
index 72d03e07cf7c..93e35f239a0a 100644
--- a/Documentation/devicetree/bindings/net/mediatek-net.txt
+++ b/Documentation/devicetree/bindings/net/mediatek-net.txt
@@ -51,6 +51,9 @@ Required properties:
 	is equal to 0 and the MAC uses fixed-link to connect
 	with internal switch such as MT7530.
 
+Optional properties:
+- label: Name of interface, defaults to ethX if missing
+
 Example:
 
 eth: ethernet@1b100000 {
@@ -76,6 +79,7 @@ eth: ethernet@1b100000 {
 		compatible = "mediatek,eth-mac";
 		reg = <0>;
 		phy-handle = <&phy0>;
+		label = "mac1";
 	};
 
 	gmac2: mac@1 {
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 2/2] net: ethernet: mtk_eth_soc: Support custom ifname
  2021-06-13 11:58 ` Reto Schneider
  (?)
@ 2021-06-13 14:59   ` Reto Schneider
  -1 siblings, 0 replies; 21+ messages in thread
From: Reto Schneider @ 2021-06-13 14:59 UTC (permalink / raw)
  To: devicetree, linux-mediatek, netdev
  Cc: Stefan Roese, Reto Schneider, David S. Miller, Felix Fietkau,
	Jakub Kicinski, John Crispin, Mark Lee, Matthias Brugger,
	Russell King, Sean Wang, linux-arm-kernel, linux-kernel

From: Reto Schneider <reto.schneider@husqvarnagroup.com>

Name the MAC interface name according to the label property. If the
property is missing, the default name (ethX) gets used.

Labels with more than IFNAMSIZ -1 characters will be truncated silently,
which seems to be what most of the code base does when using strscpy.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>

---

Changes in v2:
- Avoid dangerous usage of strncpy

 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 64adfd24e134..a921ecc1c997 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)
+		strscpy(eth->netdev[id]->name, name, IFNAMSIZ);
+
 	SET_NETDEV_DEV(eth->netdev[id], eth->dev);
 	eth->netdev[id]->watchdog_timeo = 5 * HZ;
 	eth->netdev[id]->netdev_ops = &mtk_netdev_ops;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 2/2] net: ethernet: mtk_eth_soc: Support custom ifname
@ 2021-06-13 14:59   ` Reto Schneider
  0 siblings, 0 replies; 21+ messages in thread
From: Reto Schneider @ 2021-06-13 14:59 UTC (permalink / raw)
  To: devicetree, linux-mediatek, netdev
  Cc: Stefan Roese, Reto Schneider, David S. Miller, Felix Fietkau,
	Jakub Kicinski, John Crispin, Mark Lee, Matthias Brugger,
	Russell King, Sean Wang, linux-arm-kernel, linux-kernel

From: Reto Schneider <reto.schneider@husqvarnagroup.com>

Name the MAC interface name according to the label property. If the
property is missing, the default name (ethX) gets used.

Labels with more than IFNAMSIZ -1 characters will be truncated silently,
which seems to be what most of the code base does when using strscpy.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>

---

Changes in v2:
- Avoid dangerous usage of strncpy

 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 64adfd24e134..a921ecc1c997 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)
+		strscpy(eth->netdev[id]->name, name, IFNAMSIZ);
+
 	SET_NETDEV_DEV(eth->netdev[id], eth->dev);
 	eth->netdev[id]->watchdog_timeo = 5 * HZ;
 	eth->netdev[id]->netdev_ops = &mtk_netdev_ops;
-- 
2.30.2


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v2 2/2] net: ethernet: mtk_eth_soc: Support custom ifname
@ 2021-06-13 14:59   ` Reto Schneider
  0 siblings, 0 replies; 21+ messages in thread
From: Reto Schneider @ 2021-06-13 14:59 UTC (permalink / raw)
  To: devicetree, linux-mediatek, netdev
  Cc: Stefan Roese, Reto Schneider, David S. Miller, Felix Fietkau,
	Jakub Kicinski, John Crispin, Mark Lee, Matthias Brugger,
	Russell King, Sean Wang, linux-arm-kernel, linux-kernel

From: Reto Schneider <reto.schneider@husqvarnagroup.com>

Name the MAC interface name according to the label property. If the
property is missing, the default name (ethX) gets used.

Labels with more than IFNAMSIZ -1 characters will be truncated silently,
which seems to be what most of the code base does when using strscpy.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>

---

Changes in v2:
- Avoid dangerous usage of strncpy

 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 64adfd24e134..a921ecc1c997 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)
+		strscpy(eth->netdev[id]->name, name, IFNAMSIZ);
+
 	SET_NETDEV_DEV(eth->netdev[id], eth->dev);
 	eth->netdev[id]->watchdog_timeo = 5 * HZ;
 	eth->netdev[id]->netdev_ops = &mtk_netdev_ops;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 2/2] net: ethernet: mtk_eth_soc: Support custom ifname
  2021-06-13 11:58   ` Reto Schneider
  (?)
@ 2021-06-14 19:48     ` David Miller
  -1 siblings, 0 replies; 21+ messages in thread
From: David Miller @ 2021-06-14 19:48 UTC (permalink / raw)
  To: code
  Cc: devicetree, linux-mediatek, netdev, sr, reto.schneider, nbd,
	kuba, john, Mark-MC.Lee, matthias.bgg, linux, sean.wang,
	linux-arm-kernel, linux-kernel

From: Reto Schneider <code@reto-schneider.ch>
Date: Sun, 13 Jun 2021 13:58:19 +0200

> From: Reto Schneider <reto.schneider@husqvarnagroup.com>
> 
> Name the MAC interface name according to the label property. If the
> property is missing, the default name (ethX) gets used.
> 
> Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>

Please solve naming issues in userspace via udev, thank you.


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 2/2] net: ethernet: mtk_eth_soc: Support custom ifname
@ 2021-06-14 19:48     ` David Miller
  0 siblings, 0 replies; 21+ messages in thread
From: David Miller @ 2021-06-14 19:48 UTC (permalink / raw)
  To: code
  Cc: devicetree, linux-mediatek, netdev, sr, reto.schneider, nbd,
	kuba, john, Mark-MC.Lee, matthias.bgg, linux, sean.wang,
	linux-arm-kernel, linux-kernel

From: Reto Schneider <code@reto-schneider.ch>
Date: Sun, 13 Jun 2021 13:58:19 +0200

> From: Reto Schneider <reto.schneider@husqvarnagroup.com>
> 
> Name the MAC interface name according to the label property. If the
> property is missing, the default name (ethX) gets used.
> 
> Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>

Please solve naming issues in userspace via udev, thank you.


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 2/2] net: ethernet: mtk_eth_soc: Support custom ifname
@ 2021-06-14 19:48     ` David Miller
  0 siblings, 0 replies; 21+ messages in thread
From: David Miller @ 2021-06-14 19:48 UTC (permalink / raw)
  To: code
  Cc: devicetree, linux-mediatek, netdev, sr, reto.schneider, nbd,
	kuba, john, Mark-MC.Lee, matthias.bgg, linux, sean.wang,
	linux-arm-kernel, linux-kernel

From: Reto Schneider <code@reto-schneider.ch>
Date: Sun, 13 Jun 2021 13:58:19 +0200

> From: Reto Schneider <reto.schneider@husqvarnagroup.com>
> 
> Name the MAC interface name according to the label property. If the
> property is missing, the default name (ethX) gets used.
> 
> Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>

Please solve naming issues in userspace via udev, thank you.


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2021-06-14 19:50 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-13 11:58 [PATCH v1 1/2] dt-bindings: net: mediatek: Support custom ifname Reto Schneider
2021-06-13 11:58 ` Reto Schneider
2021-06-13 11:58 ` Reto Schneider
2021-06-13 11:58 ` [PATCH v1 2/2] net: ethernet: mtk_eth_soc: " Reto Schneider
2021-06-13 11:58   ` Reto Schneider
2021-06-13 11:58   ` Reto Schneider
2021-06-13 12:20   ` Russell King (Oracle)
2021-06-13 12:20     ` Russell King (Oracle)
2021-06-13 12:20     ` Russell King (Oracle)
2021-06-13 13:53     ` Reto Schneider
2021-06-13 13:53       ` Reto Schneider
2021-06-13 13:53       ` Reto Schneider
2021-06-14 19:48   ` David Miller
2021-06-14 19:48     ` David Miller
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:58   ` Reto Schneider
2021-06-13 14:58   ` Reto Schneider
2021-06-13 14:59 ` [PATCH v2 2/2] net: ethernet: mtk_eth_soc: " Reto Schneider
2021-06-13 14:59   ` Reto Schneider
2021-06-13 14:59   ` Reto Schneider

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.