generic: platform/mikrotik: fix incorrect test
[openwrt/openwrt.git] / target / linux / generic / files / drivers / platform / mikrotik / rb_hardconfig.c
index 4bcbb75e6f0218ee60e67ecfe2457606fc1831d5..8861814be440ac052539637f8737daf094c00f5c 100644 (file)
@@ -39,7 +39,7 @@
 
 #include "routerboot.h"
 
-#define RB_HARDCONFIG_VER              "0.04"
+#define RB_HARDCONFIG_VER              "0.05"
 #define RB_HC_PR_PFX                   "[rb_hardconfig] "
 
 /* ID values for hardware settings */
@@ -58,6 +58,7 @@
 #define RB_ID_BOARD_IDENTIFIER         0x17
 #define RB_ID_PRODUCT_NAME             0x21
 #define RB_ID_DEFCONF                  0x26
+#define RB_ID_BOARD_REVISION           0x27
 
 /* Bit definitions for hardware options */
 #define RB_HW_OPT_NO_UART              BIT(0)
@@ -310,30 +311,6 @@ static struct hc_hwopt {
        },
 };
 
-static ssize_t hc_tag_show_string(const u8 *pld, u16 pld_len, char *buf)
-{
-       return snprintf(buf, pld_len+1, "%s\n", pld);
-}
-
-static ssize_t hc_tag_show_u32(const u8 *pld, u16 pld_len, char *buf)
-{
-       char *out = buf;
-       u32 data;       // cpu-endian
-
-       /* Caller ensures pld_len > 0 */
-       if (pld_len % sizeof(data))
-               return -EINVAL;
-
-       data = *(u32 *)pld;
-
-       do {
-               out += sprintf(out, "0x%08x\n", data);
-               data++;
-       } while ((pld_len -= sizeof(data)));
-
-       return out - buf;
-}
-
 /*
  * The MAC is stored network-endian on all devices, in 2 32-bit segments:
  * <XX:XX:XX:XX> <XX:XX:00:00>. Kernel print has us covered.
@@ -394,7 +371,7 @@ static struct hc_attr {
 } hc_attrs[] = {
        {
                .tag_id = RB_ID_FLASH_INFO,
-               .tshow = hc_tag_show_u32,
+               .tshow = routerboot_tag_show_u32s,
                .kattr = __ATTR(flash_info, S_IRUSR, hc_attr_show, NULL),
        }, {
                .tag_id = RB_ID_MAC_ADDRESS_PACK,
@@ -402,23 +379,23 @@ static struct hc_attr {
                .kattr = __ATTR(mac_base, S_IRUSR, hc_attr_show, NULL),
        }, {
                .tag_id = RB_ID_BOARD_PRODUCT_CODE,
-               .tshow = hc_tag_show_string,
+               .tshow = routerboot_tag_show_string,
                .kattr = __ATTR(board_product_code, S_IRUSR, hc_attr_show, NULL),
        }, {
                .tag_id = RB_ID_BIOS_VERSION,
-               .tshow = hc_tag_show_string,
+               .tshow = routerboot_tag_show_string,
                .kattr = __ATTR(booter_version, S_IRUSR, hc_attr_show, NULL),
        }, {
                .tag_id = RB_ID_SERIAL_NUMBER,
-               .tshow = hc_tag_show_string,
+               .tshow = routerboot_tag_show_string,
                .kattr = __ATTR(board_serial, S_IRUSR, hc_attr_show, NULL),
        }, {
                .tag_id = RB_ID_MEMORY_SIZE,
-               .tshow = hc_tag_show_u32,
+               .tshow = routerboot_tag_show_u32s,
                .kattr = __ATTR(mem_size, S_IRUSR, hc_attr_show, NULL),
        }, {
                .tag_id = RB_ID_MAC_ADDRESS_COUNT,
-               .tshow = hc_tag_show_u32,
+               .tshow = routerboot_tag_show_u32s,
                .kattr = __ATTR(mac_count, S_IRUSR, hc_attr_show, NULL),
        }, {
                .tag_id = RB_ID_HW_OPTIONS,
@@ -429,16 +406,20 @@ static struct hc_attr {
                .tshow = NULL,
        }, {
                .tag_id = RB_ID_BOARD_IDENTIFIER,
-               .tshow = hc_tag_show_string,
+               .tshow = routerboot_tag_show_string,
                .kattr = __ATTR(board_identifier, S_IRUSR, hc_attr_show, NULL),
        }, {
                .tag_id = RB_ID_PRODUCT_NAME,
-               .tshow = hc_tag_show_string,
+               .tshow = routerboot_tag_show_string,
                .kattr = __ATTR(product_name, S_IRUSR, hc_attr_show, NULL),
        }, {
                .tag_id = RB_ID_DEFCONF,
-               .tshow = hc_tag_show_string,
+               .tshow = routerboot_tag_show_string,
                .kattr = __ATTR(defconf, S_IRUSR, hc_attr_show, NULL),
+       }, {
+               .tag_id = RB_ID_BOARD_REVISION,
+               .tshow = routerboot_tag_show_string,
+               .kattr = __ATTR(board_revision, S_IRUSR, hc_attr_show, NULL),
        }
 };
 
@@ -499,7 +480,7 @@ static int hc_wlan_data_unpack_lzor(const u8 *inbuf, size_t inlen,
        /* Temporary buffer same size as the outbuf */
        templen = *outlen;
        tempbuf = kmalloc(templen, GFP_KERNEL);
-       if (!outbuf)
+       if (!tempbuf)
                return -ENOMEM;
 
        /* Concatenate into the outbuf */
@@ -680,6 +661,9 @@ int __init rb_hardconfig_init(struct kobject *rb_kobj)
        int i, ret;
        u32 magic;
 
+       hc_buf = NULL;
+       hc_kobj = NULL;
+
        // TODO allow override
        mtd = get_mtd_device_nm(RB_MTD_HARD_CONFIG);
        if (IS_ERR(mtd))
@@ -754,6 +738,7 @@ int __init rb_hardconfig_init(struct kobject *rb_kobj)
 
 fail:
        kfree(hc_buf);
+       hc_buf = NULL;
        return ret;
 }