kernel: fix a memory leak in split_rootfs_data()
allocate_partition() copies all the content of dpart into a new struct. SVN-Revision: 36475
This commit is contained in:
parent
c807a7737f
commit
e7e4afbb64
2 changed files with 20 additions and 42 deletions
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MTD methods which simply translate the effective address and pass through
|
* MTD methods which simply translate the effective address and pass through
|
||||||
@@ -613,6 +615,155 @@ int mtd_del_partition(struct mtd_info *m
|
@@ -613,6 +615,144 @@ int mtd_del_partition(struct mtd_info *m
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(mtd_del_partition);
|
EXPORT_SYMBOL_GPL(mtd_del_partition);
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@
|
||||||
+
|
+
|
||||||
+static int split_rootfs_data(struct mtd_info *master, struct mtd_info *rpart, const struct mtd_partition *part)
|
+static int split_rootfs_data(struct mtd_info *master, struct mtd_info *rpart, const struct mtd_partition *part)
|
||||||
+{
|
+{
|
||||||
+ struct mtd_partition *dpart;
|
+ struct mtd_partition dpart;
|
||||||
+ struct mtd_part *slave = NULL;
|
+ struct mtd_part *slave = NULL;
|
||||||
+ struct mtd_part *spart;
|
+ struct mtd_part *spart;
|
||||||
+ int ret, split_offset = 0;
|
+ int ret, split_offset = 0;
|
||||||
|
@ -101,27 +101,16 @@
|
||||||
+ if (split_offset <= 0)
|
+ if (split_offset <= 0)
|
||||||
+ return 0;
|
+ return 0;
|
||||||
+
|
+
|
||||||
+ dpart = kmalloc(sizeof(*part)+sizeof(ROOTFS_SPLIT_NAME)+1, GFP_KERNEL);
|
+ memcpy(&dpart, part, sizeof(dpart));
|
||||||
+ if (dpart == NULL) {
|
+ dpart.name = ROOTFS_SPLIT_NAME;
|
||||||
+ printk(KERN_INFO "split_squashfs: no memory for partition \"%s\"\n",
|
|
||||||
+ ROOTFS_SPLIT_NAME);
|
|
||||||
+ return -ENOMEM;
|
|
||||||
+ }
|
|
||||||
+
|
+
|
||||||
+ memcpy(dpart, part, sizeof(*part));
|
+ dpart.size = rpart->size - (split_offset - spart->offset);
|
||||||
+ dpart->name = (unsigned char *)&dpart[1];
|
+ dpart.offset = split_offset;
|
||||||
+ strcpy(dpart->name, ROOTFS_SPLIT_NAME);
|
|
||||||
+
|
|
||||||
+ dpart->size = rpart->size - (split_offset - spart->offset);
|
|
||||||
+ dpart->offset = split_offset;
|
|
||||||
+
|
|
||||||
+ if (dpart == NULL)
|
|
||||||
+ return 1;
|
|
||||||
+
|
+
|
||||||
+ printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=%llX, len=%llX \n",
|
+ printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=%llX, len=%llX \n",
|
||||||
+ ROOTFS_SPLIT_NAME, dpart->offset, dpart->size);
|
+ ROOTFS_SPLIT_NAME, dpart.offset, dpart.size);
|
||||||
+
|
+
|
||||||
+ slave = allocate_partition(master, dpart, 0, split_offset);
|
+ slave = allocate_partition(master, &dpart, 0, split_offset);
|
||||||
+ if (IS_ERR(slave))
|
+ if (IS_ERR(slave))
|
||||||
+ return PTR_ERR(slave);
|
+ return PTR_ERR(slave);
|
||||||
+ mutex_lock(&mtd_partitions_mutex);
|
+ mutex_lock(&mtd_partitions_mutex);
|
||||||
|
@ -191,7 +180,7 @@
|
||||||
/*
|
/*
|
||||||
* This function, given a master MTD object and a partition table, creates
|
* This function, given a master MTD object and a partition table, creates
|
||||||
* and registers slave MTD objects which are bound to the master according to
|
* and registers slave MTD objects which are bound to the master according to
|
||||||
@@ -629,6 +780,9 @@ int add_mtd_partitions(struct mtd_info *
|
@@ -629,6 +769,9 @@ int add_mtd_partitions(struct mtd_info *
|
||||||
struct mtd_part *slave;
|
struct mtd_part *slave;
|
||||||
uint64_t cur_offset = 0;
|
uint64_t cur_offset = 0;
|
||||||
int i;
|
int i;
|
||||||
|
@ -201,7 +190,7 @@
|
||||||
|
|
||||||
printk(KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name);
|
printk(KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name);
|
||||||
|
|
||||||
@@ -643,12 +797,53 @@ int add_mtd_partitions(struct mtd_info *
|
@@ -643,12 +786,53 @@ int add_mtd_partitions(struct mtd_info *
|
||||||
|
|
||||||
add_mtd_device(&slave->mtd);
|
add_mtd_device(&slave->mtd);
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MTD methods which simply translate the effective address and pass through
|
* MTD methods which simply translate the effective address and pass through
|
||||||
@@ -613,6 +615,155 @@ int mtd_del_partition(struct mtd_info *m
|
@@ -613,6 +615,144 @@ int mtd_del_partition(struct mtd_info *m
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(mtd_del_partition);
|
EXPORT_SYMBOL_GPL(mtd_del_partition);
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@
|
||||||
+
|
+
|
||||||
+static int split_rootfs_data(struct mtd_info *master, struct mtd_info *rpart, const struct mtd_partition *part)
|
+static int split_rootfs_data(struct mtd_info *master, struct mtd_info *rpart, const struct mtd_partition *part)
|
||||||
+{
|
+{
|
||||||
+ struct mtd_partition *dpart;
|
+ struct mtd_partition dpart;
|
||||||
+ struct mtd_part *slave = NULL;
|
+ struct mtd_part *slave = NULL;
|
||||||
+ struct mtd_part *spart;
|
+ struct mtd_part *spart;
|
||||||
+ int ret, split_offset = 0;
|
+ int ret, split_offset = 0;
|
||||||
|
@ -101,27 +101,16 @@
|
||||||
+ if (split_offset <= 0)
|
+ if (split_offset <= 0)
|
||||||
+ return 0;
|
+ return 0;
|
||||||
+
|
+
|
||||||
+ dpart = kmalloc(sizeof(*part)+sizeof(ROOTFS_SPLIT_NAME)+1, GFP_KERNEL);
|
+ memcpy(&dpart, part, sizeof(dpart));
|
||||||
+ if (dpart == NULL) {
|
+ dpart.name = ROOTFS_SPLIT_NAME;
|
||||||
+ printk(KERN_INFO "split_squashfs: no memory for partition \"%s\"\n",
|
|
||||||
+ ROOTFS_SPLIT_NAME);
|
|
||||||
+ return -ENOMEM;
|
|
||||||
+ }
|
|
||||||
+
|
+
|
||||||
+ memcpy(dpart, part, sizeof(*part));
|
+ dpart.size = rpart->size - (split_offset - spart->offset);
|
||||||
+ dpart->name = (unsigned char *)&dpart[1];
|
+ dpart.offset = split_offset;
|
||||||
+ strcpy(dpart->name, ROOTFS_SPLIT_NAME);
|
|
||||||
+
|
|
||||||
+ dpart->size = rpart->size - (split_offset - spart->offset);
|
|
||||||
+ dpart->offset = split_offset;
|
|
||||||
+
|
|
||||||
+ if (dpart == NULL)
|
|
||||||
+ return 1;
|
|
||||||
+
|
+
|
||||||
+ printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=%llX, len=%llX \n",
|
+ printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=%llX, len=%llX \n",
|
||||||
+ ROOTFS_SPLIT_NAME, dpart->offset, dpart->size);
|
+ ROOTFS_SPLIT_NAME, dpart.offset, dpart.size);
|
||||||
+
|
+
|
||||||
+ slave = allocate_partition(master, dpart, 0, split_offset);
|
+ slave = allocate_partition(master, &dpart, 0, split_offset);
|
||||||
+ if (IS_ERR(slave))
|
+ if (IS_ERR(slave))
|
||||||
+ return PTR_ERR(slave);
|
+ return PTR_ERR(slave);
|
||||||
+ mutex_lock(&mtd_partitions_mutex);
|
+ mutex_lock(&mtd_partitions_mutex);
|
||||||
|
@ -191,7 +180,7 @@
|
||||||
/*
|
/*
|
||||||
* This function, given a master MTD object and a partition table, creates
|
* This function, given a master MTD object and a partition table, creates
|
||||||
* and registers slave MTD objects which are bound to the master according to
|
* and registers slave MTD objects which are bound to the master according to
|
||||||
@@ -629,6 +780,9 @@ int add_mtd_partitions(struct mtd_info *
|
@@ -629,6 +769,9 @@ int add_mtd_partitions(struct mtd_info *
|
||||||
struct mtd_part *slave;
|
struct mtd_part *slave;
|
||||||
uint64_t cur_offset = 0;
|
uint64_t cur_offset = 0;
|
||||||
int i;
|
int i;
|
||||||
|
@ -201,7 +190,7 @@
|
||||||
|
|
||||||
printk(KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name);
|
printk(KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name);
|
||||||
|
|
||||||
@@ -643,12 +797,53 @@ int add_mtd_partitions(struct mtd_info *
|
@@ -643,12 +786,53 @@ int add_mtd_partitions(struct mtd_info *
|
||||||
|
|
||||||
add_mtd_device(&slave->mtd);
|
add_mtd_device(&slave->mtd);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue