usb: atm: don't use snprintf() for sysfs attrs
kernel/cpu.c: don't use snprintf() for sysfs attrs As per the documentation (Documentation/filesystems/sysfs.rst), snprintf() should not be used for formatting values returned by sysfs. In all of these cases, sprintf() suffices as we know that the formatted strings will be less than PAGE_SIZE in length. Issue identified by Coccinelle. Signed-off-by: Alex Dewar <alex.dewar90@gmail.com> Link: https://lore.kernel.org/r/20200824222322.22962-1-alex.dewar90@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Родитель
28157b8c7d
Коммит
cb06b385d5
|
@ -230,12 +230,12 @@ CXACRU__ATTR_INIT(_name)
|
|||
|
||||
static ssize_t cxacru_sysfs_showattr_u32(u32 value, char *buf)
|
||||
{
|
||||
return snprintf(buf, PAGE_SIZE, "%u\n", value);
|
||||
return sprintf(buf, "%u\n", value);
|
||||
}
|
||||
|
||||
static ssize_t cxacru_sysfs_showattr_s8(s8 value, char *buf)
|
||||
{
|
||||
return snprintf(buf, PAGE_SIZE, "%d\n", value);
|
||||
return sprintf(buf, "%d\n", value);
|
||||
}
|
||||
|
||||
static ssize_t cxacru_sysfs_showattr_dB(s16 value, char *buf)
|
||||
|
@ -255,8 +255,8 @@ static ssize_t cxacru_sysfs_showattr_bool(u32 value, char *buf)
|
|||
static char *str[] = { "no", "yes" };
|
||||
|
||||
if (unlikely(value >= ARRAY_SIZE(str)))
|
||||
return snprintf(buf, PAGE_SIZE, "%u\n", value);
|
||||
return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
|
||||
return sprintf(buf, "%u\n", value);
|
||||
return sprintf(buf, "%s\n", str[value]);
|
||||
}
|
||||
|
||||
static ssize_t cxacru_sysfs_showattr_LINK(u32 value, char *buf)
|
||||
|
@ -264,8 +264,8 @@ static ssize_t cxacru_sysfs_showattr_LINK(u32 value, char *buf)
|
|||
static char *str[] = { NULL, "not connected", "connected", "lost" };
|
||||
|
||||
if (unlikely(value >= ARRAY_SIZE(str) || str[value] == NULL))
|
||||
return snprintf(buf, PAGE_SIZE, "%u\n", value);
|
||||
return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
|
||||
return sprintf(buf, "%u\n", value);
|
||||
return sprintf(buf, "%s\n", str[value]);
|
||||
}
|
||||
|
||||
static ssize_t cxacru_sysfs_showattr_LINE(u32 value, char *buf)
|
||||
|
@ -275,8 +275,8 @@ static ssize_t cxacru_sysfs_showattr_LINE(u32 value, char *buf)
|
|||
"waiting", "initialising"
|
||||
};
|
||||
if (unlikely(value >= ARRAY_SIZE(str)))
|
||||
return snprintf(buf, PAGE_SIZE, "%u\n", value);
|
||||
return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
|
||||
return sprintf(buf, "%u\n", value);
|
||||
return sprintf(buf, "%s\n", str[value]);
|
||||
}
|
||||
|
||||
static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf)
|
||||
|
@ -288,8 +288,8 @@ static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf)
|
|||
"ITU-T G.992.2 (G.LITE)"
|
||||
};
|
||||
if (unlikely(value >= ARRAY_SIZE(str)))
|
||||
return snprintf(buf, PAGE_SIZE, "%u\n", value);
|
||||
return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
|
||||
return sprintf(buf, "%u\n", value);
|
||||
return sprintf(buf, "%s\n", str[value]);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -309,8 +309,7 @@ static ssize_t mac_address_show(struct device *dev,
|
|||
if (instance == NULL || instance->usbatm->atm_dev == NULL)
|
||||
return -ENODEV;
|
||||
|
||||
return snprintf(buf, PAGE_SIZE, "%pM\n",
|
||||
instance->usbatm->atm_dev->esi);
|
||||
return sprintf(buf, "%pM\n", instance->usbatm->atm_dev->esi);
|
||||
}
|
||||
|
||||
static ssize_t adsl_state_show(struct device *dev,
|
||||
|
@ -326,8 +325,8 @@ static ssize_t adsl_state_show(struct device *dev,
|
|||
|
||||
value = instance->card_info[CXINF_LINE_STARTABLE];
|
||||
if (unlikely(value >= ARRAY_SIZE(str)))
|
||||
return snprintf(buf, PAGE_SIZE, "%u\n", value);
|
||||
return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
|
||||
return sprintf(buf, "%u\n", value);
|
||||
return sprintf(buf, "%s\n", str[value]);
|
||||
}
|
||||
|
||||
static ssize_t adsl_state_store(struct device *dev,
|
||||
|
|
Загрузка…
Ссылка в новой задаче