From: Thibaut VARÈNE Date: Wed, 13 May 2020 16:42:45 +0000 (+0200) Subject: generic: platform/mikrotik: rb_hardconfig.c minor fixes X-Git-Tag: v21.02.0-rc1~2666 X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=39ec3c5986e5109c3f1dd63b27d884606453191b;p=openwrt%2Fstaging%2Fhauke.git generic: platform/mikrotik: rb_hardconfig.c minor fixes For the sake of strictly typed code, add a missing const qualifier. Add a missing return value in error path. Check the return value of mtd_read(), for good measure. Also demote the error printks of failed sysfs file creation to warn level since they are not fatal in the init() sequence. Finally, add a note regarding PAGE_SIZE and clarify a comment. Tested-by: Koen Vandeputte Tested-by: Roger Pueyo Centelles Signed-off-by: Thibaut VARÈNE --- diff --git a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c index 2a059a4d25..4bcbb75e6f 100644 --- a/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c +++ b/target/linux/generic/files/drivers/platform/mikrotik/rb_hardconfig.c @@ -18,6 +18,9 @@ * the MTD device without using a local buffer (except when requesting WLAN * calibration data), at the cost of a performance penalty. * + * Note: PAGE_SIZE is assumed to be >= 4K, hence the device attribute show + * routines need not check for output overflow. + * * Some constant defines extracted from routerboot.{c,h} by Gabor Juhos * */ @@ -36,7 +39,7 @@ #include "routerboot.h" -#define RB_HARDCONFIG_VER "0.03" +#define RB_HARDCONFIG_VER "0.04" #define RB_HC_PR_PFX "[rb_hardconfig] " /* ID values for hardware settings */ @@ -508,9 +511,9 @@ static int hc_wlan_data_unpack_lzor(const u8 *inbuf, size_t inlen, if (ret) { if (LZO_E_INPUT_NOT_CONSUMED == ret) { /* - * It is assumed that because the LZO payload is embedded - * in a "root" RB_ID_WLAN_DATA tag, the tag length is aligned - * and the payload is padded at the end, which triggers a + * The tag length appears to always be aligned (probably + * because it is the "root" RB_ID_WLAN_DATA tag), thus + * the LZO payload may be padded, which can trigger a * spurious error which we ignore here. */ pr_debug(RB_HC_PR_PFX "LZOR: LZO EOF before buffer end - this may be harmless\n"); @@ -529,6 +532,7 @@ static int hc_wlan_data_unpack_lzor(const u8 *inbuf, size_t inlen, while (RB_MAGIC_ERD != *needle++) { if ((u8 *)needle >= tempbuf+templen) { pr_debug(RB_HC_PR_PFX "LZOR: ERD magic not found\n"); + ret = -ENODATA; goto fail; } }; @@ -603,7 +607,7 @@ static int hc_wlan_data_unpack(const size_t tofs, size_t tlen, static ssize_t hc_attr_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - struct hc_attr *hc_attr; + const struct hc_attr *hc_attr; const u8 *pld; u16 pld_len; @@ -688,6 +692,9 @@ int __init rb_hardconfig_init(struct kobject *rb_kobj) ret = mtd_read(mtd, 0, hc_buflen, &bytes_read, hc_buf); + if (ret) + goto fail; + if (bytes_read != hc_buflen) { ret = -EIO; goto fail; @@ -729,14 +736,14 @@ int __init rb_hardconfig_init(struct kobject *rb_kobj) ret = sysfs_create_bin_file(hc_kobj, &hc_wlandata_battr.battr); if (ret) - pr_err(RB_HC_PR_PFX "Could not create %s sysfs entry (%d)\n", + pr_warn(RB_HC_PR_PFX "Could not create %s sysfs entry (%d)\n", hc_wlandata_battr.battr.attr.name, ret); } /* All other tags are published via standard attributes */ else { ret = sysfs_create_file(hc_kobj, &hc_attrs[i].kattr.attr); if (ret) - pr_err(RB_HC_PR_PFX "Could not create %s sysfs entry (%d)\n", + pr_warn(RB_HC_PR_PFX "Could not create %s sysfs entry (%d)\n", hc_attrs[i].kattr.attr.name, ret); } }