DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] examples/kni: clear warning about discarding const qualifier
@ 2022-05-31  8:13 Ke Zhang
  2022-05-31  9:12 ` Bruce Richardson
  2022-06-06  7:22 ` [PATCH v3] kni: fix " Ke Zhang
  0 siblings, 2 replies; 6+ messages in thread
From: Ke Zhang @ 2022-05-31  8: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 ++--
 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..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;
-- 
2.25.1


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

* Re: [PATCH] examples/kni: clear warning about discarding const qualifier
  2022-05-31  8:13 [PATCH] examples/kni: clear warning about discarding const qualifier Ke Zhang
@ 2022-05-31  9:12 ` Bruce Richardson
  2022-05-31  9:22   ` Ferruh Yigit
  2022-06-06  7:22 ` [PATCH v3] kni: fix " Ke Zhang
  1 sibling, 1 reply; 6+ messages in thread
From: Bruce Richardson @ 2022-05-31  9:12 UTC (permalink / raw)
  To: Ke Zhang; +Cc: ferruh.yigit, dev, stephen

On Tue, May 31, 2022 at 08:13:04AM +0000, Ke Zhang 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>
> ---
>  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..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;

+Stephen H on CC, for his advice

This fix seems wrong to do. Given that it's a pointer to const char* rather
than an actual array in the structure, is a better fix not to point the
pointer to a new area of memory rather than trying to overwrite the old
one?

/Bruce

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

* Re: [PATCH] examples/kni: clear warning about discarding const qualifier
  2022-05-31  9:12 ` Bruce Richardson
@ 2022-05-31  9:22   ` Ferruh Yigit
  0 siblings, 0 replies; 6+ messages in thread
From: Ferruh Yigit @ 2022-05-31  9:22 UTC (permalink / raw)
  To: Bruce Richardson, Ke Zhang; +Cc: dev, stephen

On 5/31/2022 10:12 AM, Bruce Richardson wrote:
> [CAUTION: External Email]
> 
> On Tue, May 31, 2022 at 08:13:04AM +0000, Ke Zhang 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>
>> ---
>>   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..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;
> 
> +Stephen H on CC, for his advice
> 
> This fix seems wrong to do. Given that it's a pointer to const char* rather
> than an actual array in the structure, is a better fix not to point the
> pointer to a new area of memory rather than trying to overwrite the old
> one?
> 

Agree that this is not proper fix.

Variable seems done const intentionally to prevent using it directly,
there are new helper functions like 'eth_hw_addr_set()', 
'eth_hw_addr_random()', .. to use with newer kernel versions.

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

* [PATCH v3] kni: fix warning about discarding const qualifier
  2022-05-31  8:13 [PATCH] examples/kni: clear warning about discarding const qualifier Ke Zhang
  2022-05-31  9:12 ` Bruce Richardson
@ 2022-06-06  7:22 ` Ke Zhang
  1 sibling, 0 replies; 6+ messages in thread
From: Ke Zhang @ 2022-06-06  7:22 UTC (permalink / raw)
  To: ferruh.yigit, dev; +Cc: Ke Zhang, stable, Andrew Rybchenko

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 | 6 +++++-
 kernel/linux/kni/kni_net.c  | 5 ++++-
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/kernel/linux/kni/compat.h b/kernel/linux/kni/compat.h
index 664785674f..ef1526ef85 100644
--- a/kernel/linux/kni/compat.h
+++ b/kernel/linux/kni/compat.h
@@ -141,3 +141,7 @@
 #if KERNEL_VERSION(5, 9, 0) > LINUX_VERSION_CODE
 #define HAVE_TSK_IN_GUP
 #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 780187d8bf..11fea961b3 100644
--- a/kernel/linux/kni/kni_misc.c
+++ b/kernel/linux/kni/kni_misc.c
@@ -403,10 +403,14 @@ 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))
+#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);
+#endif
 	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..496ce7e4ae 100644
--- a/kernel/linux/kni/kni_net.c
+++ b/kernel/linux/kni/kni_net.c
@@ -779,8 +779,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);
 
 	return (ret == 0 ? req.result : ret);
-- 
2.25.1


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

* Re: [PATCH] examples/kni: clear warning about discarding const qualifier
  2022-05-31  9:13 [PATCH] examples/kni: clear " Ke Zhang
@ 2022-05-31 14:55 ` Stephen Hemminger
  0 siblings, 0 replies; 6+ 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] 6+ messages in thread

* [PATCH] examples/kni: clear warning about discarding const qualifier
@ 2022-05-31  9:13 Ke Zhang
  2022-05-31 14:55 ` Stephen Hemminger
  0 siblings, 1 reply; 6+ 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] 6+ messages in thread

end of thread, other threads:[~2022-06-06  7:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-31  8:13 [PATCH] examples/kni: clear warning about discarding const qualifier Ke Zhang
2022-05-31  9:12 ` Bruce Richardson
2022-05-31  9:22   ` Ferruh Yigit
2022-06-06  7:22 ` [PATCH v3] kni: fix " Ke Zhang
2022-05-31  9:13 [PATCH] examples/kni: clear " Ke Zhang
2022-05-31 14:55 ` Stephen Hemminger

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