[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <084249630536437997a58d32ea61bd38@sphcmbx02.sunplus.com.tw>
Date: Wed, 3 Nov 2021 15:11:02 +0000
From: Wells Lu 呂芳騰 <wells.lu@...plus.com>
To: Philipp Zabel <p.zabel@...gutronix.de>,
Wells Lu <wellslutw@...il.com>,
"davem@...emloft.net" <davem@...emloft.net>,
"kuba@...nel.org" <kuba@...nel.org>,
"robh+dt@...nel.org" <robh+dt@...nel.org>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"devicetree@...r.kernel.org" <devicetree@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH 2/2] net: ethernet: Add driver for Sunplus SP7021
Thanks a lot for your review.
> From: Philipp Zabel <p.zabel@...gutronix.de>
> Sent: Wednesday, November 3, 2021 8:10 PM
> To: Wells Lu <wellslutw@...il.com>; davem@...emloft.net;
> kuba@...nel.org; robh+dt@...nel.org; netdev@...r.kernel.org;
> devicetree@...r.kernel.org; linux-kernel@...r.kernel.org
> Cc: Wells Lu 呂芳騰 <wells.lu@...plus.com>
> Subject: Re: [PATCH 2/2] net: ethernet: Add driver for Sunplus SP7021
>
> On Wed, 2021-11-03 at 19:02 +0800, Wells Lu wrote:
> [...]
> > diff --git a/drivers/net/ethernet/sunplus/l2sw_driver.c
> > b/drivers/net/ethernet/sunplus/l2sw_driver.c
> > new file mode 100644
> > index 0000000..3dfd0dd
> > --- /dev/null
> > +++ b/drivers/net/ethernet/sunplus/l2sw_driver.c
> > @@ -0,0 +1,779 @@
> [...]
> > +static int l2sw_probe(struct platform_device *pdev) {
> > + struct l2sw_common *comm;
> > + struct resource *r_mem;
> > + struct net_device *net_dev, *net_dev2;
> > + struct l2sw_mac *mac, *mac2;
> > + u32 mode;
> > + int ret = 0;
> > + int rc;
> > +
> > + if (platform_get_drvdata(pdev))
> > + return -ENODEV;
> > +
> > + // Allocate memory for l2sw 'common' area.
> > + comm = kmalloc(sizeof(*comm), GFP_KERNEL);
>
> I'd use devm_kzalloc() here for initialization and to simplify the cleanup
> path.
I'll replace kmalloc() with devm_kzalloc() and remove the kfree(...) in
cleanup path (platform remove) in PATCH v2.
> > + if (!comm)
> > + return -ENOMEM;
> > + pr_debug(" comm = %p\n", comm);
>
> What is this useful for?
'pr_debug(" comm = %p\n", comm);' is for early-stage debug.
I'll remove the line in PATCH v2.
> > + memset(comm, '\0', sizeof(struct l2sw_common));
>
> Not needed with kzalloc, See above.
Yes, I'll remove the line 'memset(...);' as devm_kzalloc() will be used in PATCH v2.
> [...]
> > + // Get memory resoruce 0 from dts.
> > + r_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > + if (r_mem) {
> > + pr_debug(" res->name = \"%s\", r_mem->start = %pa\n",
> r_mem->name, &r_mem->start);
> > + if (l2sw_reg_base_set(devm_ioremap(&pdev->dev, r_mem->start,
> > + (r_mem->end - r_mem->start + 1))) != 0) {
> > + pr_err(" ioremap failed!\n");
> > + ret = -ENOMEM;
> > + goto out_free_comm;
> > + }
> > + } else {
> > + pr_err(" No MEM resource 0 found!\n");
> > + ret = -ENXIO;
> > + goto out_free_comm;
> > + }
> > +
> > + // Get memory resoruce 1 from dts.
> > + r_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> > + if (r_mem) {
> > + pr_debug(" res->name = \"%s\", r_mem->start = %pa\n",
> r_mem->name, &r_mem->start);
> > + if (moon5_reg_base_set(devm_ioremap(&pdev->dev,
> r_mem->start,
> > + (r_mem->end - r_mem->start + 1))) != 0) {
> > + pr_err(" ioremap failed!\n");
> > + ret = -ENOMEM;
> > + goto out_free_comm;
> > + }
> > + } else {
> > + pr_err(" No MEM resource 1 found!\n");
> > + ret = -ENXIO;
> > + goto out_free_comm;
> > + }
>
> Using devm_ioremap_resource() would simplify both a lot.
Yes, I'll replace devm_ioremap() with devm_ioremap_resource() in PATCH v2.
> [...]
> > + comm->rstc = devm_reset_control_get(&pdev->dev, NULL);
>
> Please use devm_reset_control_get_exclusive().
Yes, I'll replace devm_reset_control_get() with devm_reset_control_get_exclusive() in PATCH v2.
> > + if (IS_ERR(comm->rstc)) {
> > + dev_err(&pdev->dev, "Failed to retrieve reset controller!\n");
> > + ret = PTR_ERR(comm->rstc);
> > + goto out_free_comm;
> > + }
> > +
> > + // Enable clock.
> > + clk_prepare_enable(comm->clk);
> > + udelay(1);
> > +
> > + ret = reset_control_assert(comm->rstc);
>
> No need to assign to ret if you ignore it anyway.
Ok, I'll remove 'ret =' in PATCH v2
> > + udelay(1);
> > + ret = reset_control_deassert(comm->rstc);
> > + if (ret) {
> > + dev_err(&pdev->dev, "Failed to deassert reset line (err = %d)!\n",
> ret);
> > + ret = -ENODEV;
> > + goto out_free_comm;
> > + }
> > + udelay(1);
>
> regards
> Philipp
Best regards,
Wells
Powered by blists - more mailing lists