netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine
@ 2024-02-03  7:51 Christophe JAILLET
  2024-02-03  7:51 ` [PATCH v2 1/2] nfc: hci: Introduce nfc_llc_del_engine() to reduce code duplication Christophe JAILLET
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Christophe JAILLET @ 2024-02-03  7:51 UTC (permalink / raw)
  To: krzysztof.kozlowski, davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, kernel-janitors, Christophe JAILLET

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.

v2: Add a new helper function, nfc_llc_del_engine(), to reduce code
    duplication. This is needed to address Jakub Kicinski's comment
    about nfc_llc_exit() that was not updated in v1.

v1: https://lore.kernel.org/all/6d2b8c390907dcac2e4dc6e71f1b2db2ef8abef1.1705744530.git.christophe.jaillet@wanadoo.fr/

Christophe JAILLET (2):
  nfc: hci: Introduce nfc_llc_del_engine() to reduce code duplication
  nfc: hci: Save a few bytes of memory when registering a 'nfc_llc'
    engine

 net/nfc/hci/llc.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

-- 
2.43.0


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

* [PATCH v2 1/2] nfc: hci: Introduce nfc_llc_del_engine() to reduce code duplication
  2024-02-03  7:51 [PATCH v2 0/2] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine Christophe JAILLET
@ 2024-02-03  7:51 ` Christophe JAILLET
  2024-02-06 14:30   ` Simon Horman
  2024-02-03  7:51 ` [PATCH v2 2/2] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine Christophe JAILLET
  2024-02-06 14:40 ` [PATCH v2 0/2] " patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Christophe JAILLET @ 2024-02-03  7:51 UTC (permalink / raw)
  To: krzysztof.kozlowski, davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, kernel-janitors, Christophe JAILLET

Add a new helper to avoid code duplication between nfc_llc_exit() and
nfc_llc_unregister().

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

diff --git a/net/nfc/hci/llc.c b/net/nfc/hci/llc.c
index 2140f6724644..480c17f372a5 100644
--- a/net/nfc/hci/llc.c
+++ b/net/nfc/hci/llc.c
@@ -30,15 +30,19 @@ int __init nfc_llc_init(void)
 	return r;
 }
 
+static void nfc_llc_del_engine(struct nfc_llc_engine *llc_engine)
+{
+	list_del(&llc_engine->entry);
+	kfree(llc_engine->name);
+	kfree(llc_engine);
+}
+
 void nfc_llc_exit(void)
 {
 	struct nfc_llc_engine *llc_engine, *n;
 
-	list_for_each_entry_safe(llc_engine, n, &llc_engines, entry) {
-		list_del(&llc_engine->entry);
-		kfree(llc_engine->name);
-		kfree(llc_engine);
-	}
+	list_for_each_entry_safe(llc_engine, n, &llc_engines, entry)
+		nfc_llc_del_engine(llc_engine);
 }
 
 int nfc_llc_register(const char *name, const struct nfc_llc_ops *ops)
@@ -82,9 +86,7 @@ void nfc_llc_unregister(const char *name)
 	if (llc_engine == NULL)
 		return;
 
-	list_del(&llc_engine->entry);
-	kfree(llc_engine->name);
-	kfree(llc_engine);
+	nfc_llc_del_engine(llc_engine);
 }
 
 struct nfc_llc *nfc_llc_allocate(const char *name, struct nfc_hci_dev *hdev,
-- 
2.43.0


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

* [PATCH v2 2/2] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine
  2024-02-03  7:51 [PATCH v2 0/2] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine Christophe JAILLET
  2024-02-03  7:51 ` [PATCH v2 1/2] nfc: hci: Introduce nfc_llc_del_engine() to reduce code duplication Christophe JAILLET
