thunderbolt: property: Fix a NULL pointer dereference
authorKangjie Lu <kjlu@umn.edu>
Tue, 12 Mar 2019 08:33:28 +0000 (03:33 -0500)
committerMika Westerberg <mika.westerberg@linux.intel.com>
Wed, 20 Mar 2019 10:37:12 +0000 (13:37 +0300)
In case kzalloc fails, the fix releases resources and returns
-ENOMEM to avoid the NULL pointer dereference.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
drivers/thunderbolt/property.c

index b2f0d6386ceea26bfc738ff72d54f36cc6f7a505..ee76449524a3c784b2ca468448eb9e89df91176f 100644 (file)
@@ -548,6 +548,11 @@ int tb_property_add_data(struct tb_property_dir *parent, const char *key,
 
        property->length = size / 4;
        property->value.data = kzalloc(size, GFP_KERNEL);
+       if (!property->value.data) {
+               kfree(property);
+               return -ENOMEM;
+       }
+
        memcpy(property->value.data, buf, buflen);
 
        list_add_tail(&property->list, &parent->properties);