From: Ferruh Yigit <ferruh.yigit@xilinx.com>
To: Bruce Richardson <bruce.richardson@intel.com>,
Ke Zhang <ke1x.zhang@intel.com>
Cc: <dev@dpdk.org>, <stephen@networkplumber.org>
Subject: Re: [PATCH] examples/kni: clear warning about discarding const qualifier
Date: Tue, 31 May 2022 10:22:44 +0100 [thread overview]
Message-ID: <8f8e001c-168e-0bb0-65b3-9f4ad9c94716@xilinx.com> (raw)
In-Reply-To: <YpXcADhH6t3MGHSz@bricha3-MOBL.ger.corp.intel.com>
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.
next prev parent reply other threads:[~2022-05-31 9:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-31 8:13 Ke Zhang
2022-05-31 9:12 ` Bruce Richardson
2022-05-31 9:22 ` Ferruh Yigit [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8f8e001c-168e-0bb0-65b3-9f4ad9c94716@xilinx.com \
--to=ferruh.yigit@xilinx.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=ke1x.zhang@intel.com \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).