DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] examples/kni: clear warning about discarding const qualifier
@ 2022-05-31  9:13 Ke Zhang
  2022-05-31 14:55 ` Stephen Hemminger
                   ` (4 more replies)
  0 siblings, 5 replies; 17+ messages in thread
From: Ke Zhang @ 2022-05-31  9:13 UTC (permalink / raw)
  To: ferruh.yigit, dev; +Cc: Ke Zhang

The warning info:
warning: passing argument 1 of ‘memcpy’ discards ‘const’
qualifier from pointer target type

Compulsory type conversion to clear compile warning.

Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>
---
 kernel/linux/kni/kni_misc.c | 4 ++--
 kernel/linux/kni/kni_net.c  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
index 780187d8bf..6f9dab4732 100644
--- a/kernel/linux/kni/kni_misc.c
+++ b/kernel/linux/kni/kni_misc.c
@@ -403,10 +403,10 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 
 	/* if user has provided a valid mac address */
 	if (is_valid_ether_addr(dev_info.mac_addr))
-		memcpy(net_dev->dev_addr, dev_info.mac_addr, ETH_ALEN);
+		memcpy((unsigned char *)net_dev->dev_addr, dev_info.mac_addr, ETH_ALEN);
 	else
 		/* Generate random MAC address. */
-		eth_random_addr(net_dev->dev_addr);
+		eth_random_addr((uint8_t *)net_dev->dev_addr);
 
 	if (dev_info.mtu)
 		net_dev->mtu = dev_info.mtu;
diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
index 29e5b9e21f..fd54b6fe0f 100644
--- a/kernel/linux/kni/kni_net.c
+++ b/kernel/linux/kni/kni_net.c
@@ -779,7 +779,7 @@ kni_net_set_mac(struct net_device *netdev, void *p)
 		return -EADDRNOTAVAIL;
 
 	memcpy(req.mac_addr, addr->sa_data, netdev->addr_len);
-	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
+	memcpy((unsigned char *)netdev->dev_addr, addr->sa_data, netdev->addr_len);
 
 	ret = kni_net_process_request(netdev, &req);
 
-- 
2.25.1


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

* Re: [PATCH] examples/kni: clear warning about discarding const qualifier
  2022-05-31  9:13 [PATCH] examples/kni: clear warning about discarding const qualifier Ke Zhang
@ 2022-05-31 14:55 ` Stephen Hemminger
  2022-06-01  5:45 ` [PATCH v2] " Ke Zhang
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 17+ messages in thread
From: Stephen Hemminger @ 2022-05-31 14:55 UTC (permalink / raw)
  To: Ke Zhang; +Cc: ferruh.yigit, dev

On Tue, 31 May 2022 09:13:30 +0000
Ke Zhang <ke1x.zhang@intel.com> wrote:

> The warning info:
> warning: passing argument 1 of ‘memcpy’ discards ‘const’
> qualifier from pointer target type
> 
> Compulsory type conversion to clear compile warning.
> 
> Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>

Agree with other comments, please use eth_hw_addr_set()
and eth_hw_addr_random() helpers.

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

* [PATCH v2] examples/kni: clear warning about discarding const qualifier
  2022-05-31  9:13 [PATCH] examples/kni: clear warning about discarding const qualifier Ke Zhang
  2022-05-31 14:55 ` Stephen Hemminger
@ 2022-06-01  5:45 ` Ke Zhang
  2022-06-01 15:44   ` Ferruh Yigit
  2022-06-05  9:47 ` [PATCH v3 1/2] kni: use dedicated function to set random MAC address Andrew Rybchenko
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 17+ messages in thread
From: Ke Zhang @ 2022-06-01  5:45 UTC (permalink / raw)
  To: ferruh.yigit, dev; +Cc: Ke Zhang, stable

The warning info:
warning: passing argument 1 of ‘memcpy’ discards ‘const’
qualifier from pointer target type

Variable is done const intentionally to prevent using it
directly, using the new helper functions :
'eth_hw_addr_set()' and 'eth_hw_addr_random()'

Fixes: ea6b39b5b847 ("kni: remove ethtool support")
Cc: stable@dpdk.org

Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>
---
 kernel/linux/kni/kni_misc.c | 4 ++--
 kernel/linux/kni/kni_net.c  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
index 780187d8bf..1da8e812b7 100644
--- a/kernel/linux/kni/kni_misc.c
+++ b/kernel/linux/kni/kni_misc.c
@@ -403,10 +403,10 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 
 	/* if user has provided a valid mac address */
 	if (is_valid_ether_addr(dev_info.mac_addr))
-		memcpy(net_dev->dev_addr, dev_info.mac_addr, ETH_ALEN);
+		eth_hw_addr_set(net_dev, dev_info.mac_addr);
 	else
 		/* Generate random MAC address. */
