OSDN Git Service

test_firmware: Use correct snprintf() limit
[android-x86/kernel.git] / lib / test_firmware.c
index b984806..fd48a15 100644 (file)
@@ -223,30 +223,30 @@ static ssize_t config_show(struct device *dev,
 
        mutex_lock(&test_fw_mutex);
 
-       len += snprintf(buf, PAGE_SIZE,
+       len += scnprintf(buf, PAGE_SIZE - len,
                        "Custom trigger configuration for: %s\n",
                        dev_name(dev));
 
        if (test_fw_config->name)
-               len += snprintf(buf+len, PAGE_SIZE,
+               len += scnprintf(buf+len, PAGE_SIZE - len,
                                "name:\t%s\n",
                                test_fw_config->name);
        else
-               len += snprintf(buf+len, PAGE_SIZE,
+               len += scnprintf(buf+len, PAGE_SIZE - len,
                                "name:\tEMTPY\n");
 
-       len += snprintf(buf+len, PAGE_SIZE,
+       len += scnprintf(buf+len, PAGE_SIZE - len,
                        "num_requests:\t%u\n", test_fw_config->num_requests);
 
-       len += snprintf(buf+len, PAGE_SIZE,
+       len += scnprintf(buf+len, PAGE_SIZE - len,
                        "send_uevent:\t\t%s\n",
                        test_fw_config->send_uevent ?
                        "FW_ACTION_HOTPLUG" :
                        "FW_ACTION_NOHOTPLUG");
-       len += snprintf(buf+len, PAGE_SIZE,
+       len += scnprintf(buf+len, PAGE_SIZE - len,
                        "sync_direct:\t\t%s\n",
                        test_fw_config->sync_direct ? "true" : "false");
-       len += snprintf(buf+len, PAGE_SIZE,
+       len += scnprintf(buf+len, PAGE_SIZE - len,
                        "read_fw_idx:\t%u\n", test_fw_config->read_fw_idx);
 
        mutex_unlock(&test_fw_mutex);
@@ -837,6 +837,7 @@ static ssize_t read_firmware_show(struct device *dev,
        if (req->fw->size > PAGE_SIZE) {
                pr_err("Testing interface must use PAGE_SIZE firmware for now\n");
                rc = -EINVAL;
+               goto out;
        }
        memcpy(buf, req->fw->data, req->fw->size);