nfc: hci: Save a few bytes of memory when registering a 'nfc_llc' engine
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sat, 3 Feb 2024 07:51:04 +0000 (08:51 +0100)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 6 Feb 2024 14:36:06 +0000 (15:36 +0100)
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>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/nfc/hci/llc.c

index 480c17f372a535ce6800cf583c62e702e2dc59b8..ba91284f4086ef4c2bb849920810aede7d2201d5 100644 (file)
@@ -33,7 +33,7 @@ exit:
 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;