-		eth_random_addr(net_dev->dev_addr);
+		eth_hw_addr_random(net_dev);
 
 	if (dev_info.mtu)
 		net_dev->mtu = dev_info.mtu;
diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
index 29e5b9e21f..1da4f836aa 100644
--- a/kernel/linux/kni/kni_net.c
+++ b/kernel/linux/kni/kni_net.c
@@ -779,7 +779,7 @@ kni_net_set_mac(struct net_device *netdev, void *p)
 		return -EADDRNOTAVAIL;
 
 	memcpy(req.mac_addr, addr->sa_data, netdev->addr_len);
-	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
+	eth_hw_addr_set(netdev, addr->sa_data);
 
 	ret = kni_net_process_request(netdev, &req);
 
-- 
2.25.1


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

* Re: [PATCH v2] examples/kni: clear warning about discarding const qualifier
  2022-06-01  5:45 ` [PATCH v2] " Ke Zhang
@ 2022-06-01 15:44   ` Ferruh Yigit
  0 siblings, 0 replies; 17+ messages in thread
From: Ferruh Yigit @ 2022-06-01 15:44 UTC (permalink / raw)
  To: Ke Zhang, dev; +Cc: stable

On 6/1/2022 6:45 AM, Ke Zhang wrote:
> The warning info:
> warning: passing argument 1 of ‘memcpy’ discards ‘const’
> qualifier from pointer target type
> 
> Variable is done const intentionally to prevent using it
> directly, using the new helper functions :
> 'eth_hw_addr_set()' and 'eth_hw_addr_random()'
> 
> Fixes: ea6b39b5b847 ("kni: remove ethtool support")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>
> ---
>   kernel/linux/kni/kni_misc.c | 4 ++--
>   kernel/linux/kni/kni_net.c  | 2 +-
>   2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
> index 780187d8bf..1da8e812b7 100644
> --- a/kernel/linux/kni/kni_misc.c
> +++ b/kernel/linux/kni/kni_misc.c
> @@ -403,10 +403,10 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
>   
>   	/* if user has provided a valid mac address */
>   	if (is_valid_ether_addr(dev_info.mac_addr))
> -		memcpy(net_dev->dev_addr, dev_info.mac_addr, ETH_ALEN);
> +		eth_hw_addr_set(net_dev, dev_info.mac_addr);
>   	else
>   		/* Generate random MAC address. */
> -		eth_random_addr(net_dev->dev_addr);
> +		eth_hw_addr_random(net_dev);
>   
>   	if (dev_info.mtu)
>   		net_dev->mtu = dev_info.mtu;
> diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
> index 29e5b9e21f..1da4f836aa 100644
> --- a/kernel/linux/kni/kni_net.c
> +++ b/kernel/linux/kni/kni_net.c
> @@ -779,7 +779,7 @@ kni_net_set_mac(struct net_device *netdev, void *p)
>   		return -EADDRNOTAVAIL;
>   
>   	memcpy(req.mac_addr, addr->sa_data, netdev->addr_len);
> -	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
> +	eth_hw_addr_set(netdev, addr->sa_data);
>   
>   	ret = kni_net_process_request(netdev, &req);
>   

Hi Ke,

We can't just use new APIs, otherwise this will fail with old kernels.
A version check is needed, please check 'compat.h' for various samples.

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

* [PATCH v3 1/2] kni: use dedicated function to set random MAC address
  2022-05-31  9:13 [PATCH] examples/kni: clear warning about discarding const qualifier Ke Zhang
  2022-05-31 14:55 ` Stephen Hemminger
  2022-06-01  5:45 ` [PATCH v2] " Ke Zhang
@ 2022-06-05  9:47 ` Andrew Rybchenko
  2022-06-05  9:47   ` [PATCH v3 2/2] kni: fix warning about discarding const qualifier Andrew Rybchenko
  2022-06-08 11:13 ` [PATCH v4 0/2] kni: fix build warnings with Linux 5.17+ Andrew Rybchenko
  2022-06-08 12:11 ` [PATCH v5 0/2] kni: fix build warnings with Linux 5.17+ Andrew Rybchenko
  4 siblings, 1 reply; 17+ messages in thread
From: Andrew Rybchenko @ 2022-06-05  9:47 UTC (permalink / raw)
  To: Ferruh Yigit, Stephen Hemminger; +Cc: dev, Min Hu, stable, Ke Zhang

eth_hw_addr_random() sets address type correctly.

eth_hw_addr_random() is available since Linux v3.4, so
no compat is required.

Also fix the warning:
warning: passing argument 1 of ‘memcpy’ discards ‘const’
qualifier from pointer target type

Variable dev_addr is done const intentionally in Linux v5.17 to
prevent using it directly.

Fixes: ea6b39b5b847 ("kni: remove ethtool support")
Cc: stable@dpdk.org

Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 kernel/linux/kni/kni_misc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
index 780187d8bf..4f6dd373a3 100644
--- a/kernel/linux/kni/kni_misc.c
+++ b/kernel/linux/kni/kni_misc.c
@@ -405,8 +405,8 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 	if (is_valid_ether_addr(dev_info.mac_addr))
 		memcpy(net_dev->dev_addr, dev_info.mac_addr, ETH_ALEN);
 	else
-		/* Generate random MAC address. */
-		eth_random_addr(net_dev->dev_addr);
+		/* Assign random MAC address. */
+		eth_hw_addr_random(net_dev);
 
 	if (dev_info.mtu)
 		net_dev->mtu = dev_info.mtu;
-- 
2.30.2


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

* [PATCH v3 2/2] kni: fix warning about discarding const qualifier
  2022-06-05  9:47 ` [PATCH v3 1/2] kni: use dedicated function to set random MAC address Andrew Rybchenko
@ 2022-06-05  9:47   ` Andrew Rybchenko
  0 siblings, 0 replies; 17+ messages in thread
From: Andrew Rybchenko @ 2022-06-05  9:47 UTC (permalink / raw)
  To: Ferruh Yigit, Stephen Hemminger; +Cc: dev, Min Hu, stable, Ke Zhang

The warning info:
warning: passing argument 1 of ‘memcpy’ discards ‘const’
qualifier from pointer target type

Variable dev_addr is done const intentionally in v5.17 to prevent using
it directly. See kernel series [1] for more information.

[1] https://lore.kernel.org/netdev/YZYAb4X%2FVQFy0iks@shredder/T/

Fixes: ea6b39b5b847 ("kni: remove ethtool support")
Cc: stable@dpdk.org

Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 kernel/linux/kni/compat.h   | 4 ++++
 kernel/linux/kni/kni_misc.c | 9 +++++++--
 kernel/linux/kni/kni_net.c  | 4 ++++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/kernel/linux/kni/compat.h b/kernel/linux/kni/compat.h
index 0db29a4a6f..2c8f346ddf 100644
--- a/kernel/linux/kni/compat.h
+++ b/kernel/linux/kni/compat.h
@@ -145,3 +145,7 @@
 #if KERNEL_VERSION(5, 18, 0) > LINUX_VERSION_CODE
 #define HAVE_NETIF_RX_NI
 #endif
+
+#if KERNEL_VERSION(5, 15, 0) <= LINUX_VERSION_CODE
+#define HAVE_ETH_HW_ADDR_SET
+#endif
diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
index 4f6dd373a3..0c3a86ee35 100644
--- a/kernel/linux/kni/kni_misc.c
+++ b/kernel/linux/kni/kni_misc.c
@@ -402,11 +402,16 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 	pr_debug("mbuf_size:    %u\n", kni->mbuf_size);
 
 	/* if user has provided a valid mac address */
-	if (is_valid_ether_addr(dev_info.mac_addr))
+	if (is_valid_ether_addr(dev_info.mac_addr)) {
+#ifdef HAVE_ETH_HW_ADDR_SET
+		eth_hw_addr_set(net_dev, dev_info.mac_addr);
+#else
 		memcpy(net_dev->dev_addr, dev_info.mac_addr, ETH_ALEN);
-	else
+#endif
+	} else {
 		/* Assign random MAC address. */
 		eth_hw_addr_random(net_dev);
+	}
 
 	if (dev_info.mtu)
 		net_dev->mtu = dev_info.mtu;
diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
index a8b092b756..2da2029b0c 100644
--- a/kernel/linux/kni/kni_net.c
+++ b/kernel/linux/kni/kni_net.c
@@ -783,7 +783,11 @@ kni_net_set_mac(struct net_device *netdev, void *p)
 		return -EADDRNOTAVAIL;
 
 	memcpy(req.mac_addr, addr->sa_data, netdev->addr_len);
+#ifdef HAVE_ETH_HW_ADDR_SET
+	eth_hw_addr_set(net_dev, addr->sa_data);
+#else
 	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
+#endif
 
 	ret = kni_net_process_request(netdev, &req);
 
-- 
2.30.2


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

* [PATCH v4 0/2] kni: fix build warnings with Linux 5.17+
  2022-05-31  9:13 [PATCH] examples/kni: clear warning about discarding const qualifier Ke Zhang
                   ` (2 preceding siblings ...)
  2022-06-05  9:47 ` [PATCH v3 1/2] kni: use dedicated function to set random MAC address Andrew Rybchenko
@ 2022-06-08 11:13 ` Andrew Rybchenko
  2022-06-08 11:13   ` [PATCH v4 1/2] kni: use dedicated function to set random MAC address Andrew Rybchenko
  2022-06-08 11:13   ` [PATCH v4 2/2] kni: fix warning about discarding const qualifier Andrew Rybchenko
  2022-06-08 12:11 ` [PATCH v5 0/2] kni: fix build warnings with Linux 5.17+ Andrew Rybchenko
  4 siblings, 2 replies; 17+ messages in thread
From: Andrew Rybchenko @ 2022-06-08 11:13 UTC (permalink / raw)
  To: Ferruh Yigit, Stephen Hemminger; +Cc: dev, Min Hu, Ke Zhang

v4:
    - restore original patch author
    - resend with cover letter to address patchwork recognition as a
      series

v3:
    - split single patch into two
    - clarify patches summary and description

Ke Zhang (2):
  kni: use dedicated function to set random MAC address
  kni: fix warning about discarding const qualifier

 kernel/linux/kni/compat.h   |  4 ++++
 kernel/linux/kni/kni_misc.c | 13 +++++++++----
 kernel/linux/kni/kni_net.c  |  4 ++++
 3 files changed, 17 insertions(+), 4 deletions(-)

-- 
2.30.2


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

* [PATCH v4 1/2] kni: use dedicated function to set random MAC address
  2022-06-08 11:13 ` [PATCH v4 0/2] kni: fix build warnings with Linux 5.17+ Andrew Rybchenko
@ 2022-06-08 11:13   ` Andrew Rybchenko
  2022-06-08 11:13   ` [PATCH v4 2/2] kni: fix warning about discarding const qualifier Andrew Rybchenko
  1 sibling, 0 replies; 17+ messages in thread
From: Andrew Rybchenko @ 2022-06-08 11:13 UTC (permalink / raw)
  To: Ferruh Yigit, Stephen Hemminger; +Cc: dev, Min Hu, Ke Zhang, stable

From: Ke Zhang <ke1x.zhang@intel.com>

eth_hw_addr_random() sets address type correctly.

eth_hw_addr_random() is available since Linux v3.4, so
no compat is required.

Also fix the warning:
warning: passing argument 1 of ‘memcpy’ discards ‘const’
qualifier from pointer target type

Variable dev_addr is done const intentionally in Linux v5.17 to
prevent using it directly.

Fixes: ea6b39b5b847 ("kni: remove ethtool support")
Cc: stable@dpdk.org

Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 kernel/linux/kni/kni_misc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
index 780187d8bf..4f6dd373a3 100644
--- a/kernel/linux/kni/kni_misc.c
+++ b/kernel/linux/kni/kni_misc.c
@@ -405,8 +405,8 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 	if (is_valid_ether_addr(dev_info.mac_addr))
 		memcpy(net_dev->dev_addr, dev_info.mac_addr, ETH_ALEN);
 	else
-		/* Generate random MAC address. */
-		eth_random_addr(net_dev->dev_addr);
+		/* Assign random MAC address. */
+		eth_hw_addr_random(net_dev);
 
 	if (dev_info.mtu)
 		net_dev->mtu = dev_info.mtu;
-- 
2.30.2


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

* [PATCH v4 2/2] kni: fix warning about discarding const qualifier
  2022-06-08 11:13 ` [PATCH v4 0/2] kni: fix build warnings with Linux 5.17+ Andrew Rybchenko
  2022-06-08 11:13   ` [PATCH v4 1/2] kni: use dedicated function to set random MAC address Andrew Rybchenko
@ 2022-06-08 11:13   ` Andrew Rybchenko
  1 sibling, 0 replies; 17+ messages in thread
From: Andrew Rybchenko @ 2022-06-08 11:13 UTC (permalink / raw)
  To: Ferruh Yigit, Stephen Hemminger; +Cc: dev, Min Hu, Ke Zhang, stable

From: Ke Zhang <ke1x.zhang@intel.com>

The warning info:
warning: passing argument 1 of ‘memcpy’ discards ‘const’
qualifier from pointer target type

Variable dev_addr is done const intentionally in v5.17 to prevent using
it directly. See kernel series [1] for more information.

[1] https://lore.kernel.org/netdev/YZYAb4X%2FVQFy0iks@shredder/T/

Fixes: ea6b39b5b847 ("kni: remove ethtool support")
Cc: stable@dpdk.org

Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 kernel/linux/kni/compat.h   | 4 ++++
 kernel/linux/kni/kni_misc.c | 9 +++++++--
 kernel/linux/kni/kni_net.c  | 4 ++++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/kernel/linux/kni/compat.h b/kernel/linux/kni/compat.h
index 0db29a4a6f..2c8f346ddf 100644
--- a/kernel/linux/kni/compat.h
+++ b/kernel/linux/kni/compat.h
@@ -145,3 +145,7 @@
 #if KERNEL_VERSION(5, 18, 0) > LINUX_VERSION_CODE
 #define HAVE_NETIF_RX_NI
 #endif
