Use the generic sysfs_emit() function to take place of sprintf/snprintf/scnprintf, to avoid buffer overrun.
Tian Tao (3): iio:chemical:sps30: Convert sysfs sprintf/snprintf family to sysfs_emit iio: light: Convert sysfs sprintf/snprintf family to sysfs_emit iio: trigger: stm32-timer: Convert sysfs sprintf/snprintf family to sysfs_emit
drivers/iio/chemical/sps30.c | 6 +++--- drivers/iio/light/veml6030.c | 2 +- drivers/iio/trigger/stm32-timer-trigger.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
Fix the following coccicheck warning: ./drivers/iio/chemical/sps30.c:414:8-16: WARNING: use scnprintf or sprintf
Signed-off-by: Tian Tao tiantao6@hisilicon.com --- drivers/iio/chemical/sps30.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/chemical/sps30.c b/drivers/iio/chemical/sps30.c index 2ea9a5c..7486591 100644 --- a/drivers/iio/chemical/sps30.c +++ b/drivers/iio/chemical/sps30.c @@ -411,9 +411,9 @@ static ssize_t cleaning_period_available_show(struct device *dev, struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "[%d %d %d]\n", - SPS30_AUTO_CLEANING_PERIOD_MIN, 1, - SPS30_AUTO_CLEANING_PERIOD_MAX); + return sysfs_emit(buf, "[%d %d %d]\n", + SPS30_AUTO_CLEANING_PERIOD_MIN, 1, + SPS30_AUTO_CLEANING_PERIOD_MAX); }
static IIO_DEVICE_ATTR_WO(start_cleaning, 0);
Fix the following coccicheck warning: drivers/iio/light/veml6030.c:131:8-16: WARNING: use scnprintf or sprintf
Signed-off-by: Tian Tao tiantao6@hisilicon.com --- drivers/iio/light/veml6030.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/light/veml6030.c b/drivers/iio/light/veml6030.c index de85c9b..3c937c5 100644 --- a/drivers/iio/light/veml6030.c +++ b/drivers/iio/light/veml6030.c @@ -128,7 +128,7 @@ static ssize_t in_illuminance_period_available_show(struct device *dev, return -EINVAL; }
- return snprintf(buf, PAGE_SIZE, "%s\n", period_values[x]); + return sysfs_emit(buf, "%s\n", period_values[x]); }
static IIO_DEVICE_ATTR_RO(in_illuminance_period_available, 0);
Fix the following coccicheck warning: drivers/iio/trigger/stm32-timer-trigger.c:299:8-16: WARNING: use scnprintf or sprintf
Signed-off-by: Tian Tao tiantao6@hisilicon.com --- drivers/iio/trigger/stm32-timer-trigger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/trigger/stm32-timer-trigger.c b/drivers/iio/trigger/stm32-timer-trigger.c index 3aa9e8b..3308387 100644 --- a/drivers/iio/trigger/stm32-timer-trigger.c +++ b/drivers/iio/trigger/stm32-timer-trigger.c @@ -296,7 +296,7 @@ static ssize_t stm32_tt_show_master_mode(struct device *dev, else cr2 = (cr2 & TIM_CR2_MMS) >> TIM_CR2_MMS_SHIFT;
- return snprintf(buf, PAGE_SIZE, "%s\n", master_mode_table[cr2]); + return sysfs_emit(buf, "%s\n", master_mode_table[cr2]); }
static ssize_t stm32_tt_store_master_mode(struct device *dev,
On Mon, 12 Apr 2021 10:27:57 +0800 Tian Tao tiantao6@hisilicon.com wrote:
Use the generic sysfs_emit() function to take place of sprintf/snprintf/scnprintf, to avoid buffer overrun.
Patches are all fine, though in reality none of these have any chance of causing a buffer overrun (all fixed and easily checked max length).
However, I need to wait to see if Greg KH is reopenning staging (IIO goes via that tree for historical reasons) - if he isn't these will be in the next cycle.
Jonathan
Tian Tao (3): iio:chemical:sps30: Convert sysfs sprintf/snprintf family to sysfs_emit iio: light: Convert sysfs sprintf/snprintf family to sysfs_emit iio: trigger: stm32-timer: Convert sysfs sprintf/snprintf family to sysfs_emit
drivers/iio/chemical/sps30.c | 6 +++--- drivers/iio/light/veml6030.c | 2 +- drivers/iio/trigger/stm32-timer-trigger.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)