mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-29 18:11:20 +00:00
devlink: Add helper function for safely copy string param
Devlink string param buffer is allocated at the size of DEVLINK_PARAM_MAX_STRING_VALUE. Add helper function which makes sure this size is not exceeded. Renamed DEVLINK_PARAM_MAX_STRING_VALUE to __DEVLINK_PARAM_MAX_STRING_VALUE to emphasize that it should be used by devlink only. The driver should use the helper function instead to verify it doesn't exceed the allowed length. Signed-off-by: Moshe Shemesh <moshe@mellanox.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
1276534c98
commit
bde74ad10e
2 changed files with 28 additions and 3 deletions
|
@ -3015,7 +3015,7 @@ devlink_param_value_get_from_info(const struct devlink_param *param,
|
|||
len = strnlen(nla_data(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]),
|
||||
nla_len(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]));
|
||||
if (len == nla_len(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]) ||
|
||||
len >= DEVLINK_PARAM_MAX_STRING_VALUE)
|
||||
len >= __DEVLINK_PARAM_MAX_STRING_VALUE)
|
||||
return -EINVAL;
|
||||
strcpy(value->vstr,
|
||||
nla_data(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]));
|
||||
|
@ -4617,6 +4617,23 @@ void devlink_param_value_changed(struct devlink *devlink, u32 param_id)
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(devlink_param_value_changed);
|
||||
|
||||
/**
|
||||
* devlink_param_value_str_fill - Safely fill-up the string preventing
|
||||
* from overflow of the preallocated buffer
|
||||
*
|
||||
* @dst_val: destination devlink_param_value
|
||||
* @src: source buffer
|
||||
*/
|
||||
void devlink_param_value_str_fill(union devlink_param_value *dst_val,
|
||||
const char *src)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
len = strlcpy(dst_val->vstr, src, __DEVLINK_PARAM_MAX_STRING_VALUE);
|
||||
WARN_ON(len >= __DEVLINK_PARAM_MAX_STRING_VALUE);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(devlink_param_value_str_fill);
|
||||
|
||||
/**
|
||||
* devlink_region_create - create a new address region
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue