All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac()
@ 2020-05-03 20:49 wu000273
  2020-05-04  6:01 ` Markus Elfring
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: wu000273 @ 2020-05-03 20:49 UTC (permalink / raw)
  To: kuba
  Cc: davem, Markus.Elfring, oss-drivers, netdev, linux-kernel, kjlu, wu000273

From: Qiushi Wu <wu000273@umn.edu>

In function nfp_abm_vnic_set_mac, pointer nsp is allocated by nfp_nsp_open.
But when nfp_nsp_has_hwinfo_lookup fail, the pointer is not released,
which can lead to a memory leak bug. Thus add a call of the function
“nfp_nsp_close” for the completion of the exception handling.

Fixes: f6e71efdf9fb1 ("nfp: abm: look up MAC addresses via management FW")
Signed-off-by: Qiushi Wu <wu000273@umn.edu>
---
 drivers/net/ethernet/netronome/nfp/abm/main.c | 21 ++++++++++---------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/abm/main.c b/drivers/net/ethernet/netronome/nfp/abm/main.c
index 9183b3e85d21..f196789f62fe 100644
--- a/drivers/net/ethernet/netronome/nfp/abm/main.c
+++ b/drivers/net/ethernet/netronome/nfp/abm/main.c
@@ -265,8 +265,7 @@ nfp_abm_vnic_set_mac(struct nfp_pf *pf, struct nfp_abm *abm, struct nfp_net *nn,
 
 	if (id > pf->eth_tbl->count) {
 		nfp_warn(pf->cpp, "No entry for persistent MAC address\n");
-		eth_hw_addr_random(nn->dp.netdev);
-		return;
+		goto generate_random_address;
 	}
 
 	snprintf(hwinfo, sizeof(hwinfo), "eth%u.mac.pf%u",
@@ -276,14 +275,13 @@ nfp_abm_vnic_set_mac(struct nfp_pf *pf, struct nfp_abm *abm, struct nfp_net *nn,
 	if (IS_ERR(nsp)) {
 		nfp_warn(pf->cpp, "Failed to access the NSP for persistent MAC address: %ld\n",
 			 PTR_ERR(nsp));
-		eth_hw_addr_random(nn->dp.netdev);
-		return;
+		goto generate_random_address;
 	}
 
 	if (!nfp_nsp_has_hwinfo_lookup(nsp)) {
 		nfp_warn(pf->cpp, "NSP doesn't support PF MAC generation\n");
-		eth_hw_addr_random(nn->dp.netdev);
-		return;
+		nfp_nsp_close(nsp);
+		goto generate_random_address;
 	}
 
 	err = nfp_nsp_hwinfo_lookup(nsp, hwinfo, sizeof(hwinfo));
@@ -291,8 +289,7 @@ nfp_abm_vnic_set_mac(struct nfp_pf *pf, struct nfp_abm *abm, struct nfp_net *nn,
 	if (err) {
 		nfp_warn(pf->cpp, "Reading persistent MAC address failed: %d\n",
 			 err);
-		eth_hw_addr_random(nn->dp.netdev);
-		return;
+		goto generate_random_address;
 	}
 
 	if (sscanf(hwinfo, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
@@ -300,12 +297,16 @@ nfp_abm_vnic_set_mac(struct nfp_pf *pf, struct nfp_abm *abm, struct nfp_net *nn,
 		   &mac_addr[3], &mac_addr[4], &mac_addr[5]) != 6) {
 		nfp_warn(pf->cpp, "Can't parse persistent MAC address (%s)\n",
 			 hwinfo);
-		eth_hw_addr_random(nn->dp.netdev);
-		return;
+		goto generate_random_address;
 	}
 
 	ether_addr_copy(nn->dp.netdev->dev_addr, mac_addr);
 	ether_addr_copy(nn->dp.netdev->perm_addr, mac_addr);
+	return;
+
+generate_random_address:
+	eth_hw_addr_random(nn->dp.netdev);
+	return;
 }
 
 static int
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v3] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac()
  2020-05-03 20:49 [PATCH v3] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac() wu000273
@ 2020-05-04  6:01 ` Markus Elfring
  2020-05-04  7:34 ` Markus Elfring
  2020-05-04 17:03 ` Jakub Kicinski
  2 siblings, 0 replies; 10+ messages in thread
