[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <2dce66e0-2a06-46bb-b1a2-cb5be1756fbd@lunn.ch>
Date: Thu, 8 May 2025 15:49:50 +0200
From: Andrew Lunn <andrew@...n.ch>
To: Ozgur Kara <ozgur@...sey.org>
Cc: "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>, netdev@...r.kernel.org,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Simon Horman <horms@...nel.org>,
Nikolay Aleksandrov <razor@...ckwall.org>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] net: ethernet: Fixe issue in nvmem_get_mac_address()
where invalid mac addresses
On Thu, May 08, 2025 at 12:37:40PM +0000, Ozgur Kara wrote:
> Andrew Lunn <andrew@...n.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@...sey.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
Powered by blists - more mailing lists