patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH v2] examples/kni: clear warning about discarding const qualifier
@ 2022-06-01  3:24 Ke Zhang
  0 siblings, 0 replies; 3+ 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] 3+ messages in thread

* Re: [PATCH v2] examples/kni: clear warning about discarding const qualifier
  2022-06-01  5:45 ` Ke Zhang
@ 2022-06-01 15:44   ` Ferruh Yigit
  0 siblings, 0 replies; 3+ 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] 3+ messages in thread

* [PATCH v2] examples/kni: clear warning about discarding const qualifier
       [not found] <20220531091330.230715-1-ke1x.zhang@intel.com>
@ 2022-06-01  5:45 ` Ke Zhang
  2022-06-01 15:44   ` Ferruh Yigit
  0 siblings, 1 reply; 3+ 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] 3+ messages in thread

end of thread, other threads:[~2022-06-01 15:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-01  3:24 [PATCH v2] examples/kni: clear warning about discarding const qualifier Ke Zhang
     [not found] <20220531091330.230715-1-ke1x.zhang@intel.com>
2022-06-01  5:45 ` Ke Zhang
2022-06-01 15:44   ` Ferruh Yigit

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