+
+#if KERNEL_VERSION(5, 15, 0) <= LINUX_VERSION_CODE
+#define HAVE_ETH_HW_ADDR_SET
+#endif
diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
index 4f6dd373a3..0c3a86ee35 100644
--- a/kernel/linux/kni/kni_misc.c
+++ b/kernel/linux/kni/kni_misc.c
@@ -402,11 +402,16 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 	pr_debug("mbuf_size:    %u\n", kni->mbuf_size);
 
 	/* if user has provided a valid mac address */
-	if (is_valid_ether_addr(dev_info.mac_addr))
+	if (is_valid_ether_addr(dev_info.mac_addr)) {
+#ifdef HAVE_ETH_HW_ADDR_SET
+		eth_hw_addr_set(net_dev, dev_info.mac_addr);
+#else
 		memcpy(net_dev->dev_addr, dev_info.mac_addr, ETH_ALEN);
-	else
+#endif
+	} else {
 		/* Assign random MAC address. */
 		eth_hw_addr_random(net_dev);
+	}
 
 	if (dev_info.mtu)
 		net_dev->mtu = dev_info.mtu;
diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
index 41805fcabf..6257dcb1a8 100644
--- a/kernel/linux/kni/kni_net.c
+++ b/kernel/linux/kni/kni_net.c
@@ -783,7 +783,11 @@ kni_net_set_mac(struct net_device *netdev, void *p)
 		return -EADDRNOTAVAIL;
 
 	memcpy(req.mac_addr, addr->sa_data, netdev->addr_len);
+#ifdef HAVE_ETH_HW_ADDR_SET
+	eth_hw_addr_set(net_dev, addr->sa_data);
+#else
 	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
+#endif
 
 	ret = kni_net_process_request(netdev, &req);
 
-- 
2.30.2


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

* [PATCH v5 0/2] kni: fix build warnings with Linux 5.17+
  2022-05-31  9:13 [PATCH] examples/kni: clear warning about discarding const qualifier Ke Zhang
                   ` (3 preceding siblings ...)
  2022-06-08 11:13 ` [PATCH v4 0/2] kni: fix build warnings with Linux 5.17+ Andrew Rybchenko
@ 2022-06-08 12:11 ` Andrew Rybchenko
  2022-06-08 12:11   ` [PATCH v5 1/2] kni: use dedicated function to set random MAC address Andrew Rybchenko
                     ` (2 more replies)
  4 siblings, 3 replies; 17+ messages in thread
From: Andrew Rybchenko @ 2022-06-08 12:11 UTC (permalink / raw)
  To: Ferruh Yigit, Stephen Hemminger; +Cc: dev, Min Hu, Ke Zhang

v5:
    - fix broken build

v4:
    - restore original patch author
    - resend with cover letter to address patchwork recognition as a
      series

v3:
    - split single patch into two
    - clarify patches summary and description

Ke Zhang (2):
  kni: use dedicated function to set random MAC address
  kni: fix warning about discarding const qualifier

 kernel/linux/kni/compat.h   |  4 ++++
 kernel/linux/kni/kni_misc.c | 13 +++++++++----
 kernel/linux/kni/kni_net.c  |  4 ++++
 3 files changed, 17 insertions(+), 4 deletions(-)

-- 
2.30.2


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

* [PATCH v5 1/2] kni: use dedicated function to set random MAC address
  2022-06-08 12:11 ` [PATCH v5 0/2] kni: fix build warnings with Linux 5.17+ Andrew Rybchenko
@ 2022-06-08 12:11   ` Andrew Rybchenko
  2022-06-08 12:52     ` Ferruh Yigit
  2022-06-08 12:11   ` [PATCH v5 2/2] kni: fix warning about discarding const qualifier Andrew Rybchenko
  2022-06-08 17:23   ` [PATCH v5 0/2] kni: fix build warnings with Linux 5.17+ Andrew Rybchenko
  2 siblings, 1 reply; 17+ messages in thread
From: Andrew Rybchenko @ 2022-06-08 12:11 UTC (permalink / raw)
  To: Ferruh Yigit, Stephen Hemminger; +Cc: dev, Min Hu, Ke Zhang, stable

From: Ke Zhang <ke1x.zhang@intel.com>

eth_hw_addr_random() sets address type correctly.

eth_hw_addr_random() is available since Linux v3.4, so
no compat is required.

Also fix the warning:
warning: passing argument 1 of ‘memcpy’ discards ‘const’
qualifier from pointer target type

Variable dev_addr is done const intentionally in Linux v5.17 to
prevent using it directly.

Fixes: ea6b39b5b847 ("kni: remove ethtool support")
Cc: stable@dpdk.org

Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 kernel/linux/kni/kni_misc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
index 780187d8bf..4f6dd373a3 100644
--- a/kernel/linux/kni/kni_misc.c
+++ b/kernel/linux/kni/kni_misc.c
@@ -405,8 +405,8 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 	if (is_valid_ether_addr(dev_info.mac_addr))
 		memcpy(net_dev->dev_addr, dev_info.mac_addr, ETH_ALEN);
 	else
