nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine
Subsystems (4)
v2 cover nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine
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.
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(-)
Signature · 1 line
2.43.0
PATCH v2 1/2 nfc: hci: Introduce nfc_llc_del_engine() to reduce code duplication
Add a new helper to avoid code duplication between nfc_llc_exit() and nfc_llc_unregister().
--- net/nfc/hci/llc.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
net/nfc/hci/llc.c +10 -8
@@ -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,
Signature · 1 line
2.43.0
Re: [PATCH v2 1/2] nfc: hci: Introduce nfc_llc_del_engine() to reduce code duplication
Quoted 4 lines · Christophe JAILLET
Add a new helper to avoid code duplication between
nfc_llc_exit()andnfc_llc_unregister().Signed-off-by Christophe JAILLET <[email protected]>
PATCH v2 2/2 nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine
In reply to Christophe JAILLETnfc_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.
--- net/nfc/hci/llc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/nfc/hci/llc.c +2 -2
@@ -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 ;
Signature · 1 line
2.43.0
Quoted 6 lines · Christophe JAILLET
nfc_llc_register()calls pass a string literal as the 'name' parameter.So
kstrdup_const()can be used instead ofkfree()to avoid a memory allocation in such cases.Signed-off-by Christophe JAILLET <[email protected]>
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 10 lines · 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 ofkfree()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 aboutnfc_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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html