Subject: Re: [PATCHv3 net-next] net: modernize ioremap in probe

From: Niklas Söderlund <[email-masked]>
Date: Tue, 19 Nov 2024 21:39:16 +0100

On 2024-11-17 15:07:53 -0800, Rosen Penev wrote:
> On Sun, Nov 17, 2024 at 2:38 PM Niklas Söderlund
> <[email-masked]> wrote:
> >
> > Hello Rosen,
> >
> > Thanks for your work.
> >
> > On 2024-11-17 13:27:11 -0800, Rosen Penev wrote:
> >
> > > diff --git a/drivers/net/ethernet/renesas/rtsn.c
> > > b/drivers/net/ethernet/renesas/rtsn.c
> > > index 6b3f7fca8d15..bfe08facc707 100644
> > > --- a/drivers/net/ethernet/renesas/rtsn.c
> > > +++ b/drivers/net/ethernet/renesas/rtsn.c
> > > @@ -1297,14 +1297,8 @@ static int rtsn_probe(struct platform_device *pdev)
> > >       ndev->netdev_ops = &rtsn_netdev_ops;
> > >       ndev->ethtool_ops = &rtsn_ethtool_ops;
> > >
> > > -     res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "gptp");
> > > -     if (!res) {
> > > -             dev_err(&pdev->dev, "Can't find gptp resource\n");
> > > -             ret = -EINVAL;
> > > -             goto error_free;
> > > -     }
> > > -
> > > -     priv->ptp_priv->addr = devm_ioremap_resource(&pdev->dev, res);
> > > +     priv->ptp_priv->addr =
> > > +             devm_platform_ioremap_resource_byname(pdev, "gptp");
> > >       if (IS_ERR(priv->ptp_priv->addr)) {
> > >               ret = PTR_ERR(priv->ptp_priv->addr);
> > >               goto error_free;
> >
> > You have a similar construct using platform_get_resource_byname() a few
> > lines above this one. Please convert both uses, or none, mixing them is
> > just confusing IMHO.
> that cannot be converted.
> 
> devm_platform_ioremap_resource_byname has no res parameter, which is a
> problem as there's this lovely line below it.
> 
> ndev->base_addr = res->start;

I see, maybe we can refactor that too? I see not all drivers set 
base_addr, and some even set it to the remapped memory returned by 
devm_platform_ioremap_resource_byname() or such.

The documentation for this field is not crystal clear for me and it is 
marked with a FIXME in the definition.

struct net_device {

	...

	/*
	 *	I/O specific fields
	 *	FIXME: Merge these and struct ifmap into one
	 */
	unsigned long		mem_end;
	unsigned long		mem_start;
	unsigned long		base_addr;

	...

> > --
> > Kind Regards,
> > Niklas Söderlund

-- 
Kind Regards,
Niklas Söderlund