-		/* Generate random MAC address. */
-		eth_random_addr(net_dev->dev_addr);
+		/* Assign random MAC address. */
+		eth_hw_addr_random(net_dev);
 
 	if (dev_info.mtu)
 		net_dev->mtu = dev_info.mtu;
-- 
2.30.2


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

* [PATCH v5 2/2] kni: fix warning about discarding const qualifier
  2022-06-08 12:11 ` [PATCH v5 0/2] kni: fix build warnings with Linux 5.17+ Andrew Rybchenko
  2022-06-08 12:11   ` [PATCH v5 1/2] kni: use dedicated function to set random MAC address Andrew Rybchenko
@ 2022-06-08 12:11   ` Andrew Rybchenko
  2022-06-08 12:54     ` Ferruh Yigit
  2022-06-08 17:23   ` [PATCH v5 0/2] kni: fix build warnings with Linux 5.17+ Andrew Rybchenko
  2 siblings, 1 reply; 17+ messages in thread
From: Andrew Rybchenko @ 2022-06-08 12:11 UTC (permalink / raw)
  To: Ferruh Yigit, Stephen Hemminger; +Cc: dev, Min Hu, Ke Zhang, stable

From: Ke Zhang <ke1x.zhang@intel.com>

The warning info:
warning: passing argument 1 of ‘memcpy’ discards ‘const’
qualifier from pointer target type

Variable dev_addr is done const intentionally in v5.17 to prevent using
it directly. See kernel series [1] for more information.

[1] https://lore.kernel.org/netdev/YZYAb4X%2FVQFy0iks@shredder/T/

Fixes: ea6b39b5b847 ("kni: remove ethtool support")
Cc: stable@dpdk.org

Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 kernel/linux/kni/compat.h   | 4 ++++
 kernel/linux/kni/kni_misc.c | 9 +++++++--
 kernel/linux/kni/kni_net.c  | 4 ++++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/kernel/linux/kni/compat.h b/kernel/linux/kni/compat.h
index 0db29a4a6f..2c8f346ddf 100644
--- a/kernel/linux/kni/compat.h
+++ b/kernel/linux/kni/compat.h
@@ -145,3 +145,7 @@
 #if KERNEL_VERSION(5, 18, 0) > LINUX_VERSION_CODE
 #define HAVE_NETIF_RX_NI
 #endif
+
+#if KERNEL_VERSION(5, 15, 0) <= LINUX_VERSION_CODE
+#define HAVE_ETH_HW_ADDR_SET
+#endif
diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
index 4f6dd373a3..0c3a86ee35 100644
--- a/kernel/linux/kni/kni_misc.c
+++ b/kernel/linux/kni/kni_misc.c
@@ -402,11 +402,16 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 	pr_debug("mbuf_size:    %u\n", kni->mbuf_size);
 
 	/* if user has provided a valid mac address */
-	if (is_valid_ether_addr(dev_info.mac_addr))
+	if (is_valid_ether_addr(dev_info.mac_addr)) {
+#ifdef HAVE_ETH_HW_ADDR_SET
+		eth_hw_addr_set(net_dev, dev_info.mac_addr);
+#else
 		memcpy(net_dev->dev_addr, dev_info.mac_addr, ETH_ALEN);
-	else
+#endif
+	} else {
 		/* Assign random MAC address. */
 		eth_hw_addr_random(net_dev);
+	}
 
 	if (dev_info.mtu)
 		net_dev->mtu = dev_info.mtu;
diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
index 41805fcabf..779ee3451a 100644
--- a/kernel/linux/kni/kni_net.c
+++ b/kernel/linux/kni/kni_net.c
@@ -783,7 +783,11 @@ kni_net_set_mac(struct net_device *netdev, void *p)
 		return -EADDRNOTAVAIL;
 
 	memcpy(req.mac_addr, addr->sa_data, netdev->addr_len);
+#ifdef HAVE_ETH_HW_ADDR_SET
+	eth_hw_addr_set(netdev, addr->sa_data);
+#else
 	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
+#endif
 
 	ret = kni_net_process_request(netdev, &req);
 
-- 
2.30.2


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

* Re: [PATCH v5 1/2] kni: use dedicated function to set random MAC address
  2022-06-08 12:11   ` [PATCH v5 1/2] kni: use dedicated function to set random MAC address Andrew Rybchenko
