[NEUS7920-133]wlbt: allow MAC address file to be in /proc
authorIvan Priest <i.priest@samsung.com>
Wed, 13 Feb 2019 11:51:17 +0000 (11:51 +0000)
committerYoungmin Nam <youngmin.nam@samsung.com>
Tue, 21 May 2019 10:45:23 +0000 (19:45 +0900)
One customer is placing the MAC address in procfs, and
the current mx140_file reader cannot handle the
zero length virtual files. Fix this and check that
a loaded file contains a valid MAC address.

This is the replacement for conflicting customer code
that appeared upstream.

Change-Id: Ib606b16c6f07ddd86810772d54445780f000f96c
SCSC-Bug-Id: SSB-49343
Signed-off-by: Ivan Priest <i.priest@samsung.com>
drivers/misc/samsung/scsc/mx140_file.c
drivers/net/wireless/scsc/mgt.c

index 40e918e6f88a9878e56c49b392c8734721a53989..3df437ef60fcd171210a2caca4dff1e9b63b7978 100644 (file)
@@ -431,6 +431,27 @@ int mx140_request_file(struct scsc_mx *mx, char *path, const struct firmware **f
 
        fs = get_fs();
        set_fs(get_ds());
+
+       /* Special case if file length is reported as zero - try to read until it fails.
+        * This allows us to read /proc
+        */
+       if (whats_left == 0) {
+               do {
+                       r = vfs_read(f, p, max_read_size, &f->f_pos);
+                       if (r < 0) {
+                               SCSC_TAG_INFO(MX_FILE, "No more data %s\n", path);
+                               break;
+                       }
+                       p += r;
+                       if (r < max_read_size) {
+                               SCSC_TAG_INFO(MX_FILE, "Read %zd from %s\n", (ptrdiff_t)(p - buf), path);
+                               break;
+                       }
+               } while (r > 0);
+
+               goto done;
+       }
+
        /* Read at most max_read_size in each read. Loop until the whole file has
         * been copied to the local buffer.
         */
@@ -446,6 +467,7 @@ int mx140_request_file(struct scsc_mx *mx, char *path, const struct firmware **f
                whats_left -= r;
                p += r;
        }
+done:
        set_fs(fs);
        filp_close(f, NULL);
 
index ed0d3e1d1ec1ad21b2fce4be57f4cc71992d71a5..37e73fa73dfff377f98ec3d664940872ddebd8fc 100755 (executable)
@@ -192,6 +192,7 @@ void slsi_get_hw_mac_address(struct slsi_dev *sdev, u8 *addr)
        u32                   u[ETH_ALEN];
        char                  path_name[MX_WLAN_FILE_PATH_LEN_MAX];
        int                   r;
+       bool                  valid = false;
 
        /* read maddr_file */
        if (sdev->maddr_file_name) {
@@ -228,14 +229,29 @@ mac_efs:
        }
        r = sscanf(e->data, "%02X:%02X:%02X:%02X:%02X:%02X", &u[0], &u[1], &u[2], &u[3], &u[4], &u[5]);
        if (r != ETH_ALEN) {
-               SLSI_ERR(sdev, "%s exists, but format is incorrect (should be e.g. xx:xx:xx:xx:xx:xx)\n", path_name);
+               SLSI_ERR(sdev, "%s exists, but format is incorrect (%d) [%20s] (should be e.g. xx:xx:xx:xx:xx:xx)\n",
+                        CONFIG_SCSC_WLAN_MAC_ADDRESS_FILENAME, r, e->data);
                goto mac_default;
        }
-       for (i = 0; i < ETH_ALEN; i++)
+       for (i = 0; i < ETH_ALEN; i++) {
+               if (u[i] != 0xff)
+                       valid = true;
                addr[i] = u[i] & 0xff;
-       SLSI_INFO(sdev, "MAC address loaded from %s: %02X:%02X:%02X:%02X:%02X:%02X\n", CONFIG_SCSC_WLAN_MAC_ADDRESS_FILENAME, u[0], u[1], u[2], u[3], u[4], u[5]);
-       mx140_release_file(sdev->maxwell_core, e);
-       return;
+       }
+
+       /* If MAC address seems valid, finished */
+       if (valid) {
+               SLSI_INFO(sdev, "MAC address loaded from %s: %02X:%02X:%02X:%02X:%02X:%02X\n",
+                         CONFIG_SCSC_WLAN_MAC_ADDRESS_FILENAME, u[0], u[1], u[2], u[3], u[4], u[5]);
+
+               /* MAC address read could hold invalid values, try to fix it to normal address */
+               if (addr[0] & 0x01) {
+                       addr[0] = addr[0] & 0xfe;
+                       SLSI_INFO(sdev, "MAC address invalid, fixed address: %pM\n", addr);
+               }
+               mx140_release_file(sdev->maxwell_core, e);
+               return;
+       }
 #endif
 
 mac_default: