Commit f355cfcd authored by Moshe Shemesh's avatar Moshe Shemesh Committed by David S. Miller

devlink: Fix param set handling for string type

In case devlink param type is string, it needs to copy the string value
it got from the input to devlink_param_value.

Fixes: e3b7ca18 ("devlink: Add param set command")
Signed-off-by: default avatarMoshe Shemesh <moshe@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4cf34c0c
...@@ -311,7 +311,7 @@ union devlink_param_value { ...@@ -311,7 +311,7 @@ union devlink_param_value {
u8 vu8; u8 vu8;
u16 vu16; u16 vu16;
u32 vu32; u32 vu32;
const char *vstr; char vstr[DEVLINK_PARAM_MAX_STRING_VALUE];
bool vbool; bool vbool;
}; };
......
...@@ -2995,6 +2995,8 @@ devlink_param_value_get_from_info(const struct devlink_param *param, ...@@ -2995,6 +2995,8 @@ devlink_param_value_get_from_info(const struct devlink_param *param,
struct genl_info *info, struct genl_info *info,
union devlink_param_value *value) union devlink_param_value *value)
{ {
int len;
if (param->type != DEVLINK_PARAM_TYPE_BOOL && if (param->type != DEVLINK_PARAM_TYPE_BOOL &&
!info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]) !info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA])
return -EINVAL; return -EINVAL;
...@@ -3010,10 +3012,13 @@ devlink_param_value_get_from_info(const struct devlink_param *param, ...@@ -3010,10 +3012,13 @@ devlink_param_value_get_from_info(const struct devlink_param *param,
value->vu32 = nla_get_u32(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]); value->vu32 = nla_get_u32(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]);
break; break;
case DEVLINK_PARAM_TYPE_STRING: case DEVLINK_PARAM_TYPE_STRING:
if (nla_len(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]) > len = strnlen(nla_data(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]),
DEVLINK_PARAM_MAX_STRING_VALUE) 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)
return -EINVAL; return -EINVAL;
value->vstr = nla_data(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]); strcpy(value->vstr,
nla_data(info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA]));
break; break;
case DEVLINK_PARAM_TYPE_BOOL: case DEVLINK_PARAM_TYPE_BOOL:
value->vbool = info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA] ? value->vbool = info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA] ?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment