Commit 60b4dfcd authored by Paolo Abeni's avatar Paolo Abeni

Merge branch 'nfc-hci-save-a-few-bytes-of-memory-when-registering-a-nfc_llc-engine'

Christophe says:

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

Link: https://lore.kernel.org/r/cover.1706946099.git.christophe.jaillet@wanadoo.frSigned-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parents 06e6bc1b 83cdd8db
...@@ -30,15 +30,19 @@ int __init nfc_llc_init(void) ...@@ -30,15 +30,19 @@ int __init nfc_llc_init(void)
return r; return r;
} }
static void nfc_llc_del_engine(struct nfc_llc_engine *llc_engine)
{
list_del(&llc_engine->entry);
kfree_const(llc_engine->name);
kfree(llc_engine);
}
void nfc_llc_exit(void) void nfc_llc_exit(void)
{ {
struct nfc_llc_engine *llc_engine, *n; struct nfc_llc_engine *llc_engine, *n;
list_for_each_entry_safe(llc_engine, n, &llc_engines, entry) { list_for_each_entry_safe(llc_engine, n, &llc_engines, entry)
list_del(&llc_engine->entry); nfc_llc_del_engine(llc_engine);
kfree(llc_engine->name);
kfree(llc_engine);
}
} }
int nfc_llc_register(const char *name, const struct nfc_llc_ops *ops) int nfc_llc_register(const char *name, const struct nfc_llc_ops *ops)
...@@ -49,7 +53,7 @@ int nfc_llc_register(const char *name, const struct nfc_llc_ops *ops) ...@@ -49,7 +53,7 @@ int nfc_llc_register(const char *name, const struct nfc_llc_ops *ops)
if (llc_engine == NULL) if (llc_engine == NULL)
return -ENOMEM; return -ENOMEM;
llc_engine->name = kstrdup(name, GFP_KERNEL); llc_engine->name = kstrdup_const(name, GFP_KERNEL);
if (llc_engine->name == NULL) { if (llc_engine->name == NULL) {
kfree(llc_engine); kfree(llc_engine);
return -ENOMEM; return -ENOMEM;
...@@ -82,9 +86,7 @@ void nfc_llc_unregister(const char *name) ...@@ -82,9 +86,7 @@ void nfc_llc_unregister(const char *name)
if (llc_engine == NULL) if (llc_engine == NULL)
return; return;
list_del(&llc_engine->entry); nfc_llc_del_engine(llc_engine);
kfree(llc_engine->name);
kfree(llc_engine);
} }
struct nfc_llc *nfc_llc_allocate(const char *name, struct nfc_hci_dev *hdev, struct nfc_llc *nfc_llc_allocate(const char *name, struct nfc_hci_dev *hdev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment