forked from mirrors/linux
		
	initramfs: free initrd memory if opening /initrd.image fails
Patch series "initramfs tidyups". I've spent some time chasing down behavior in initramfs and found plenty of opportunity to improve the code. A first stab on that is contained in this series. This patch (of 7): We free the initrd memory for all successful or error cases except for the case where opening /initrd.image fails, which looks like an oversight. Steven said: : This also changes the behaviour when CONFIG_INITRAMFS_FORCE is enabled : - specifically it means that the initrd is freed (previously it was : ignored and never freed). But that seems like reasonable behaviour and : the previous behaviour looks like another oversight. Link: http://lkml.kernel.org/r/20190213174621.29297-3-hch@lst.de Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Steven Price <steven.price@arm.com> Acked-by: Mike Rapoport <rppt@linux.ibm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> [arm64] Cc: Geert Uytterhoeven <geert@linux-m68k.org> [m68k] Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Russell King <linux@armlinux.org.uk> Cc: Will Deacon <will.deacon@arm.com> Cc: Guan Xuetao <gxt@pku.edu.cn> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
		
							parent
							
								
									1df3a33907
								
							
						
					
					
						commit
						54c7a8916a
					
				
					 1 changed files with 6 additions and 8 deletions
				
			
		| 
						 | 
					@ -612,13 +612,12 @@ static int __init populate_rootfs(void)
 | 
				
			||||||
		printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n");
 | 
							printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n");
 | 
				
			||||||
		err = unpack_to_rootfs((char *)initrd_start,
 | 
							err = unpack_to_rootfs((char *)initrd_start,
 | 
				
			||||||
			initrd_end - initrd_start);
 | 
								initrd_end - initrd_start);
 | 
				
			||||||
		if (!err) {
 | 
							if (!err)
 | 
				
			||||||
			free_initrd();
 | 
					 | 
				
			||||||
			goto done;
 | 
								goto done;
 | 
				
			||||||
		} else {
 | 
					
 | 
				
			||||||
			clean_rootfs();
 | 
							clean_rootfs();
 | 
				
			||||||
			unpack_to_rootfs(__initramfs_start, __initramfs_size);
 | 
							unpack_to_rootfs(__initramfs_start, __initramfs_size);
 | 
				
			||||||
		}
 | 
					
 | 
				
			||||||
		printk(KERN_INFO "rootfs image is not initramfs (%s)"
 | 
							printk(KERN_INFO "rootfs image is not initramfs (%s)"
 | 
				
			||||||
				"; looks like an initrd\n", err);
 | 
									"; looks like an initrd\n", err);
 | 
				
			||||||
		fd = ksys_open("/initrd.image",
 | 
							fd = ksys_open("/initrd.image",
 | 
				
			||||||
| 
						 | 
					@ -632,7 +631,6 @@ static int __init populate_rootfs(void)
 | 
				
			||||||
				       written, initrd_end - initrd_start);
 | 
									       written, initrd_end - initrd_start);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			ksys_close(fd);
 | 
								ksys_close(fd);
 | 
				
			||||||
			free_initrd();
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	done:
 | 
						done:
 | 
				
			||||||
		/* empty statement */;
 | 
							/* empty statement */;
 | 
				
			||||||
| 
						 | 
					@ -642,9 +640,9 @@ static int __init populate_rootfs(void)
 | 
				
			||||||
			initrd_end - initrd_start);
 | 
								initrd_end - initrd_start);
 | 
				
			||||||
		if (err)
 | 
							if (err)
 | 
				
			||||||
			printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
 | 
								printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);
 | 
				
			||||||
		free_initrd();
 | 
					 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						free_initrd();
 | 
				
			||||||
	flush_delayed_fput();
 | 
						flush_delayed_fput();
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue