[package] libpcap: explicitely disable libnl support to prevent different build resul...
[openwrt.git] / target / linux / ar71xx / files / drivers / mtd / wrt160nl_part.c
index eabb47e..72927f6 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 
@@ -76,30 +77,40 @@ struct wrt160nl_header {
        struct uimage_header    uimage;
 } __attribute__ ((packed));
 
-static struct mtd_partition trx_parts[TRX_PARTS];
-
 #define WRT160NL_UBOOT_LEN     0x40000
 #define WRT160NL_ART_LEN       0x10000
 #define WRT160NL_NVRAM_LEN     0x10000
 
 static int wrt160nl_parse_partitions(struct mtd_info *master,
                                     struct mtd_partition **pparts,
-                                    unsigned long origin)
+                                    struct mtd_part_parser_data *data)
 {
        struct wrt160nl_header *header;
        struct trx_header *theader;
        struct uimage_header *uheader;
+       struct mtd_partition *trx_parts;
        size_t retlen;
        unsigned int kernel_len;
-       unsigned int uboot_len = max(master->erasesize, WRT160NL_UBOOT_LEN);
-       unsigned int nvram_len = max(master->erasesize, WRT160NL_NVRAM_LEN);
-       unsigned int art_len = max(master->erasesize, WRT160NL_ART_LEN);
+       unsigned int uboot_len;
+       unsigned int nvram_len;
+       unsigned int art_len;
        int ret;
 
+       uboot_len = max_t(unsigned int, master->erasesize, WRT160NL_UBOOT_LEN);
+       nvram_len = max_t(unsigned int, master->erasesize, WRT160NL_NVRAM_LEN);
+       art_len = max_t(unsigned int, master->erasesize, WRT160NL_ART_LEN);
+
+       trx_parts = kzalloc(TRX_PARTS * sizeof(struct mtd_partition),
+                           GFP_KERNEL);
+       if (!trx_parts) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
        header = vmalloc(sizeof(*header));
        if (!header) {
                return -ENOMEM;
-               goto out;
+               goto free_parts;
        }
 
        ret = master->read(master, uboot_len, sizeof(*header),
@@ -164,11 +175,15 @@ static int wrt160nl_parse_partitions(struct mtd_info *master,
        trx_parts[5].size = master->size - uboot_len - nvram_len - art_len;
        trx_parts[5].mask_flags = 0;
 
+       vfree(header);
+
        *pparts = trx_parts;
-       ret = TRX_PARTS;
+       return TRX_PARTS;
 
 free_hdr:
        vfree(header);
+free_parts:
+       kfree(trx_parts);
 out:
        return ret;
 }
This page took 0.025857 seconds and 4 git commands to generate.