// SPDX-License-Identifier: GPL-2.0 #ifndef __AVM_MTD_HELPER_H__ #define __AVM_MTD_HELPER_H__ #include #include #include #include static inline u8 prom_get_linux_fs(void) { const char *val; u8 fs; val = prom_getenv("linux_fs_start"); if (!val) return 0; if (kstrtou8(val, 10, &fs)) { pr_warn("linux_fs_start does not contain a valid number\n"); return 0; } return fs; } static inline int rename_mtd(struct mtd_info* mtd, const char *new_name) { const char *old_name; // Nothing to rename if (strcmp(mtd->name, new_name) == 0) return 0; old_name = mtd->name; mtd->name = kstrdup(new_name, GFP_KERNEL); if (!mtd->name) { mtd->name = old_name; return -ENOMEM; } pr_debug("Renamed %s to %s\n", old_name, new_name); // Only MTD_UBIVOLUME ensures that the name is kmalloc'd // For other types we will leak the old name if (mtd->type == MTD_UBIVOLUME) kfree(old_name); return 0; } extern struct mtd_notifier avm_mtd_rootfs_notifier; extern struct mtd_notifier avm_mtd_rename_fw_notifier;; extern struct mtd_notifier avm_mtd_rename_ubi_notifier; #endif