Re: [PATCH] net: ethernet: Fixe issue in nvmem_get_mac_address() where invalid mac addresses

From: Ozgur Kara
Date: Thu May 08 2025 - 09:58:54 EST


Andrew Lunn <andrew@xxxxxxx>, 8 May 2025 Per, 16:49 tarihinde şunu yazdı:
>
> On Thu, May 08, 2025 at 12:37:40PM +0000, Ozgur Kara wrote:
> > Andrew Lunn <andrew@xxxxxxx>, 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@xxxxxxxxxx>
> > > >
> > > > 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.
>

Hello Andrew,

okay, now i understand so since mac is already of type const void *
and kfree() is already wait a parameter of type of const void * and
cast was also wrong.
I understand, I will review eth.c code better.

Regards

Ozgur

> Andrew
>
>