From 58c150be956b8cb43e019f3f9646a6662a0bb608 Mon Sep 17 00:00:00 2001 From: Michael Benedict Date: Fri, 26 Apr 2019 01:21:58 +1000 Subject: [PATCH] drivers: touchscreen: fix strncat-size warnings S10 sec_ts as reference Signed-off-by: Michael Benedict --- drivers/input/touchscreen/sec_ts/sec_ts_fn.c | 56 ++++++++++---------- drivers/input/touchscreen/stm/fts_sec.c | 14 ++--- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/drivers/input/touchscreen/sec_ts/sec_ts_fn.c b/drivers/input/touchscreen/sec_ts/sec_ts_fn.c index 67e5c0c46cab..c8bc4fbb47d9 100644 --- a/drivers/input/touchscreen/sec_ts/sec_ts_fn.c +++ b/drivers/input/touchscreen/sec_ts/sec_ts_fn.c @@ -604,7 +604,7 @@ static ssize_t read_pressure_raw_check_show(struct device *dev, char tmp[20] = {0}; snprintf(tmp, sizeof(tmp), "\"TP%02d%c\":\"%d\"", data[i], loc[j], ts->pressure_data[data[i]][j]); - strncat(buff, tmp, sizeof(tmp)); + strlcat(buff, tmp, sizeof(buff)); if (i < 3 || j < PRESSURE_CHANNEL_NUM - 1) strncat(buff, ",", 2); } @@ -650,13 +650,13 @@ static ssize_t read_ambient_channel_info_show(struct device *dev, for (i = 0; i < ts->tx_count; i++) { snprintf(temp, sizeof(temp), "\"TAMB_TX%02d\":\"%d\",", i, ts->ambient_tx[i]); - strncat(buffer, temp, sizeof(temp)); + strlcat(buffer, temp, (ts->tx_count + ts->rx_count) * 25); } for (i = 0; i < ts->rx_count; i++) { snprintf(temp, sizeof(temp), "\"TAMB_RX%02d\":\"%d\"", i, ts->ambient_rx[i]); - strncat(buffer, temp, sizeof(temp)); + strlcat(buffer, temp, (ts->tx_count + ts->rx_count) * 25); if (i != (ts->rx_count - 1)) strncat(buffer, ",", 2); } @@ -688,13 +688,13 @@ static ssize_t read_ambient_channel_delta_show(struct device *dev, for (i = 0; i < ts->tx_count; i++) { snprintf(temp, sizeof(temp), "\"TCDT%02d\":\"%d\",", i, ts->ambient_tx_delta[i]); - strncat(buffer, temp, sizeof(temp)); + strlcat(buffer, temp, (ts->tx_count + ts->rx_count) * 25); } for (i = 0; i < ts->rx_count; i++) { snprintf(temp, sizeof(temp), "\"TCDR%02d\":\"%d\"", i, ts->ambient_rx_delta[i]); - strncat(buffer, temp, sizeof(temp)); + strlcat(buffer, temp, (ts->tx_count + ts->rx_count) * 25); if (i != (ts->rx_count - 1)) strncat(buffer, ",", 2); } @@ -780,7 +780,7 @@ static ssize_t get_lp_dump(struct device *dev, struct device_attribute *attr, ch snprintf(buff, sizeof(buff), "%d: %04x%04x%04x%04x\n", string_addr, data0, data1, data2, data3); - strncat(buf, buff, sizeof(buff)); + strlcat(buf, buff, PAGE_SIZE); } } @@ -836,21 +836,21 @@ static ssize_t ic_status_show(struct device *dev, return snprintf(buf, SEC_CMD_BUF_SIZE, "%s\n", buff); snprintf(temp, sizeof(temp), "mutual,%d,", data[0] & 0x01 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); snprintf(temp, sizeof(temp), "hover,%d,", data[0] & 0x02 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); snprintf(temp, sizeof(temp), "cover,%d,", data[0] & 0x04 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); snprintf(temp, sizeof(temp), "glove,%d,", data[0] & 0x08 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); snprintf(temp, sizeof(temp), "stylus,%d,", data[0] & 0x10 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); snprintf(temp, sizeof(temp), "palm,%d,", data[0] & 0x20 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); snprintf(temp, sizeof(temp), "wet,%d,", data[0] & 0x40 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); snprintf(temp, sizeof(temp), "prox,%d,", data[0] & 0x80 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); memset(data, 0x00, 2); ret = ts->sec_ts_i2c_read(ts, SEC_TS_CMD_SET_POWER_MODE, data, 1); @@ -858,13 +858,13 @@ static ssize_t ic_status_show(struct device *dev, return snprintf(buf, SEC_CMD_BUF_SIZE, "%s\n", buff); snprintf(temp, sizeof(temp), "npm,%d,", data[0] == 0 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); snprintf(temp, sizeof(temp), "lpm,%d,", data[0] == 1 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); snprintf(temp, sizeof(temp), "test,%d,", data[0] == 2 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); snprintf(temp, sizeof(temp), "flash,%d,", data[0] == 3 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); memset(data, 0x00, 2); ret = ts->sec_ts_i2c_read(ts, SET_TS_CMD_SET_CHARGER_MODE, data, 1); @@ -872,11 +872,11 @@ static ssize_t ic_status_show(struct device *dev, return snprintf(buf, SEC_CMD_BUF_SIZE, "%s\n", buff); snprintf(temp, sizeof(temp), "no_charge,%d,", data[0] == 0 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); snprintf(temp, sizeof(temp), "wire_charge,%d,", data[0] == 1 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); snprintf(temp, sizeof(temp), "wireless_charge,%d,", data[0] == 2 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); memset(data, 0x00, 2); ret = ts->sec_ts_i2c_read(ts, SET_TS_CMD_SET_NOISE_MODE, data, 1); @@ -884,7 +884,7 @@ static ssize_t ic_status_show(struct device *dev, return snprintf(buf, SEC_CMD_BUF_SIZE, "%s\n", buff); snprintf(temp, sizeof(temp), "noise,%d,", data[0]); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); memset(data, 0x00, 2); ret = ts->sec_ts_i2c_read(ts, SEC_TS_CMD_SET_COVERTYPE, data, 1); @@ -892,7 +892,7 @@ static ssize_t ic_status_show(struct device *dev, return snprintf(buf, SEC_CMD_BUF_SIZE, "%s\n", buff); snprintf(temp, sizeof(temp), "cover_type,%d,", data[0]); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); memset(data, 0x00, 2); ret = ts->sec_ts_read_sponge(ts, data, 1); @@ -900,13 +900,13 @@ static ssize_t ic_status_show(struct device *dev, return snprintf(buf, SEC_CMD_BUF_SIZE, "%s\n", buff); snprintf(temp, sizeof(temp), "pressure,%d,", data[0] & 0x40 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); snprintf(temp, sizeof(temp), "aod,%d,", data[0] & 0x04 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); snprintf(temp, sizeof(temp), "spay,%d,", data[0] & 0x02 ? 1 : 0); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); snprintf(temp, sizeof(temp), "singletap,%d,", data[0] & 0x08 ? 1 : 0); strncat(buff, temp, sizeof(temp)); @@ -918,7 +918,7 @@ static ssize_t ic_status_show(struct device *dev, return snprintf(buf, SEC_CMD_BUF_SIZE, "%s\n", buff); snprintf(temp, sizeof(temp), "dex,%d,", data[0]); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); data[0] = 0; @@ -927,7 +927,7 @@ static ssize_t ic_status_show(struct device *dev, return snprintf(buf, SEC_CMD_BUF_SIZE, "%s\n", buff); snprintf(temp, sizeof(temp), "artcanvas,%d,", data[0]); - strncat(buff, temp, sizeof(temp)); + strlcat(buff, temp, sizeof(buff)); input_info(true, &ts->client->dev, "%s: %s\n", __func__, buff); diff --git a/drivers/input/touchscreen/stm/fts_sec.c b/drivers/input/touchscreen/stm/fts_sec.c index 8aaafb6cd296..21f3ba31e065 100644 --- a/drivers/input/touchscreen/stm/fts_sec.c +++ b/drivers/input/touchscreen/stm/fts_sec.c @@ -627,14 +627,14 @@ static ssize_t read_ambient_channel_info_show(struct device *dev, for (i = 0; i < info->ForceChannelLength; i++) { snprintf(temp, sizeof(temp), "\"TAMB_TX%02d\":\"%d\",", i, info->baseline_tx[i]); - strncat(buffer, temp, sizeof(temp)); + strlcat(buffer, temp, (info->ForceChannelLength + info->SenseChannelLength) * 25); } for (i = 0; i < info->SenseChannelLength; i++) { snprintf(temp, sizeof(temp), "\"TAMB_RX%02d\":\"%d\"", i, info->baseline_rx[i]); if (strnlen(buffer, (info->ForceChannelLength + info->SenseChannelLength) * 25) <= 893) { - strncat(buffer, temp, sizeof(temp)); + strlcat(buffer, temp, (info->ForceChannelLength + info->SenseChannelLength) * 25); if (i != (info->SenseChannelLength - 1)) strncat(buffer, ",", 2); } @@ -667,13 +667,13 @@ static ssize_t read_ambient_channel_delta_show(struct device *dev, for (i = 0; i < info->ForceChannelLength; i++) { snprintf(temp, sizeof(temp), "\"TCDT%02d\":\"%d\",", i, info->baseline_tx_delta[i]); - strncat(buffer, temp, sizeof(temp)); + strlcat(buffer, temp, (info->ForceChannelLength + info->SenseChannelLength) * 25); } for (i = 0; i < info->SenseChannelLength; i++) { snprintf(temp, sizeof(temp), "\"TCDR%02d\":\"%d\"", i, info->baseline_rx_delta[i]); - strncat(buffer, temp, sizeof(temp)); + strlcat(buffer, temp, (info->ForceChannelLength + info->SenseChannelLength) * 25); if (i != (info->SenseChannelLength - 1)) strncat(buffer, ",", 2); } @@ -775,7 +775,7 @@ static ssize_t get_lp_dump(struct device *dev, struct device_attribute *attr, ch snprintf(buff, sizeof(buff), "%d: %04x%04x%04x%04x\n", (string_addr - FTS_CMD_STRING_ACCESS), data0, data1, data2, data3); - strncat(buf, buff, sizeof(buff)); + strlcat(buf, buff, PAGE_SIZE); } } @@ -1853,7 +1853,7 @@ static void get_strength_all_data(void *device_data) for (j = 0; j < info->SenseChannelLength; j++) { snprintf(buff, sizeof(buff), "%d,", info->pFrame[(i * info->SenseChannelLength) + j]); - strncat(all_strbuff, buff, sizeof(buff)); + strlcat(all_strbuff, buff, sizeof(all_strbuff)); } } @@ -2772,7 +2772,7 @@ static void get_cx_all_data(void *device_data) for(i = 0; i < rx_num; i++){ info->cx_data[(j * rx_num) + i] = ReadData[j][i + 1]; snprintf(buff, sizeof(buff), "%d,", ReadData[j][i + 1]); - strncat(all_strbuff, buff, sizeof(buff)); + strlcat(all_strbuff, buff, sizeof(all_strbuff)); } } } -- 2.20.1