From: Ivan Priest Date: Wed, 13 Feb 2019 11:51:17 +0000 (+0000) Subject: [NEUS7920-133]wlbt: allow MAC address file to be in /proc X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=77c3261cae6d7c7177d39c1b880a3c1e30302ac9;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git [NEUS7920-133]wlbt: allow MAC address file to be in /proc 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 --- diff --git a/drivers/misc/samsung/scsc/mx140_file.c b/drivers/misc/samsung/scsc/mx140_file.c index 40e918e6f88a..3df437ef60fc 100644 --- a/drivers/misc/samsung/scsc/mx140_file.c +++ b/drivers/misc/samsung/scsc/mx140_file.c @@ -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); diff --git a/drivers/net/wireless/scsc/mgt.c b/drivers/net/wireless/scsc/mgt.c index ed0d3e1d1ec1..37e73fa73dff 100755 --- a/drivers/net/wireless/scsc/mgt.c +++ b/drivers/net/wireless/scsc/mgt.c @@ -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: