]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - drivers/thunderbolt/switch.c
UBUNTU: Ubuntu-4.13.0-45.50
[mirror_ubuntu-artful-kernel.git] / drivers / thunderbolt / switch.c
index e9391bbd4036023c63d8b7ec90185f56f9523ade..53f40c57df59ccaefe0f69ab0d02977b3406e518 100644 (file)
@@ -807,11 +807,11 @@ static ssize_t key_store(struct device *dev, struct device_attribute *attr,
        struct tb_switch *sw = tb_to_switch(dev);
        u8 key[TB_SWITCH_KEY_SIZE];
        ssize_t ret = count;
+       bool clear = false;
 
-       if (count < 64)
-               return -EINVAL;
-
-       if (hex2bin(key, buf, sizeof(key)))
+       if (!strcmp(buf, "\n"))
+               clear = true;
+       else if (hex2bin(key, buf, sizeof(key)))
                return -EINVAL;
 
        if (mutex_lock_interruptible(&switch_lock))
@@ -821,15 +821,19 @@ static ssize_t key_store(struct device *dev, struct device_attribute *attr,
                ret = -EBUSY;
        } else {
                kfree(sw->key);
-               sw->key = kmemdup(key, sizeof(key), GFP_KERNEL);
-               if (!sw->key)
-                       ret = -ENOMEM;
+               if (clear) {
+                       sw->key = NULL;
+               } else {
+                       sw->key = kmemdup(key, sizeof(key), GFP_KERNEL);
+                       if (!sw->key)
+                               ret = -ENOMEM;
+               }
        }
 
        mutex_unlock(&switch_lock);
        return ret;
 }
-static DEVICE_ATTR_RW(key);
+static DEVICE_ATTR(key, 0600, key_show, key_store);
 
 static ssize_t nvm_authenticate_show(struct device *dev,
        struct device_attribute *attr, char *buf)