NFS: Replace various occurrences of kstrndup() with kmemdup_nul()
authorTrond Myklebust <trondmy@gmail.com>
Sun, 2 Feb 2020 22:57:07 +0000 (17:57 -0500)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Mon, 3 Feb 2020 21:35:07 +0000 (16:35 -0500)
When we already know the string length, it is more efficient to
use kmemdup_nul().

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
[Anna - Changes to super.c were already made during fscontext conversion]
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
fs/nfs/dns_resolve.c
fs/nfs/nfs4namespace.c

index aec769a500a15b9eac153ab5658f5d6875f98c0d..89bd5581f3172cfd0d226632578ec45c25a9b567 100644 (file)
@@ -93,7 +93,7 @@ static void nfs_dns_ent_init(struct cache_head *cnew,
        key = container_of(ckey, struct nfs_dns_ent, h);
 
        kfree(new->hostname);
-       new->hostname = kstrndup(key->hostname, key->namelen, GFP_KERNEL);
+       new->hostname = kmemdup_nul(key->hostname, key->namelen, GFP_KERNEL);
        if (new->hostname) {
                new->namelen = key->namelen;
                nfs_dns_ent_update(cnew, ckey);
index 3ea1c1008b5bbb23552ce5c32205dc2baa046f18..84026e7b8a5f3fe528d9f95968a2b43947b5762e 100644 (file)
@@ -501,7 +501,7 @@ static int nfs4_try_replacing_one_location(struct nfs_server *server,
                rpc_set_port(sap, NFS_PORT);
 
                error = -ENOMEM;
-               hostname = kstrndup(buf->data, buf->len, GFP_KERNEL);
+               hostname = kmemdup_nul(buf->data, buf->len, GFP_KERNEL);
                if (hostname == NULL)
                        break;