From: Andrew Lunn <andrew@lunn.ch>
To: Ozgur Kara <ozgur@goosey.org>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Nikolay Aleksandrov <razor@blackwall.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] net: ethernet: Fixe issue in nvmem_get_mac_address() where invalid mac addresses
Date: Thu, 8 May 2025 15:49:50 +0200 [thread overview]
Message-ID: <2dce66e0-2a06-46bb-b1a2-cb5be1756fbd@lunn.ch> (raw)
In-Reply-To: <01100196afe6cdc1-41e8d610-06b8-4e6a-bc41-d01d9844df3b-000000@eu-north-1.amazonses.com>
On Thu, May 08, 2025 at 12:37:40PM +0000, Ozgur Kara wrote:
> Andrew Lunn <andrew@lunn.ch>, 8 May 2025 Per, 15:01 tarihinde şunu yazdı:
> >
> > On Thu, May 08, 2025 at 02:14:00AM +0000, Ozgur Kara wrote:
> > > From: Ozgur Karatas <ozgur@goosey.org>
> > >
> > > it's necessary to log error returned from
> > > fwnode_property_read_u8_array because there is no detailed information
> > > when addr returns an invalid mac address.
> > >
> > > kfree(mac) should actually be marked as kfree((void *)mac) because mac
> > > pointer is of type const void * and type conversion is required so
> > > data returned from nvmem_cell_read() is of same type.
> >
> > What warning do you see from the compiler?
>
> Hello Andrew,
>
> My compiler didnt give an error to this but we had to declare that
> pointer would be used as a memory block not data and i added (void *)
> because i was hoping that mac variable would use it to safely remove
> const so expect a parameter of type void * avoid possible compiler
> incompatibilities.
> I guess, however if mac is a pointer of a different type (i guess) we
> use kfree(mac) without converting it to (void *) type compiler may
> give an error.
/**
* kfree - free previously allocated memory
* @object: pointer returned by kmalloc() or kmem_cache_alloc()
*
* If @object is NULL, no operation is performed.
*/
void kfree(const void *object)
{
So kfree() expects a const void *.
int nvmem_get_mac_address(struct device *dev, void *addrbuf)
{
struct nvmem_cell *cell;
const void *mac;
mac is a const void *
In general, casts should not be used, the indicate bad design. But the
cast you are adding appears to be wrong, which is even worse.
Andrew
next prev parent reply other threads:[~2025-05-08 13:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-08 2:14 Ozgur Kara
2025-05-08 12:01 ` Andrew Lunn
2025-05-08 12:37 ` Ozgur Kara
[not found] ` <01100196afe6cdc1-41e8d610-06b8-4e6a-bc41-d01d9844df3b-000000@eu-north-1.amazonses.com>
2025-05-08 13:49 ` Andrew Lunn [this message]
2025-05-08 13:58 ` Ozgur Kara
[not found] <01100196adabd19e-0056f10b-0ffb-4076-8a6b-779f87c327b6-000000@eu-north-1.amazonses.com>
2025-05-09 17:30 ` Simon Horman
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=2dce66e0-2a06-46bb-b1a2-cb5be1756fbd@lunn.ch \
--to=andrew@lunn.ch \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=ozgur@goosey.org \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.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
all inboxes | Powered by JetHome®