[v5,2/2] kni: fix warning about discarding const qualifier

Message ID 20220608121117.1445731-3-andrew.rybchenko@oktetlabs.ru (mailing list archive)
State Accepted, archived
Delegated to: Andrew Rybchenko
Headers
Series kni: fix build warnings with Linux 5.17+ |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Andrew Rybchenko June 8, 2022, 12:11 p.m. UTC
  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(-)
  

Comments

Ferruh Yigit June 8, 2022, 12:54 p.m. UTC | #1
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>
  
Ferruh Yigit June 8, 2022, 1:10 p.m. UTC | #2
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>
>
  

Patch

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