aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux
diff options
context:
space:
mode:
authorRafał Miłecki <zajec5@gmail.com>2015-02-12 07:44:34 +0000
committerRafał Miłecki <zajec5@gmail.com>2015-02-12 07:44:34 +0000
commit02c8dea914ad7d77ed8e2a06cca51569b27e699a (patch)
tree4a3e3aa55ec4299cbf0ee1f644578b43352f6734 /target/linux
parent8f970a79ae18422f46bc073416d6575ac863e998 (diff)
downloadupstream-02c8dea914ad7d77ed8e2a06cca51569b27e699a.tar.gz
upstream-02c8dea914ad7d77ed8e2a06cca51569b27e699a.tar.bz2
upstream-02c8dea914ad7d77ed8e2a06cca51569b27e699a.zip
kernel: mtdsplit_uimage: use separated buffer for reading data
We shouldn't read data directly into the header struct, as some devices (e.g. Edimax) need more bytes due to some extra header. Signed-off-by: Rafał Miłecki <zajec5@gmail.com> git-svn-id: svn://svn.openwrt.org/openwrt/trunk@44414 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'target/linux')
-rw-r--r--target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c
index 04a0eb47d7..eb4729a765 100644
--- a/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c
+++ b/target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c
@@ -49,15 +49,15 @@ struct uimage_header {
static int
read_uimage_header(struct mtd_info *mtd, size_t offset,
- struct uimage_header *header)
+ u_char *buf)
{
+ struct uimage_header *header;
size_t header_len;
size_t retlen;
int ret;
header_len = sizeof(*header);
- ret = mtd_read(mtd, offset, header_len, &retlen,
- (unsigned char *) header);
+ ret = mtd_read(mtd, offset, header_len, &retlen, buf);
if (ret) {
pr_debug("read error in \"%s\"\n", mtd->name);
return ret;
@@ -83,6 +83,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
ssize_t (*find_header)(u_char *buf, size_t len))
{
struct mtd_partition *parts;
+ u_char *buf;
struct uimage_header *header;
int nr_parts;
size_t offset;
@@ -98,8 +99,8 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
if (!parts)
return -ENOMEM;
- header = vmalloc(sizeof(*header));
- if (!header) {
+ buf = vmalloc(sizeof(*header));
+ if (!buf) {
ret = -ENOMEM;
goto err_free_parts;
}
@@ -108,20 +109,17 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
for (offset = 0; offset < master->size; offset += master->erasesize) {
uimage_size = 0;
- ret = read_uimage_header(master, offset, header);
+ ret = read_uimage_header(master, offset, buf);
if (ret)
continue;
- ret = find_header((u_char *)header, sizeof(*header));
+ ret = find_header(buf, sizeof(*buf));
if (ret < 0) {
pr_debug("no valid uImage found in \"%s\" at offset %llx\n",
master->name, (unsigned long long) offset);
continue;
}
- if (ret > 0) {
- pr_warn("extra header offsets are not supported yet\n");
- continue;
- }
+ header = (struct uimage_header *)(buf + ret);
uimage_size = sizeof(*header) + be32_to_cpu(header->ih_size);
if ((offset + uimage_size) > master->size) {
@@ -135,7 +133,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
if (uimage_size == 0) {
pr_debug("no uImage found in \"%s\"\n", master->name);
ret = -ENODEV;
- goto err_free_header;
+ goto err_free_buf;
}
uimage_offset = offset;
@@ -152,7 +150,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
if (ret) {
pr_debug("no rootfs after uImage in \"%s\"\n",
master->name);
- goto err_free_header;
+ goto err_free_buf;
}
rootfs_size = master->size - rootfs_offset;
@@ -166,7 +164,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
if (ret) {
pr_debug("no rootfs before uImage in \"%s\"\n",
master->name);
- goto err_free_header;
+ goto err_free_buf;
}
rootfs_offset = 0;
@@ -176,7 +174,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
if (rootfs_size == 0) {
pr_debug("no rootfs found in \"%s\"\n", master->name);
ret = -ENODEV;
- goto err_free_header;
+ goto err_free_buf;
}
parts[uimage_part].name = KERNEL_PART_NAME;
@@ -187,13 +185,13 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
parts[rf_part].offset = rootfs_offset;
parts[rf_part].size = rootfs_size;
- vfree(header);
+ vfree(buf);
*pparts = parts;
return nr_parts;
-err_free_header:
- vfree(header);
+err_free_buf:
+ vfree(buf);
err_free_parts:
kfree(parts);