return early if malloc fails to avoid use after free
authorjsg <jsg@openbsd.org>
Sat, 3 Feb 2024 09:15:57 +0000 (09:15 +0000)
committerjsg <jsg@openbsd.org>
Sat, 3 Feb 2024 09:15:57 +0000 (09:15 +0000)
found by "passing freed memory 'edid'" smatch warning

sys/dev/pci/drm/drm_edid.c

index 3766ff2..ba92bd0 100644 (file)
@@ -2120,8 +2120,10 @@ static struct edid *edid_filter_invalid_blocks(struct edid *edid,
                kfree(edid);
 #else
        new = kmalloc(*alloc_size, GFP_KERNEL);
-       if (!new)
+       if (!new) {
                kfree(edid);
+               return NULL;
+       }
        memcpy(new, edid, EDID_LENGTH);
        kfree(edid);
 #endif