2023-03-04 16:49:16

by Fedor Pchelkin

[permalink] [raw]
Subject: [PATCH] nfc: change order inside nfc_se_io error path

cb_context should be freed on error paths in nfc_se_io as stated by commit
25ff6f8a5a3b ("nfc: fix memory leak of se_io context in nfc_genl_se_io").

Make the error path in nfc_se_io unwind everything in reverse order, i.e.
free the cb_context after unlocking the device.

No functional changes intended - only adjusting to good coding practice.

Suggested-by: Krzysztof Kozlowski <[email protected]>
Signed-off-by: Fedor Pchelkin <[email protected]>
---
net/nfc/netlink.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index 348bf561bc9f..b9264e730fd9 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -1446,8 +1446,8 @@ static int nfc_se_io(struct nfc_dev *dev, u32 se_idx,
return rc;

error:
- kfree(cb_context);
device_unlock(&dev->dev);
+ kfree(cb_context);
return rc;
}

--
2.34.1



2023-03-06 15:28:51

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH] nfc: change order inside nfc_se_io error path

On 04/03/2023 17:48, Fedor Pchelkin wrote:
> cb_context should be freed on error paths in nfc_se_io as stated by commit
> 25ff6f8a5a3b ("nfc: fix memory leak of se_io context in nfc_genl_se_io").
>
> Make the error path in nfc_se_io unwind everything in reverse order, i.e.
> free the cb_context after unlocking the device.
>
> No functional changes intended - only adjusting to good coding practice.

I would argue that it is functional. Running code in or outside of
critical section/locks is quite functional change.

>
> Suggested-by: Krzysztof Kozlowski <[email protected]>
> Signed-off-by: Fedor Pchelkin <[email protected]>
> ---
> net/nfc/netlink.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
> index 348bf561bc9f..b9264e730fd9 100644
> --- a/net/nfc/netlink.c
> +++ b/net/nfc/netlink.c
> @@ -1446,8 +1446,8 @@ static int nfc_se_io(struct nfc_dev *dev, u32 se_idx,
> return rc;
>
> error:
> - kfree(cb_context);
> device_unlock(&dev->dev);
> + kfree(cb_context);


Acked-by: Krzysztof Kozlowski <[email protected]>

>

Best regards,
Krzysztof


2023-03-06 20:35:19

by Fedor Pchelkin

[permalink] [raw]
Subject: Re: [PATCH] nfc: change order inside nfc_se_io error path

On Mon, Mar 06, 2023 at 04:28:12PM +0100, Krzysztof Kozlowski wrote:
> On 04/03/2023 17:48, Fedor Pchelkin wrote:
> > cb_context should be freed on error paths in nfc_se_io as stated by commit
> > 25ff6f8a5a3b ("nfc: fix memory leak of se_io context in nfc_genl_se_io").
> >
> > Make the error path in nfc_se_io unwind everything in reverse order, i.e.
> > free the cb_context after unlocking the device.
> >
> > No functional changes intended - only adjusting to good coding practice.
>
> I would argue that it is functional. Running code in or outside of
> critical section/locks is quite functional change.
>

Hmm, actually, yes. I'll resend v2 with changed commit info as 'no
functional changes' statement can probably be misunderstood later.

Should this patch be backported by the way? It doesn't seem to fix any
real issue but, as you mentioned, it contains some functional changes
which may be of some importance in future.

2023-03-06 20:42:03

by Fedor Pchelkin

[permalink] [raw]
Subject: Re: [PATCH] nfc: change order inside nfc_se_io error path

On Mon, Mar 06, 2023 at 11:35:09PM +0300, Fedor Pchelkin wrote:
> On Mon, Mar 06, 2023 at 04:28:12PM +0100, Krzysztof Kozlowski wrote:
> > On 04/03/2023 17:48, Fedor Pchelkin wrote:
> > > cb_context should be freed on error paths in nfc_se_io as stated by commit
> > > 25ff6f8a5a3b ("nfc: fix memory leak of se_io context in nfc_genl_se_io").
> > >
> > > Make the error path in nfc_se_io unwind everything in reverse order, i.e.
> > > free the cb_context after unlocking the device.
> > >
> > > No functional changes intended - only adjusting to good coding practice.
> >
> > I would argue that it is functional. Running code in or outside of
> > critical section/locks is quite functional change.
> >
>
> Hmm, actually, yes. I'll resend v2 with changed commit info as 'no
> functional changes' statement can probably be misunderstood later.
>
> Should this patch be backported by the way? It doesn't seem to fix any
> real issue but, as you mentioned, it contains some functional changes
> which may be of some importance in future.

Sorry for the noise. Didn't see the patch was already applied. So it's
okay as it is.

2023-03-06 20:58:53

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH] nfc: change order inside nfc_se_io error path