@ 2024-02-03  7:51 ` Christophe JAILLET
  2024-02-06 14:34   ` Simon Horman
  2024-02-06 14:40 ` [PATCH v2 0/2] " patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Christophe JAILLET @ 2024-02-03  7:51 UTC (permalink / raw)
  To: krzysztof.kozlowski, davem, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, kernel-janitors, Christophe JAILLET

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 480c17f372a5..ba91284f4086 100644
--- a/net/nfc/hci/llc.c
+++ b/net/nfc/hci/llc.c
@@ -33,7 +33,7 @@ int __init nfc_llc_init(void)
 static void nfc_llc_del_engine(struct nfc_llc_engine *llc_engine)
 {
 	list_del(&llc_engine->entry);
-	kfree(llc_engine->name);
+	kfree_const(llc_engine->name);
 	kfree(llc_engine);
 }
 
@@ -53,7 +53,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;
-- 
2.43.0


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

* Re: [PATCH v2 1/2] nfc: hci: Introduce nfc_llc_del_engine() to reduce code duplication
  2024-02-03  7:51 ` [PATCH v2 1/2] nfc: hci: Introduce nfc_llc_del_engine() to reduce code duplication Christophe JAILLET
@ 2024-02-06 14:30   ` Simon Horman
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2024-02-06 14:30 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: krzysztof.kozlowski, davem, edumazet, kuba, pabeni, netdev,
	linux-kernel, kernel-janitors

On Sat, Feb 03, 2024 at 08:51:03AM +0100, Christophe JAILLET wrote:
> Add a new helper to avoid code duplication between nfc_llc_exit() and
> nfc_llc_unregister().
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Reviewed-by: Simon Horman <horms@kernel.org>


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

* Re: [PATCH v2 2/2] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine
  2024-02-03  7:51 ` [PATCH v2 2/2] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine Christophe JAILLET
@ 2024-02-06 14:34   ` Simon Horman
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2024-02-06 14:34 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: krzysztof.kozlowski, davem, edumazet, kuba, pabeni, netdev,
	linux-kernel, kernel-janitors

On Sat, Feb 03, 2024 at 08:51:04AM +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: Simon Horman <horms@kernel.org>


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

* Re: [PATCH v2 0/2] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine
  2024-02-03  7:51 [PATCH v2 0/2] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine Christophe JAILLET
  2024-02-03  7:51 ` [PATCH v2 1/2] nfc: hci: Introduce nfc_llc_del_engine() to reduce code duplication Christophe JAILLET
  2024-02-03  7:51 ` [PATCH v2 2/2] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine Christophe JAILLET
@ 2024-02-06 14:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-02-06 14:40 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: krzysztof.kozlowski, davem, edumazet, kuba, pabeni, netdev,
	linux-kernel, kernel-janitors

Hello:

This series was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Sat,  3 Feb 2024 08:51:02 +0100 you 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.
> 
> v2: Add a new helper function, nfc_llc_del_engine(), to reduce code
>     duplication. This is needed to address Jakub Kicinski's comment
>     about nfc_llc_exit() that was not updated in v1.
> 
> [...]

Here is the summary with links:
  - [v2,1/2] nfc: hci: Introduce nfc_llc_del_engine() to reduce code duplication
    https://git.kernel.org/netdev/net-next/c/d6f4aac19ad4
  - [v2,2/2] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine
    https://git.kernel.org/netdev/net-next/c/83cdd8db7508

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



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

end of thread, other threads:[~2024-02-06 14:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-03  7:51 [PATCH v2 0/2] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine Christophe JAILLET
2024-02-03  7:51 ` [PATCH v2 1/2] nfc: hci: Introduce nfc_llc_del_engine() to reduce code duplication Christophe JAILLET
2024-02-06 14:30   ` Simon Horman
2024-02-03  7:51 ` [PATCH v2 2/2] nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine Christophe JAILLET
2024-02-06 14:34   ` Simon Horman
2024-02-06 14:40 ` [PATCH v2 0/2] " patchwork-bot+netdevbpf

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).