libnvdimm, namespace: Replace kmemdup() with kstrndup()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 11 Jun 2018 13:47:21 +0000 (16:47 +0300)
committerDan Williams <dan.j.williams@intel.com>
Mon, 10 Dec 2018 23:58:46 +0000 (15:58 -0800)
kstrndup() takes care of '\0' terminator for the strings.

Use it here instead of kmemdup() + explicit terminating the input string.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
drivers/nvdimm/namespace_devs.c

index 681af3a8fd62eead13b17bdcbb6785b96aabe2ac..4b077555ac70248292eba1f8a73b6a75fda3025d 100644 (file)
@@ -270,11 +270,10 @@ static ssize_t __alt_name_store(struct device *dev, const char *buf,
        if (dev->driver || to_ndns(dev)->claim)
                return -EBUSY;
 
-       input = kmemdup(buf, len + 1, GFP_KERNEL);
+       input = kstrndup(buf, len, GFP_KERNEL);
        if (!input)
                return -ENOMEM;
 
-       input[len] = '\0';
        pos = strim(input);
        if (strlen(pos) + 1 > NSLABEL_NAME_LEN) {
                rc = -EINVAL;