From: Markus Elfring @ 2020-05-04  6:01 UTC (permalink / raw)
  To: Qiushi Wu, Jakub Kicinski, netdev
  Cc: oss-drivers, linux-kernel, David S. Miller, Kangjie Lu

> … Thus add a call of the function
> “nfp_nsp_close” for the completion of the exception handling.

I suggest to mention also the addition of a jump target because of
a Linux coding style concern.


…
> +++ b/drivers/net/ethernet/netronome/nfp/abm/main.c
> @@ -300,12 +297,16 @@ nfp_abm_vnic_set_mac(struct nfp_pf *pf, struct nfp_abm *abm, struct nfp_net *nn,
> +generate_random_address:
> +	eth_hw_addr_random(nn->dp.netdev);
> +	return;
>  }
…

I recommend to apply the check “RETURN_VOID” once more.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/checkpatch.pl?id=0e698dfa282211e414076f9dc7e83c1c288314fd#n4866

Regards,
Markus

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac()
  2020-05-03 20:49 [PATCH v3] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac() wu000273
  2020-05-04  6:01 ` Markus Elfring
@ 2020-05-04  7:34 ` Markus Elfring
  2020-05-04 17:03 ` Jakub Kicinski
  2 siblings, 0 replies; 10+ messages in thread
From: Markus Elfring @ 2020-05-04  7:34 UTC (permalink / raw)
  To: Qiushi Wu, netdev
  Cc: oss-drivers, linux-kernel, David S. Miller, Jakub Kicinski, Kangjie Lu

> But when nfp_nsp_has_hwinfo_lookup fail, the pointer is not released,

Do you distinguish between releasing items and the role of such a pointer?


> which can lead to a memory leak bug.

Would you like to reconsider the usage of the word “can” for
such change descriptions?

Regards,
Markus

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac()
  2020-05-03 20:49 [PATCH v3] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac() wu000273
  2020-05-04  6:01 ` Markus Elfring
  2020-05-04  7:34 ` Markus Elfring
@ 2020-05-04 17:03 ` Jakub Kicinski
       [not found]   ` <CAMV6ehFC=efyD81rtNRcWW9gbiD4t6z4G2TkLk7WqLS+Qg9X-Q@mail.gmail.com>
  2 siblings, 1 reply; 10+ messages in thread
From: Jakub Kicinski @ 2020-05-04 17:03 UTC (permalink / raw)
  To: wu000273; +Cc: davem, Markus.Elfring, oss-drivers, netdev, linux-kernel, kjlu

On Sun,  3 May 2020 15:49:32 -0500 wu000273@umn.edu wrote:
> From: Qiushi Wu <wu000273@umn.edu>
> 
> In function nfp_abm_vnic_set_mac, pointer nsp is allocated by nfp_nsp_open.
> But when nfp_nsp_has_hwinfo_lookup fail, the pointer is not released,
> which can lead to a memory leak bug. Thus add a call of the function
> “nfp_nsp_close” for the completion of the exception handling.
> 
> Fixes: f6e71efdf9fb1 ("nfp: abm: look up MAC addresses via management FW")
> Signed-off-by: Qiushi Wu <wu000273@umn.edu>

This just makes the code longer. v1 was perfectly fine, thanks for the
fix. 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [v3] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac()
       [not found]   ` <CAMV6ehFC=efyD81rtNRcWW9gbiD4t6z4G2TkLk7WqLS+Qg9X-Q@mail.gmail.com>
@ 2020-05-04 20:13     ` Markus Elfring
       [not found]       ` <CAMV6ehE=GXooHwG1TQ-LZqpepceAudX=P63o139UgKG7TMRxwQ@mail.gmail.com>
  0 siblings, 1 reply; 10+ messages in thread
From: Markus Elfring @ 2020-05-04 20:13 UTC (permalink / raw)
  To: Qiushi Wu, netdev
  Cc: LKML, oss-drivers, Kangjie Lu, Jakub Kicinski, David S. Miller

> By the way, is there anything else that I need to improve for this patch?

I became curious if you would like to adjust further details from
the change description.
Other contributors might care less for presented concerns.

