test: firmware_class: use kstrndup() where appropriate
authorBrian Norris <computersforpeace@gmail.com>
Wed, 9 Dec 2015 22:50:26 +0000 (14:50 -0800)
committerShuah Khan <shuahkh@osg.samsung.com>
Thu, 7 Jan 2016 20:43:28 +0000 (13:43 -0700)
We're essentially just doing an open-coded kstrndup(). The only
differences are with what happens after the first '\0' character, but
request_firmware() doesn't care about that.

Suggested-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
lib/test_firmware.c

index 841191061816b699e4108c5d155b639e937c5317..690b9c35a274d925a673b1656a3f044e87d789d1 100644 (file)
@@ -54,10 +54,9 @@ static ssize_t trigger_request_store(struct device *dev,
        int rc;
        char *name;
 
-       name = kzalloc(count + 1, GFP_KERNEL);
+       name = kstrndup(buf, count, GFP_KERNEL);
        if (!name)
                return -ENOSPC;
-       memcpy(name, buf, count);
 
        pr_info("loading '%s'\n", name);