@ 2022-06-08 12:52     ` Ferruh Yigit
  0 siblings, 0 replies; 17+ messages in thread
From: Ferruh Yigit @ 2022-06-08 12:52 UTC (permalink / raw)
  To: Andrew Rybchenko, Stephen Hemminger; +Cc: dev, Min Hu, Ke Zhang, stable

On 6/8/2022 1:11 PM, Andrew Rybchenko wrote:
> From: Ke Zhang <ke1x.zhang@intel.com>
> 
> eth_hw_addr_random() sets address type correctly.
> 
> eth_hw_addr_random() is available since Linux v3.4, so
> no compat is required.
> 
> Also fix the warning:
> warning: passing argument 1 of ‘memcpy’ discards ‘const’
> qualifier from pointer target type
> 
> Variable dev_addr is done const intentionally in Linux v5.17 to
> prevent using it directly.
> 
> Fixes: ea6b39b5b847 ("kni: remove ethtool support")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>
> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>

Acked-by: Ferruh Yigit <ferruh.yigit@xilinx.com>

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

* Re: [PATCH v5 2/2] kni: fix warning about discarding const qualifier
  2022-06-08 12:11   ` [PATCH v5 2/2] kni: fix warning about discarding const qualifier Andrew Rybchenko
@ 2022-06-08 12:54     ` Ferruh Yigit
  2022-06-08 13:10       ` Ferruh Yigit
  0 siblings, 1 reply; 17+ messages in thread
From: Ferruh Yigit @ 2022-06-08 12:54 UTC (permalink / raw)
  To: Andrew Rybchenko, Stephen Hemminger; +Cc: dev, Min Hu, Ke Zhang, stable

On 6/8/2022 1:11 PM, Andrew Rybchenko wrote:

> 
> From: Ke Zhang <ke1x.zhang@intel.com>
> 
> The warning info:
> warning: passing argument 1 of ‘memcpy’ discards ‘const’
> qualifier from pointer target type
> 
> Variable dev_addr is done const intentionally in v5.17 to prevent using
> it directly. See kernel series [1] for more information.
> 
> [1] https://lore.kernel.org/netdev/YZYAb4X%2FVQFy0iks@shredder/T/

Can you add Linux kernel commit log, instead of the mail list archive? 
This helps to check the relevant code change in kernel easier, and 
verify in which versions it exists etc..

> 
> Fixes: ea6b39b5b847 ("kni: remove ethtool support")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>
> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>

Acked-by: Ferruh Yigit <ferruh.yigit@xilinx.com>


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

* Re: [PATCH v5 2/2] kni: fix warning about discarding const qualifier
  2022-06-08 12:54     ` Ferruh Yigit
@ 2022-06-08 13:10       ` Ferruh Yigit
  0 siblings, 0 replies; 17+ messages in thread
From: Ferruh Yigit @ 2022-06-08 13:10 UTC (permalink / raw)
  To: Andrew Rybchenko, Stephen Hemminger; +Cc: dev, Min Hu, Ke Zhang, stable

On 6/8/2022 1:54 PM, Ferruh Yigit wrote:
> On 6/8/2022 1:11 PM, Andrew Rybchenko wrote:
> 
>>
>> From: Ke Zhang <ke1x.zhang@intel.com>
>>
>> The warning info:
>> warning: passing argument 1 of ‘memcpy’ discards ‘const’
>> qualifier from pointer target type
>>
>> Variable dev_addr is done const intentionally in v5.17 to prevent using
>> it directly. See kernel series [1] for more information.

`dev_addr` is done const in v5.17,
but patch checks >= v5.15 because used helpers introduced in v5.15, 
should this be clarified to not confuse users? No strong opinion from me.

>>
>> [1] https://lore.kernel.org/netdev/YZYAb4X%2FVQFy0iks@shredder/T/
> 
> Can you add Linux kernel commit log, instead of the mail list archive? 
> This helps to check the relevant code change in kernel easier, and 
> verify in which versions it exists etc..
> 

I think mentioned commit is following
Commit adeef3e32146 ("net: constify netdev->dev_addr")

>>
>> Fixes: ea6b39b5b847 ("kni: remove ethtool support")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>
>> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> 
> Acked-by: Ferruh Yigit <ferruh.yigit@xilinx.com>
> 


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

* Re: [PATCH v5 0/2] kni: fix build warnings with Linux 5.17+
  2022-06-08 12:11 ` [PATCH v5 0/2] kni: fix build warnings with Linux 5.17+ Andrew Rybchenko
  2022-06-08 12:11   ` [PATCH v5 1/2] kni: use dedicated function to set random MAC address Andrew Rybchenko
  2022-06-08 12:11   ` [PATCH v5 2/2] kni: fix warning about discarding const qualifier Andrew Rybchenko
@ 2022-06-08 17:23   ` Andrew Rybchenko
  2 siblings, 0 replies; 17+ messages in thread
From: Andrew Rybchenko @ 2022-06-08 17:23 UTC (permalink / raw)
  To: Ferruh Yigit, Stephen Hemminger; +Cc: dev, Min Hu, Ke Zhang