Regards,
Markus

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [v3] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac()
       [not found]       ` <CAMV6ehE=GXooHwG1TQ-LZqpepceAudX=P63o139UgKG7TMRxwQ@mail.gmail.com>
@ 2020-05-05  5:48         ` Markus Elfring
       [not found]           ` <CAMV6ehEP-X+5bXj6VXMpZCPkr6YZWsB0Z_sTBxFxNpwa6D0Z0Q@mail.gmail.com>
  0 siblings, 1 reply; 10+ messages in thread
From: Markus Elfring @ 2020-05-05  5:48 UTC (permalink / raw)
  To: Qiushi Wu, netdev
  Cc: LKML, oss-drivers, Kangjie Lu, Jakub Kicinski, David S. Miller

> Thanks for your feedback, and yes, I'd like to further adjust the description details
> to make the patch more clear and better.

Thanks for such a positive response.


> But because Jakub seems to prefer v1, so I'm somehow confused

Such a view can be reasonable.
The change acceptance varies between involved contributors.


> if I should submit a new version based on v1

Such a choice depends also on your willingness to clarify and improve
the software situation by better commit messages.


> or based on the version that has an addition of a jump target?

I propose that you can offer patch series with two update steps (for example)
according to the affected function implementation.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=47cf1b422e6093aee2a3e55d5e162112a2c69870#n102

1. Add a missing function call for the completion of the desired resource clean-up.

2. Adjust a bit of exception handling code so that it can be better reused
   at the end of this function.
   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?id=47cf1b422e6093aee2a3e55d5e162112a2c69870#n450


I am curious if you are going to answer (my) previous questions and suggestions
(in constructive ways).

Regards,
Markus

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [v3] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac()
       [not found]           ` <CAMV6ehEP-X+5bXj6VXMpZCPkr6YZWsB0Z_sTBxFxNpwa6D0Z0Q@mail.gmail.com>
@ 2020-05-05  8:26             ` Markus Elfring
       [not found]               ` <CAMV6ehE9YRxakbP9ahXkiZEPut8E3qYsN0cxiLqCWasfvLAWFw@mail.gmail.com>
  0 siblings, 1 reply; 10+ messages in thread
From: Markus Elfring @ 2020-05-05  8:26 UTC (permalink / raw)
  To: Qiushi Wu, netdev
  Cc: LKML, oss-drivers, Kangjie Lu, Jakub Kicinski, David S. Miller

>> Do you distinguish between releasing items and the role of such a pointer?
> I didn't distinguish these. 

How do you think about to clarify this aspect a bit more (according to computer science)
besides your subsequent constructive feedback?

Regards,
Markus

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [v3] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac()
       [not found]               ` <CAMV6ehE9YRxakbP9ahXkiZEPut8E3qYsN0cxiLqCWasfvLAWFw@mail.gmail.com>
@ 2020-05-05 20:17                 ` Markus Elfring
       [not found]                   ` <CAMV6ehFCcSZtqpxonfbp6i_v5zzmnLJ9Gncx=5Y36R35wqTtDw@mail.gmail.com>
  0 siblings, 1 reply; 10+ messages in thread
From: Markus Elfring @ 2020-05-05 20:17 UTC (permalink / raw)
  To: Qiushi Wu, netdev
  Cc: LKML, oss-drivers, Kangjie Lu, Jakub Kicinski, David S. Miller

> What do you think about changing:
> "But when nfp_nsp_has_hwinfo_lookup fail, the pointer is not released,.."
> to
> or
> "But when nfp_nsp_has_hwinfo_lookup fail,

I became curious about a related wording variant.

  But when a call of the function “…” failed,


> NSP resource is not cleaned up and unlocked."

I find such information also nicer. (The abbreviation “NSP” might need
another bit of clarification.)

I imagine there might be interests (eventually related to computer science)
to measure the corresponding object sizes because of a missed function call
and offer a more precise information in the commit message
(depending on the willingness to invest efforts in such a data determination).

Will such considerations become relevant for any subsequent
software development approaches?

Regards,
Markus

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [v3] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac()
       [not found]                   ` <CAMV6ehFCcSZtqpxonfbp6i_v5zzmnLJ9Gncx=5Y36R35wqTtDw@mail.gmail.com>
@ 2020-05-06  6:12                     ` Markus Elfring
       [not found]                       ` <CAK8KejrEuumVxdbBmuHbhjXQa7KH_jP-XLmAHjp1+AC7DUa9WQ@mail.gmail.com>
  0 siblings, 1 reply; 10+ messages in thread
