Skip to content

Commit b2a74d5

Browse files
author
Christoph Hellwig
committed
initramfs: remove clean_rootfs
There is no point in trying to clean up after unpacking the initramfs failed, as it should never get past the magic number check. In addition the current code only removes file that are direct children of the root entry, which wasn't complete anyway Fixes: df52092 ("fastboot: remove duplicate unpack_to_rootfs()") Reported-by: Marek Szyprowski <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 9ab6b71 commit b2a74d5

File tree

1 file changed

+1
-48
lines changed

1 file changed

+1
-48
lines changed

init/initramfs.c

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/utime.h>
1212
#include <linux/file.h>
1313
#include <linux/memblock.h>
14+
#include <linux/namei.h>
1415

1516
static ssize_t __init xwrite(int fd, const char *p, size_t count)
1617
{
@@ -572,53 +573,6 @@ static inline bool kexec_free_initrd(void)
572573
#endif /* CONFIG_KEXEC_CORE */
573574

574575
#ifdef CONFIG_BLK_DEV_RAM
575-
#define BUF_SIZE 1024
576-
static void __init clean_rootfs(void)
577-
{
578-
int fd;
579-
void *buf;
580-
struct linux_dirent64 *dirp;
581-
int num;
582-
583-
fd = ksys_open("/", O_RDONLY, 0);
584-
WARN_ON(fd < 0);
585-
if (fd < 0)
586-
return;
587-
buf = kzalloc(BUF_SIZE, GFP_KERNEL);
588-
WARN_ON(!buf);
589-
if (!buf) {
590-
ksys_close(fd);
591-
return;
592-
}
593-
594-
dirp = buf;
595-
num = ksys_getdents64(fd, dirp, BUF_SIZE);
596-
while (num > 0) {
597-
while (num > 0) {
598-
struct kstat st;
599-
int ret;
600-
601-
ret = vfs_lstat(dirp->d_name, &st);
602-
WARN_ON_ONCE(ret);
603-
if (!ret) {
604-
if (S_ISDIR(st.mode))
605-
ksys_rmdir(dirp->d_name);
606-
else
607-
ksys_unlink(dirp->d_name);
608-
}
609-
610-
num -= dirp->d_reclen;
611-
dirp = (void *)dirp + dirp->d_reclen;
612-
}
613-
dirp = buf;
614-
memset(buf, 0, BUF_SIZE);
615-
num = ksys_getdents64(fd, dirp, BUF_SIZE);
616-
}
617-
618-
ksys_close(fd);
619-
kfree(buf);
620-
}
621-
622576
static void __init populate_initrd_image(char *err)
623577
{
624578
ssize_t written;
@@ -658,7 +612,6 @@ static int __init populate_rootfs(void)
658612
err = unpack_to_rootfs((char *)initrd_start, initrd_end - initrd_start);
659613
if (err) {
660614
#ifdef CONFIG_BLK_DEV_RAM
661-
clean_rootfs();
662615
populate_initrd_image(err);
663616
#else
664617
printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err);

0 commit comments

Comments
 (0)