thunderbolt: Fix a missing check of kmemdup
authorKangjie Lu <kjlu@umn.edu>
Thu, 14 Mar 2019 06:55:31 +0000 (01:55 -0500)
committerMika Westerberg <mika.westerberg@linux.intel.com>
Wed, 20 Mar 2019 10:37:12 +0000 (13:37 +0300)
kmemdup may fail and return NULL. The fix adds a check and returns
NULL in case it fails to avoid NULL pointer dereferecen.

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

index ee76449524a3c784b2ca468448eb9e89df91176f..841314deb446dbe2c39cdf72342d5f273254db23 100644 (file)
@@ -176,6 +176,10 @@ static struct tb_property_dir *__tb_property_parse_dir(const u32 *block,
        } else {
                dir->uuid = kmemdup(&block[dir_offset], sizeof(*dir->uuid),
                                    GFP_KERNEL);
+               if (!dir->uuid) {
+                       tb_property_free_dir(dir);
+                       return NULL;
+               }
                content_offset = dir_offset + 4;
                content_len = dir_len - 4; /* Length includes UUID */
        }