From: Markus Elfring @ 2020-05-06  6:12 UTC (permalink / raw)
  To: Qiushi Wu, netdev
  Cc: LKML, oss-drivers, Kangjie Lu, Jakub Kicinski, David S. Miller

> I'm curious if I could still modify these commit message information for the v1 patch,
> which has already been applied and queued up?

The maintainer found the provided information good enough.
Thus he committed the software correction with the subject
“nfp: abm: fix a memory leak bug” on 2020-05-04.
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/net/ethernet/netronome/nfp/abm/main.c?id=bd4af432cc71b5fbfe4833510359a6ad3ada250d

So this change will probably be published “forever” since then.

I got the impression that the corresponding patch review contains helpful information.
I am curious then if it might affect the adjustment of related patches.


>> Will such considerations become relevant for any subsequent
>> software development approaches?
>
> Sorry, I actually don't familiar with these.

I am informed in the way that you can participate in university research groups.
Thus I assumed that you would like to add recent insights
from computer science areas.
I imagined that the bug report (combined with a patch) was triggered by
an evolving source code analysis approach which will be explained
in another research paper. Is such a view appropriate?
https://github.com/umnsec/cheq/

Regards,
Markus

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [v3] nfp: abm: University research groups?
       [not found]                       ` <CAK8KejrEuumVxdbBmuHbhjXQa7KH_jP-XLmAHjp1+AC7DUa9WQ@mail.gmail.com>
@ 2020-05-07  7:23                         ` Markus Elfring
  0 siblings, 0 replies; 10+ messages in thread
From: Markus Elfring @ 2020-05-07  7:23 UTC (permalink / raw)
  To: Kangjie Lu, Qiushi Wu, netdev
  Cc: LKML, oss-drivers, Jakub Kicinski, David S. Miller

> > I imagined that the bug report (combined with a patch) was triggered by
> > an evolving source code analysis approach which will be explained
> > in another research paper. Is such a view appropriate?
> > https://github.com/umnsec/cheq/
>
> Could you elaborate more on "university research groups?"

You are working together for the publishing of some papers which will
eventually be presented at conferences.
You might build additional relationships and participate in further work groups.


> We are continuously working on automated kernel analysis

This is good to know.


> to improve the unfortunately very buggy kernel.

There are various software development challenges to consider.

Have you got a desire to express connections to recent research results
also in commit messages?

Regards,
Markus

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-05-07  7:24 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-03 20:49 [PATCH v3] nfp: abm: Fix incomplete release of system resources in nfp_abm_vnic_set_mac() wu000273
2020-05-04  6:01 ` Markus Elfring
2020-05-04  7:34 ` Markus Elfring
2020-05-04 17:03 ` Jakub Kicinski
     [not found]   ` <CAMV6ehFC=efyD81rtNRcWW9gbiD4t6z4G2TkLk7WqLS+Qg9X-Q@mail.gmail.com>
2020-05-04 20:13     ` [v3] " Markus Elfring
     [not found]       ` <CAMV6ehE=GXooHwG1TQ-LZqpepceAudX=P63o139UgKG7TMRxwQ@mail.gmail.com>
2020-05-05  5:48         ` Markus Elfring
     [not found]           ` <CAMV6ehEP-X+5bXj6VXMpZCPkr6YZWsB0Z_sTBxFxNpwa6D0Z0Q@mail.gmail.com>
2020-05-05  8:26             ` Markus Elfring
     [not found]               ` <CAMV6ehE9YRxakbP9ahXkiZEPut8E3qYsN0cxiLqCWasfvLAWFw@mail.gmail.com>
2020-05-05 20:17                 ` Markus Elfring
     [not found]                   ` <CAMV6ehFCcSZtqpxonfbp6i_v5zzmnLJ9Gncx=5Y36R35wqTtDw@mail.gmail.com>
2020-05-06  6:12                     ` Markus Elfring
     [not found]                       ` <CAK8KejrEuumVxdbBmuHbhjXQa7KH_jP-XLmAHjp1+AC7DUa9WQ@mail.gmail.com>
2020-05-07  7:23                         ` [v3] nfp: abm: University research groups? Markus Elfring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.