On Mon, 6 Mar 2023 23:41:50 +0300 Fedor Pchelkin wrote:
> On Mon, Mar 06, 2023 at 11:35:09PM +0300, Fedor Pchelkin wrote:
> > On Mon, Mar 06, 2023 at 04:28:12PM +0100, Krzysztof Kozlowski wrote:
> > > I would argue that it is functional. Running code in or outside of
> > > critical section/locks is quite functional change.
> > >
> >
> > Hmm, actually, yes. I'll resend v2 with changed commit info as 'no
> > functional changes' statement can probably be misunderstood later.
> >
> > Should this patch be backported by the way? It doesn't seem to fix any
> > real issue but, as you mentioned, it contains some functional changes
> > which may be of some importance in future.
>
> Sorry for the noise. Didn't see the patch was already applied. So it's
> okay as it is.


As luck would have it it was applied to the wrong branch (we use main,
not master now). Script malfunction perhaps. So I'll toss it, you can
send a v2 with the updated commit message, please.

2023-03-06 21:27:10

by Fedor Pchelkin

[permalink] [raw]
Subject: [PATCH v2] nfc: change order inside nfc_se_io error path

cb_context should be freed on the error path in nfc_se_io as stated by
commit 25ff6f8a5a3b ("nfc: fix memory leak of se_io context in
nfc_genl_se_io").

Make the error path in nfc_se_io unwind everything in reverse order, i.e.
free the cb_context after unlocking the device.

Suggested-by: Krzysztof Kozlowski <[email protected]>
Signed-off-by: Fedor Pchelkin <[email protected]>
---
v1->v2: remove 'no functional changes' statement from commit info

net/nfc/netlink.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index 348bf561bc9f..b9264e730fd9 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -1446,8 +1446,8 @@ static int nfc_se_io(struct nfc_dev *dev, u32 se_idx,
return rc;

error:
- kfree(cb_context);
device_unlock(&dev->dev);
+ kfree(cb_context);
return rc;
}

--
2.34.1


2023-03-07 09:20:26

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH v2] nfc: change order inside nfc_se_io error path

On 06/03/2023 22:26, Fedor Pchelkin wrote:
> cb_context should be freed on the error path in nfc_se_io as stated by
> commit 25ff6f8a5a3b ("nfc: fix memory leak of se_io context in
> nfc_genl_se_io").
>
> Make the error path in nfc_se_io unwind everything in reverse order, i.e.
> free the cb_context after unlocking the device.
>
> Suggested-by: Krzysztof Kozlowski <[email protected]>
> Signed-off-by: Fedor Pchelkin <[email protected]>


Reviewed-by: Krzysztof Kozlowski <[email protected]>

Best regards,
Krzysztof


2023-03-07 21:50:34

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH v2] nfc: change order inside nfc_se_io error path

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

On Tue, 7 Mar 2023 00:26:50 +0300 you wrote:
> cb_context should be freed on the error path in nfc_se_io as stated by
> commit 25ff6f8a5a3b ("nfc: fix memory leak of se_io context in
> nfc_genl_se_io").
>
> Make the error path in nfc_se_io unwind everything in reverse order, i.e.
> free the cb_context after unlocking the device.
>
> [...]

Here is the summary with links:
- [v2] nfc: change order inside nfc_se_io error path
https://git.kernel.org/netdev/net/c/7d834b4d1ab6

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html