@@ -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);
@@ -452,7 +452,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;
@@ -1969,13 +1969,13 @@ static int nfs_parse_devname(const char *dev_name,
goto out_hostname;
/* N.B. caller will free nfs_server.hostname in all cases */
- *hostname = kstrndup(dev_name, len, GFP_KERNEL);
+ *hostname = kmemdup_nul(dev_name, len, GFP_KERNEL);
if (*hostname == NULL)
goto out_nomem;
len = strlen(++end);
if (len > maxpathlen)
goto out_path;
- *export_path = kstrndup(end, len, GFP_KERNEL);
+ *export_path = kmemdup_nul(end, len, GFP_KERNEL);
if (!*export_path)
goto out_nomem;
When we already know the string length, it is more efficient to use kmemdup_nul(). Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> --- fs/nfs/dns_resolve.c | 2 +- fs/nfs/nfs4namespace.c | 2 +- fs/nfs/super.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)