libnvdimm, namespace: Replace kmemdup() with kstrndup()
PATCH 1/1 libnvdimm, namespace: Replace kmemdup() with kstrndup()
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 <[email protected]>
--- drivers/nvdimm/namespace_devs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/nvdimm/namespace_devs.c +1 -2
@@ -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 ;
Signature · 6 lines
2.17.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Quoted 4 lines · Andy Shevchenko
kstrndup()takes care of '\0' terminator for the strings.Use it here instead of
kmemdup()+ explicit terminating the input string.
Any comments on this?
Quoted 25 lines
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/nvdimm/namespace_devs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/nvdimm/namespace_devs.c +1
-2@@ -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 ;Signature · 1 line
2.17.1
Signature · 8 lines
With Best Regards, Andy Shevchenko _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Andy Shevchenko
kstrndup()takes care of '\0' terminator for the strings.Use it here instead of
kmemdup()+ explicit terminating the input string.Any comments on this?
Applied. Sorry looks like this one got missed.
Quoted 19 lines
Quoted 19 lines
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/nvdimm/namespace_devs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/nvdimm/namespace_devs.c +1
-1@@ -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 ;
Quoted 8 lines
Quoted 7 lines
drivers/nvdimm/namespace_devs.c +0
-1- input[len] ='\0' ; pos =strim (input);if (strlen (pos) +1 >NSLABEL_NAME_LEN ) { rc = -EINVAL ;Signature · 1 line
2.17.1
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm