mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Wells Lu 呂芳騰" <wells.lu@sunplus.com>
To: Pavel Skripkin <paskripkin@gmail.com>,
	Wells Lu <wellslutw@gmail.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"kuba@kernel.org" <kuba@kernel.org>,
	"robh+dt@kernel.org" <robh+dt@kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"p.zabel@pengutronix.de" <p.zabel@pengutronix.de>
Subject: RE: [PATCH 2/2] net: ethernet: Add driver for Sunplus SP7021
Date: Wed, 17 Nov 2021 09:28:27 +0000	[thread overview]
Message-ID: <29c352ebf87a4ecb854c5599f5282910@sphcmbx02.sunplus.com.tw> (raw)
In-Reply-To: <52dbf9c9-0fa6-d4c6-ed6e-bba39e6e921b@gmail.com>

Hi Pavel,

> Hi, Wells!
> 
> On 11/3/21 14:02, Wells Lu wrote:
> 
> [code snip]
> 
> > +		if (comm->dual_nic) {
> > +			struct net_device *net_dev2 = mac->next_netdev;
> > +
> > +			if (!netif_running(net_dev2)) {
> > +				mac_hw_stop(mac);
> > +
> > +				mac2 = netdev_priv(net_dev2);
> > +
> 
> (*)
> 
> > +				// unregister and free net device.
> > +				unregister_netdev(net_dev2);
> > +				free_netdev(net_dev2);
> > +				mac->next_netdev = NULL;
> > +				pr_info(" Unregistered and freed net device \"eth1\"!\n");
> > +
> > +				comm->dual_nic = 0;
> > +				mac_switch_mode(mac);
> > +				rx_mode_set(net_dev);
> > +				mac_hw_addr_del(mac2);
> > +
> 
> mac2 is net_dev2 private data (*), so it will become freed after
> free_netdev() call.
> 
> FWIW the latest `smatch` should warn about this type of bugs.

Yes, this is indeed a bug.
But the code paragraph has been removed thoroughly in [PATCH v2].


> > +				// If eth0 is up, turn on lan 0 and 1 when
> > +				// switching to daisy-chain mode.
> > +				if (comm->enable & 0x1)
> > +					comm->enable = 0x3;
> 
> [code snip]
> 
> > +static int l2sw_remove(struct platform_device *pdev) {
> > +	struct net_device *net_dev;
> > +	struct net_device *net_dev2;
> > +	struct l2sw_mac *mac;
> > +
> > +	net_dev = platform_get_drvdata(pdev);
> > +	if (!net_dev)
> > +		return 0;
> > +	mac = netdev_priv(net_dev);
> > +
> > +	// Unregister and free 2nd net device.
> > +	net_dev2 = mac->next_netdev;
> > +	if (net_dev2) {
> > +		unregister_netdev(net_dev2);
> > +		free_netdev(net_dev2);
> > +	}
> > +
> 
> Is it save here to free mac->next_netdev before unregistering "parent"
> netdev? I haven't checked the whole code, just asking :)

Yes, I think it is save.
netdev2 should be unregistered and freed before net_dev.
If net_dev is unregistered and freed in advance,
mac->next_netdev becomes danger because 'mac' has been freed.


> > +	sysfs_remove_group(&pdev->dev.kobj, &l2sw_attribute_group);
> > +
> > +	mac->comm->enable = 0;
> > +	soc0_stop(mac);
> > +
> > +	napi_disable(&mac->comm->rx_napi);
> > +	netif_napi_del(&mac->comm->rx_napi);
> > +	napi_disable(&mac->comm->tx_napi);
> > +	netif_napi_del(&mac->comm->tx_napi);
> > +
> > +	mdio_remove(net_dev);
> > +
> > +	// Unregister and free 1st net device.
> > +	unregister_netdev(net_dev);
> > +	free_netdev(net_dev);
> > +
> > +	clk_disable(mac->comm->clk);
> > +
> > +	// Free 'common' area.
> > +	kfree(mac->comm);
> 
> Same here with `mac`.

This is indeed a bug.
But the statement, Kfree(mac->comm);, has been removed in [PATCH v2].
In [PATCH v2], structure data 'mac->comm' is allocated by
devm_kzalloc(). No more need to free it here.


> > +	return 0;
> > +}
> 
> 
> I haven't read the whole thread, i am sorry if these questions were already discussed.
> 
> 
> 
> With regards,
> Pavel Skripkin


Thank you very much for your review!

Best regards,
Wells Lu

  reply	other threads:[~2021-11-17  9:28 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-03 11:02 [PATCH 0/2] This is a patch series of ethernet driver for Sunplus SP7021 SoC Wells Lu
2021-11-03 11:02 ` [PATCH 1/2] devicetree: bindings: net: Add bindings doc for Sunplus SP7021 Wells Lu
2021-11-03 11:02 ` [PATCH 2/2] net: ethernet: Add driver " Wells Lu
2021-11-03 12:05   ` Denis Kirjanov
2021-11-03 14:08     ` Wells Lu 呂芳騰
2021-11-03 12:10   ` Philipp Zabel
2021-11-03 15:11     ` Wells Lu 呂芳騰
2021-11-03 15:52   ` Randy Dunlap
2021-11-03 18:08     ` Wells Lu 呂芳騰
2021-11-03 19:30       ` Andrew Lunn
2021-11-04  5:31         ` Wells Lu 呂芳騰
2021-11-04 12:59           ` Andrew Lunn
2021-11-04 14:55             ` Randy Dunlap
2021-11-04 17:51               ` Wells Lu 呂芳騰
2021-11-04 17:46             ` Wells Lu 呂芳騰
2021-11-04 18:21               ` Andrew Lunn
2021-11-04 19:03                 ` Wells Lu 呂芳騰
2021-11-03 20:26       ` Randy Dunlap
2021-11-03 16:51   ` Andrew Lunn
2021-11-05 11:25     ` Wells Lu 呂芳騰
2021-11-05 13:37       ` Andrew Lunn
2021-11-08  9:37         ` Wells Lu 呂芳騰
2021-11-08 13:15           ` Andrew Lunn
2021-11-08 14:26             ` Wells Lu 呂芳騰
2021-11-08 14:52               ` Andrew Lunn
2021-11-08 16:47                 ` Wells Lu 呂芳騰
2021-11-08 17:32                   ` Andrew Lunn
2021-11-09 14:39                     ` Wells Lu 呂芳騰
2021-11-09 15:32                       ` Andrew Lunn
2021-11-09 17:05                         ` Wells Lu 呂芳騰
2021-11-14 19:19   ` Pavel Skripkin
2021-11-17  9:28     ` Wells Lu 呂芳騰 [this message]
2021-11-03 11:27 ` [PATCH 0/2] This is a patch series of ethernet driver for Sunplus SP7021 SoC Denis Kirjanov
2021-11-11  9:04 ` [PATCH v2 0/2] This is a patch series for pinctrl " Wells Lu
2021-11-11  9:04   ` [PATCH v2 1/2] devicetree: bindings: net: Add bindings doc for Sunplus SP7021 Wells Lu
2021-11-11 14:57     ` Rob Herring
2021-11-12  2:57       ` Wells Lu 呂芳騰
2021-11-11 18:23     ` Andrew Lunn
2021-11-12  2:50       ` Wells Lu 呂芳騰
2021-11-11  9:04   ` [PATCH v2 2/2] net: ethernet: Add driver " Wells Lu
2021-11-11 11:31     ` Denis Kirjanov
2021-11-13 14:22       ` Wells Lu 呂芳騰
2021-11-13 15:34         ` Andrew Lunn
2021-11-18  8:15           ` Wells Lu 呂芳騰
2021-11-12 17:42     ` kernel test robot
2021-11-12 23:16     ` Florian Fainelli
2021-11-12 23:24       ` Andrew Lunn
2021-11-15 14:38         ` Wells Lu 呂芳騰
2021-11-14 18:59       ` Wells Lu 呂芳騰
2021-11-12 23:58     ` Andrew Lunn
2021-11-16 17:09       ` Wells Lu 呂芳騰
2021-11-16 22:15         ` Andrew Lunn
2021-11-18  8:22           ` Wells Lu 呂芳騰
2021-11-25 11:28       ` Wells Lu 呂芳騰
2021-11-25 15:20         ` Andrew Lunn
2021-11-26  3:56           ` Wells Lu 呂芳騰
2021-11-26 14:38             ` Andrew Lunn
2021-11-26 16:12               ` Wells Lu 呂芳騰
2021-11-26 18:07                 ` Andrew Lunn
2021-11-26 19:13                   ` Wells Lu 呂芳騰
2021-11-26 19:32                     ` Andrew Lunn
2021-11-29 11:16                       ` Wells Lu 呂芳騰

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=29c352ebf87a4ecb854c5599f5282910@sphcmbx02.sunplus.com.tw \
    --to=wells.lu@sunplus.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=paskripkin@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=wellslutw@gmail.com \
    /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®