On 6/8/22 15:11, Andrew Rybchenko wrote:
> v5:
>      - fix broken build
> 
> v4:
>      - restore original patch author
>      - resend with cover letter to address patchwork recognition as a
>        series
> 
> v3:
>      - split single patch into two
>      - clarify patches summary and description
> 
> Ke Zhang (2):
>    kni: use dedicated function to set random MAC address
>    kni: fix warning about discarding const qualifier
> 
>   kernel/linux/kni/compat.h   |  4 ++++
>   kernel/linux/kni/kni_misc.c | 13 +++++++++----
>   kernel/linux/kni/kni_net.c  |  4 ++++
>   3 files changed, 17 insertions(+), 4 deletions(-)
> 

With review notes from Ferruh processed applied to dpdk-next-net/main.

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

* [PATCH v2] examples/kni: clear warning about discarding const qualifier
@ 2022-06-01  3:24 Ke Zhang
  0 siblings, 0 replies; 17+ messages in thread
From: Ke Zhang @ 2022-06-01  3:24 UTC (permalink / raw)
  To: ferruh.yigit, dev; +Cc: Ke Zhang, stable

The warning info:
warning: passing argument 1 of ‘memcpy’ discards ‘const’
qualifier from pointer target type

Variable is done const intentionally to prevent using it
directly, using the new helper functions :
'eth_hw_addr_set()' and 'eth_hw_addr_random()'

Fixes: ea6b39b5b847 ("kni: remove ethtool support")
Cc: stable@dpdk.org

Signed-off-by: Ke Zhang <ke1x.zhang@intel.com>
---
 kernel/linux/kni/kni_misc.c | 4 ++--
 kernel/linux/kni/kni_net.c  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/linux/kni/kni_misc.c b/kernel/linux/kni/kni_misc.c
index 780187d8bf..1da8e812b7 100644
--- a/kernel/linux/kni/kni_misc.c
+++ b/kernel/linux/kni/kni_misc.c
@@ -403,10 +403,10 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 
 	/* if user has provided a valid mac address */
 	if (is_valid_ether_addr(dev_info.mac_addr))
-		memcpy(net_dev->dev_addr, dev_info.mac_addr, ETH_ALEN);
+		eth_hw_addr_set(net_dev, dev_info.mac_addr);
 	else
 		/* Generate random MAC address. */
-		eth_random_addr(net_dev->dev_addr);
+		eth_hw_addr_random(net_dev);
 
 	if (dev_info.mtu)
 		net_dev->mtu = dev_info.mtu;
diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
index 29e5b9e21f..1da4f836aa 100644
--- a/kernel/linux/kni/kni_net.c
+++ b/kernel/linux/kni/kni_net.c
@@ -779,7 +779,7 @@ kni_net_set_mac(struct net_device *netdev, void *p)
 		return -EADDRNOTAVAIL;
 
 	memcpy(req.mac_addr, addr->sa_data, netdev->addr_len);
-	memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
+	eth_hw_addr_set(netdev, addr->sa_data);
 
 	ret = kni_net_process_request(netdev, &req);
 
-- 
2.25.1


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

end of thread, other threads:[~2022-06-08 17:23 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-31  9:13 [PATCH] examples/kni: clear warning about discarding const qualifier Ke Zhang
2022-05-31 14:55 ` Stephen Hemminger
2022-06-01  5:45 ` [PATCH v2] " Ke Zhang
2022-06-01 15:44   ` Ferruh Yigit
2022-06-05  9:47 ` [PATCH v3 1/2] kni: use dedicated function to set random MAC address Andrew Rybchenko
2022-06-05  9:47   ` [PATCH v3 2/2] kni: fix warning about discarding const qualifier Andrew Rybchenko
2022-06-08 11:13 ` [PATCH v4 0/2] kni: fix build warnings with Linux 5.17+ Andrew Rybchenko
2022-06-08 11:13   ` [PATCH v4 1/2] kni: use dedicated function to set random MAC address Andrew Rybchenko
2022-06-08 11:13   ` [PATCH v4 2/2] kni: fix warning about discarding const qualifier Andrew Rybchenko
2022-06-08 12:11 ` [PATCH v5 0/2] kni: fix build warnings with Linux 5.17+ Andrew Rybchenko
2022-06-08 12:11   ` [PATCH v5 1/2] kni: use dedicated function to set random MAC address Andrew Rybchenko
2022-06-08 12:52     ` Ferruh Yigit
2022-06-08 12:11   ` [PATCH v5 2/2] kni: fix warning about discarding const qualifier Andrew Rybchenko
2022-06-08 12:54     ` Ferruh Yigit
2022-06-08 13:10       ` Ferruh Yigit
2022-06-08 17:23   ` [PATCH v5 0/2] kni: fix build warnings with Linux 5.17+ Andrew Rybchenko
2022-06-01  3:24 [PATCH v2] examples/kni: clear warning about discarding const qualifier Ke Zhang

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).