netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine
@ 2024-01-20  9:56 Christophe JAILLET
  2024-01-20 12:00 ` Simon Horman
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Christophe JAILLET @ 2024-01-20  9:56 UTC (permalink / raw)
  To: Krzysztof Kozlowski, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, netdev

nfc_llc_register() calls pass a string literal as the 'name' parameter.

So kstrdup_const() can be used instead of kfree() to avoid a memory
allocation in such cases.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 net/nfc/hci/llc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/nfc/hci/llc.c b/net/nfc/hci/llc.c
index 2140f6724644..8c7b5a817b25 100644
--- a/net/nfc/hci/llc.c
+++ b/net/nfc/hci/llc.c
@@ -49,7 +49,7 @@ int nfc_llc_register(const char *name, const struct nfc_llc_ops *ops)
 	if (llc_engine == NULL)
 		return -ENOMEM;
 
-	llc_engine->name = kstrdup(name, GFP_KERNEL);
+	llc_engine->name = kstrdup_const(name, GFP_KERNEL);
 	if (llc_engine->name == NULL) {
 		kfree(llc_engine);
 		return -ENOMEM;
@@ -83,7 +83,7 @@ void nfc_llc_unregister(const char *name)
 		return;
 
 	list_del(&llc_engine->entry);
-	kfree(llc_engine->name);
+	kfree_const(llc_engine->name);
 	kfree(llc_engine);
 }
 
-- 
2.43.0


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

* Re: [PATCH] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine
  2024-01-20  9:56 [PATCH] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine Christophe JAILLET
@ 2024-01-20 12:00 ` Simon Horman
  2024-01-23 13:24 ` Krzysztof Kozlowski
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Simon Horman @ 2024-01-20 12:00 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Krzysztof Kozlowski, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-kernel, kernel-janitors,
	netdev

On Sat, Jan 20, 2024 at 10:56:06AM +0100, Christophe JAILLET wrote:
> nfc_llc_register() calls pass a string literal as the 'name' parameter.
> 
> So kstrdup_const() can be used instead of kfree() to avoid a memory
> allocation in such cases.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

## Form letter - net-next-closed

[adapted from text by Jakub]

The merge window for v6.8 has begun and therefore net-next is closed
for new drivers, features, code refactoring and optimizations.
We are currently accepting bug fixes only.

Please repost when net-next reopens on or after 22nd January.

RFC patches sent for review only are obviously welcome at any time.

See: https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#development-cycle
--
pw-bot: defer

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

* Re: [PATCH] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine
  2024-01-20  9:56 [PATCH] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine Christophe JAILLET
  2024-01-20 12:00 ` Simon Horman
@ 2024-01-23 13:24 ` Krzysztof Kozlowski
  2024-01-27  9:58 ` [PATCH RESEND] " Christophe JAILLET
  2024-01-31 23:08 ` Jakub Kicinski
  3 siblings, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2024-01-23 13:24 UTC (permalink / raw)
  To: Christophe JAILLET, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: linux-kernel, kernel-janitors, netdev

On 20/01/2024 10:56, Christophe JAILLET wrote:
> nfc_llc_register() calls pass a string literal as the 'name' parameter.
> 
> So kstrdup_const() can be used instead of kfree() to avoid a memory
> allocation in such cases.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>


Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

You probably need to resend it, because that time net-next was closed.
If resending, keep my tag.

Best regards,
Krzysztof


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

* [PATCH RESEND] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine
  2024-01-20  9:56 [PATCH] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine Christophe JAILLET
  2024-01-20 12:00 ` Simon Horman
  2024-01-23 13:24 ` Krzysztof Kozlowski
@ 2024-01-27  9:58 ` Christophe JAILLET
  2024-01-31 23:08 ` Jakub Kicinski
  3 siblings, 0 replies; 7+ messages in thread
From: Christophe JAILLET @ 2024-01-27  9:58 UTC (permalink / raw)
  To: Krzysztof Kozlowski, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, netdev

nfc_llc_register() calls pass a string literal as the 'name' parameter.

So kstrdup_const() can be used instead of kfree() to avoid a memory
allocation in such cases.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
Resent because of 'net-next-closed' message on previous try.

Added R-b tag. (see [1])

[1]: https://lore.kernel.org/all/9415e571-50a1-41d3-8205-68e4128bbe6d@linaro.org/
---
 net/nfc/hci/llc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/nfc/hci/llc.c b/net/nfc/hci/llc.c
index 2140f6724644..8c7b5a817b25 100644
--- a/net/nfc/hci/llc.c
+++ b/net/nfc/hci/llc.c
@@ -49,7 +49,7 @@ int nfc_llc_register(const char *name, const struct nfc_llc_ops *ops)
 	if (llc_engine == NULL)
 		return -ENOMEM;
 
-	llc_engine->name = kstrdup(name, GFP_KERNEL);
+	llc_engine->name = kstrdup_const(name, GFP_KERNEL);
 	if (llc_engine->name == NULL) {
 		kfree(llc_engine);
 		return -ENOMEM;
@@ -83,7 +83,7 @@ void nfc_llc_unregister(const char *name)
 		return;
 
 	list_del(&llc_engine->entry);
-	kfree(llc_engine->name);
+	kfree_const(llc_engine->name);
 	kfree(llc_engine);
 }
 
-- 
2.43.0


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

* Re: [PATCH RESEND] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine
  2024-01-20  9:56 [PATCH] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine Christophe JAILLET
                   ` (2 preceding siblings ...)
  2024-01-27  9:58 ` [PATCH RESEND] " Christophe JAILLET
@ 2024-01-31 23:08 ` Jakub Kicinski
  2024-02-02 19:11   ` Christophe JAILLET
  3 siblings, 1 reply; 7+ messages in thread
From: Jakub Kicinski @ 2024-01-31 23:08 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Krzysztof Kozlowski, David S. Miller, Eric Dumazet, Paolo Abeni,
	linux-kernel, kernel-janitors, netdev

On Sat, 27 Jan 2024 10:58:29 +0100 Christophe JAILLET wrote:
> nfc_llc_register() calls pass a string literal as the 'name' parameter.
> 
> So kstrdup_const() can be used instead of kfree() to avoid a memory
> allocation in such cases.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

There is a kfree() call in nfc_llc_exit() that looks suspiciously
like it may also free the name.

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

* Re: [PATCH RESEND] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine
  2024-01-31 23:08 ` Jakub Kicinski
