kernel: generic: fix fonfxc uimage parser
[openwrt/openwrt.git] / target / linux / generic / files / drivers / mtd / mtdsplit / mtdsplit_uimage.c
index 091403ae9186baa1827e942bf3948783aba04a4f..2ac559a3f3a2326460e167374c46ef3b3dfdc77e 100644 (file)
@@ -398,22 +398,29 @@ static ssize_t uimage_find_fonfxc(u_char *buf, size_t len, int *extralen)
        return 0;
 }
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
+static const struct of_device_id mtdsplit_uimage_fonfxc_of_match_table[] = {
+       { .compatible = "fonfxc,uimage" },
+       {},
+};
+#endif
+
 static int
 mtdsplit_uimage_parse_fonfxc(struct mtd_info *master,
                              const struct mtd_partition **pparts,
                              struct mtd_part_parser_data *data)
 {
+       struct device_node *np_mtd;
+
+       np_mtd = mtd_get_of_node(master);
+       if (!np_mtd ||
+           !of_match_node(mtdsplit_uimage_fonfxc_of_match_table, np_mtd))
+               return -ENODEV;
+
        return __mtdsplit_parse_uimage(master, pparts, data,
                                       uimage_find_fonfxc);
 }
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
-static const struct of_device_id mtdsplit_uimage_fonfxc_of_match_table[] = {
-       { .compatible = "fonfxc,uimage" },
-       {},
-};
-#endif
-
 static struct mtd_part_parser uimage_fonfxc_parser = {
        .owner = THIS_MODULE,
        .name = "fonfxc-fw",