Skip to contentSkip to conversation

viafb: NULL dereference on allocation failure in query_edid()

PATCH In review Dan Carpenter 2 participants 2 messages Feb 17, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 viafb: NULL dereference on allocation failure in query_edid()

We should handle the allocation here, if only to keep the static checkers happy.

drivers/video/via/via_aux_edid.c +5 -2
index 03f7a41..754d450 100644
@@ -36,10 +36,13 @@ static void query_edid(struct via_aux_drv *drv)
 	unsigned char edid[EDID_LENGTH];
 	bool valid = false;
 
-	if (spec)
+	if (spec) {
 		fb_destroy_modedb(spec->modedb);
-	else
+	} else {
 		spec = kmalloc(sizeof(*spec), GFP_KERNEL);
+		if (!spec)
+			return;
+	}
 
 	spec->version = spec->revision = 0;
 	if (via_aux_read(drv, 0x00, edid, EDID_LENGTH)) {
#1 lore raw
Quoted 4 lines · Dan Carpenter

We should handle the allocation here, if only to keep the static checkers happy.

Ah, thanks for noticing it and sorry that I introduced it in the first place. Applied.

Thanks,

Florian Tobias Schandinat

Quoted 22 lines
drivers/video/via/via_aux_edid.c +5 -2
index 03f7a41..754d450 100644
@@ -36,10 +36,13 @@ static void query_edid(struct via_aux_drv *drv)
 	unsigned char edid[EDID_LENGTH];
 	bool valid = false;
 
-	if (spec)
+	if (spec) {
 		fb_destroy_modedb(spec->modedb);
-	else
+	} else {
 		spec = kmalloc(sizeof(*spec), GFP_KERNEL);
+		if (!spec)
+			return;
+	}
 
 	spec->version = spec->revision = 0;
 	if (via_aux_read(drv, 0x00, edid, EDID_LENGTH)) {