diff options
| -rw-r--r-- | include/net/devlink.h | 12 | ||||
| -rw-r--r-- | net/core/devlink.c | 19 |
2 files changed, 28 insertions, 3 deletions
diff --git a/include/net/devlink.h b/include/net/devlink.h index b0e17c025fdc..99efc156a309 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h | |||
| @@ -298,7 +298,7 @@ struct devlink_resource { | |||
| 298 | 298 | ||
| 299 | #define DEVLINK_RESOURCE_ID_PARENT_TOP 0 | 299 | #define DEVLINK_RESOURCE_ID_PARENT_TOP 0 |
| 300 | 300 | ||
| 301 | #define DEVLINK_PARAM_MAX_STRING_VALUE 32 | 301 | #define __DEVLINK_PARAM_MAX_STRING_VALUE 32 |
| 302 | enum devlink_param_type { | 302 | enum devlink_param_type { |
| 303 | DEVLINK_PARAM_TYPE_U8, | 303 | DEVLINK_PARAM_TYPE_U8, |
| 304 | DEVLINK_PARAM_TYPE_U16, | 304 | DEVLINK_PARAM_TYPE_U16, |
| @@ -311,7 +311,7 @@ union devlink_param_value { | |||
| 311 | u8 vu8; | 311 | u8 vu8; |
| 312 | u16 vu16; | 312 | u16 vu16; |
| 313 | u32 vu32; | 313 | u32 vu32; |
| 314 | char vstr[DEVLINK_PARAM_MAX_STRING_VALUE]; | 314 | char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE]; |
| 315 | bool vbool; | 315 | bool vbool; |
| 316 | }; | 316 | }; |
| 317 | 317 | ||
| @@ -553,6 +553,8 @@ int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id, | |||
| 553 | int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id, | 553 | int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id, |
| 554 | union devlink_param_value init_val); | 554 | union devlink_param_value init_val); |
| 555 | void devlink_param_value_changed(struct devlink *devlink, u32 param_id); | 555 | void devlink_param_value_changed(struct devlink *devlink, u32 param_id); |
| 556 | void devlink_param_value_str_fill(union devlink_param_value *dst_val, | ||
| 557 | const char *src); | ||
| 556 | struct devlink_region *devlink_region_create(struct devlink *devlink, | 558 | struct devlink_region *devlink_region_create(struct devlink *devlink, |
| 557 | const char *region_name, | 559 | const char *region_name, |
| 558 | u32 region_max_snapshots, | 560 | u32 region_max_snapshots, |
| @@ -789,6 +791,12 @@ devlink_param_value_changed(struct devlink *devlink, u32 param_id) | |||
| 789 | { | 791 | { |
| 790 | } | 792 | } |
| 791 | 793 | ||
| 794 | static inline void | ||
| 795 | devlink_param_value_str_fill(union devlink_param_value *dst_val, | ||
| 796 | const char *src) | ||
| 797 | { | ||
| 798 | } | ||
| 799 | |||
| 792 | static inline struct devlink_region * | 800 | static inline struct devlink_region * |
| 793 | devlink_region_create(struct devlink *devlink, | 801 | devlink_region_create(struct devlink *devlink, |
| 794 | const char *region_name, | 802 | const char *region_name, |
diff --git a/net/core/devlink.c b/net/core/devlink.c index 1a0de1677197..6bc42933be4a 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c | |||
| @@ -3015,7 +3015,7 @@ devlink_param_value_get_from_info(const struct devlink_param *param, | |||
| 3015 | len = strnlen(nla_data(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]), | 3015 | len = strnlen(nla_data(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]), |
| 3016 | nla_len(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA])); | 3016 | nla_len(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA])); |
| 3017 | if (len == nla_len(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]) || | 3017 | if (len == nla_len(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]) || |
| 3018 | len >= DEVLINK_PARAM_MAX_STRING_VALUE) | 3018 | len >= __DEVLINK_PARAM_MAX_STRING_VALUE) |
| 3019 | return -EINVAL; | 3019 | return -EINVAL; |
| 3020 | strcpy(value->vstr, | 3020 | strcpy(value->vstr, |
| 3021 | nla_data(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA])); | 3021 | nla_data(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA])); |
| @@ -4618,6 +4618,23 @@ void devlink_param_value_changed(struct devlink *devlink, u32 param_id) | |||
| 4618 | EXPORT_SYMBOL_GPL(devlink_param_value_changed); | 4618 | EXPORT_SYMBOL_GPL(devlink_param_value_changed); |
| 4619 | 4619 | ||
| 4620 | /** | 4620 | /** |
| 4621 | * devlink_param_value_str_fill - Safely fill-up the string preventing | ||
| 4622 | * from overflow of the preallocated buffer | ||
| 4623 | * | ||
| 4624 | * @dst_val: destination devlink_param_value | ||
| 4625 | * @src: source buffer | ||
| 4626 | */ | ||
| 4627 | void devlink_param_value_str_fill(union devlink_param_value *dst_val, | ||
| 4628 | const char *src) | ||
| 4629 | { | ||
| 4630 | size_t len; | ||
| 4631 | |||
| 4632 | len = strlcpy(dst_val->vstr, src, __DEVLINK_PARAM_MAX_STRING_VALUE); | ||
| 4633 | WARN_ON(len >= __DEVLINK_PARAM_MAX_STRING_VALUE); | ||
| 4634 | } | ||
| 4635 | EXPORT_SYMBOL_GPL(devlink_param_value_str_fill); | ||
| 4636 | |||
| 4637 | /** | ||
| 4621 | * devlink_region_create - create a new address region | 4638 | * devlink_region_create - create a new address region |
| 4622 | * | 4639 | * |
| 4623 | * @devlink: devlink | 4640 | * @devlink: devlink |