@ 2024-02-02 19:11   ` Christophe JAILLET
  2024-02-02 19:33     ` Jakub Kicinski
  0 siblings, 1 reply; 7+ messages in thread
From: Christophe JAILLET @ 2024-02-02 19:11 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Krzysztof Kozlowski, David S. Miller, Eric Dumazet, Paolo Abeni,
	linux-kernel, kernel-janitors, netdev

Le 01/02/2024 à 00:08, Jakub Kicinski a écrit :
> On Sat, 27 Jan 2024 10:58:29 +0100 Christophe JAILLET wrote:
>> nfc_llc_register() calls pass a string literal as the 'name' parameter.
>>
>> So kstrdup_const() can be used instead of kfree() to avoid a memory
>> allocation in such cases.
>>
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> 
> There is a kfree() call in nfc_llc_exit() that looks suspiciously
> like it may also free the name.
> 
> 

Hi,

you are right.


Should we have something like:

void nfc_llc_exit(void)
{
	struct nfc_llc_engine *llc_engine, *n;

	list_for_each_entry_safe(llc_engine, n, &llc_engines, entry)
		nfc_llc_unregister(&llc_engine->name);
}


It would be slower, but it would reduce code duplication as well.
This is just an _exit() function, so it shouldn't be called that often 
anyway, if called at all.

Or, add another function with the list_del()+kfree_const()+kfree(), that 
would be called from nfc_llc_exit() and nfc_llc_unregister(), to have 
the best of the 2 worlds?

CJ

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

* Re: [PATCH RESEND] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine
  2024-02-02 19:11   ` Christophe JAILLET
@ 2024-02-02 19:33     ` Jakub Kicinski
  0 siblings, 0 replies; 7+ messages in thread
From: Jakub Kicinski @ 2024-02-02 19:33 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Krzysztof Kozlowski, David S. Miller, Eric Dumazet, Paolo Abeni,
	linux-kernel, kernel-janitors, netdev

On Fri, 2 Feb 2024 20:11:56 +0100 Christophe JAILLET wrote:
> It would be slower, but it would reduce code duplication as well.
> This is just an _exit() function, so it shouldn't be called that often 
> anyway, if called at all.
> 
> Or, add another function with the list_del()+kfree_const()+kfree(), that 
> would be called from nfc_llc_exit() and nfc_llc_unregister(), to have 
> the best of the 2 worlds?

My vote is the latter - factor out the 3 calls into a new helper, call
it where appropriate.

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

end of thread, other threads:[~2024-02-02 19:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-20  9:56 [PATCH] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine Christophe JAILLET
2024-01-20 12:00 ` Simon Horman
2024-01-23 13:24 ` Krzysztof Kozlowski
2024-01-27  9:58 ` [PATCH RESEND] " Christophe JAILLET
2024-01-31 23:08 ` Jakub Kicinski
2024-02-02 19:11   ` Christophe JAILLET
2024-02-02 19:33     ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).