diff
--- a/drivers/gpu/drm/nouveau/nvkm/engine/firmware.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/firmware.c
@@ -9,11 +9,15 @@
 5 	fw->func = func;
 6 	fw->name = name;
 7 	fw->device = device;
-8 	fw->len = len;
+8 	fw->len = len; 
+> 	if (fw->func) {
 10 	switch (fw->func->type) {
 12 		fw->img = kmemdup(src, fw->len, GFP_KERNEL);
+> 			if (!fw->img)
+> 				return -ENOMEM;
 15 		len = ALIGN(fw->len, PAGE_SIZE);
+> 	}
 