diff --git a/drivers/mmi_info/mmi_info_main.c b/drivers/mmi_info/mmi_info_main.c index 6e106fb6e0e2..9b523b1dc2e3 100644 --- a/drivers/mmi_info/mmi_info_main.c +++ b/drivers/mmi_info/mmi_info_main.c @@ -93,87 +93,7 @@ bool mmi_device_is_available(struct device_node *np) } EXPORT_SYMBOL(mmi_device_is_available); -#ifdef CONFIG_BOOT_CONFIG -#include -#include -#include -//#include -#define BOOTCONFIG_FULLPATH "/proc/bootconfig" -static char bootconfig_tmp[256]; - - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) -static inline ssize_t kernel_read_stub(struct file *file, void *addr, size_t count) -{ - loff_t pos = 0; - return kernel_read(file, addr, count, &pos); -} -#else -static inline ssize_t kernel_read_stub(struct file *file, void *addr, size_t count) -{ - return kernel_read(file, 0, addr, count); -} -#endif - -static int mmi_get_bootarg_bootconfig(const char *bootconfig_key, char **bootconfig_val) -{ - struct file *filep = NULL; - char *xbc_buf = NULL; - int bytes = 0; - char *start_bootdevice = NULL; - int rc = 0; - - filep = filp_open(BOOTCONFIG_FULLPATH, O_RDONLY, 0600); - if (IS_ERR_OR_NULL(filep)) { - rc = PTR_ERR(filep); - pr_err("opening (%s) errno=%d\n", BOOTCONFIG_FULLPATH, rc); - return rc; - } - - xbc_buf = kzalloc(XBC_DATA_MAX, GFP_KERNEL); - if (!xbc_buf) { - pr_err("alloc len %d memory fail\n", XBC_DATA_MAX); - filp_close(filep, NULL); - return -ENOMEM; - - } - - bytes = kernel_read_stub(filep, (void *) xbc_buf, XBC_DATA_MAX); - pr_debug("read bootconfig bytes %d\n", bytes); - if (bytes <= 0) { - pr_err("fail read bytes %d\n", bytes); - kfree(xbc_buf); - filp_close(filep, NULL); - return -EIO; - } - - start_bootdevice = strstr(xbc_buf, bootconfig_key); - if (start_bootdevice) { - char *p = start_bootdevice + strlen(bootconfig_key); - int i = 0; - - memset(bootconfig_tmp, 0, sizeof(bootconfig_tmp)); - while (p && *p && (*p != '\n') && (*p != '"') - && (i < sizeof(bootconfig_tmp))) { - bootconfig_tmp[i] = *p; - i++; - p++; - } - *bootconfig_val = bootconfig_tmp; - pr_info("bootconfig key %s%s\"\n", bootconfig_key, *bootconfig_val); - } else { - pr_err("cannot find key %s\n", bootconfig_key); - rc = -ENOENT; - } - - kfree(xbc_buf); - filp_close(filep, NULL); - - return rc; -} -#else - -static int mmi_get_bootarg_cmdline(char *key, char **value) +static int mmi_get_bootarg_dt(char *key, char **value, char *prop, char *spl_flag) { const char *bootargs_tmp = NULL; char *idx = NULL; @@ -185,7 +105,7 @@ static int mmi_get_bootarg_cmdline(char *key, char **value) if (n == NULL) goto err; - if (of_property_read_string(n, "bootargs", &bootargs_tmp) != 0) + if (of_property_read_string(n, prop, &bootargs_tmp) != 0) goto putnode; bootargs_tmp_len = strlen(bootargs_tmp); @@ -204,7 +124,7 @@ static int mmi_get_bootarg_cmdline(char *key, char **value) kvpair = strsep(&idx, " "); if (kvpair) if (strsep(&kvpair, "=")) { - *value = strsep(&kvpair, " "); + *value = strsep(&kvpair, spl_flag); if (*value) err = 0; } @@ -215,19 +135,13 @@ putnode: err: return err; } -#endif int mmi_get_bootarg(char *key, char **value) { #ifdef CONFIG_BOOT_CONFIG - char *tmp_buf = " = \""; - char new_key[256]; - memset(new_key, 0x0, 256); - memcpy(new_key, key, strlen(key) - 1); - strcat(new_key, tmp_buf); - return mmi_get_bootarg_bootconfig(new_key, value); + return mmi_get_bootarg_dt(key, value, "mmi,bootconfig", "\n"); #else - return mmi_get_bootarg_cmdline(key, value); + return mmi_get_bootarg_dt(key, value, "bootargs", " "); #endif }