Lift the param type demux and value attr placement into a separate function. This new function, devlink_nl_param_put(), can be used to place additional types values in the value array, e.g., default, current, next values. This commit has no functional change.
Unified · Split
| @@ -193,58 +193,66 @@ static int devlink_param_set(struct devlink *devlink, · 192 unmodified lines | ||
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | static int |
| 196 | −devlink_nl_param_value_fill_one(struct sk_buff *msg, | |
| 197 | − enum devlink_param_type type, | |
| 198 | − enum devlink_param_cmode cmode, | |
| 199 | − union devlink_param_value val) | |
| 196 | +devlink_nl_param_value_put(struct sk_buff *msg, enum devlink_param_type type, | |
| 197 | + int nla_type, union devlink_param_value val) | |
| 200 | 198 | { |
| 201 | − struct nlattr *param_value_attr; | |
| 202 | − | |
| 203 | − param_value_attr = nla_nest_start_noflag(msg, | |
| 204 | − DEVLINK_ATTR_PARAM_VALUE); | |
| 205 | − if (!param_value_attr) | |
| 206 | − goto nla_put_failure; | |
| 207 | − | |
| 208 | − if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_VALUE_CMODE, cmode)) | |
| 209 | − goto value_nest_cancel; | |
| 210 | − | |
| 211 | 199 | switch (type) { |
| 212 | 200 | case DEVLINK_PARAM_TYPE_U8: |
| 213 | − if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, val.vu8)) | |
| 214 | − goto value_nest_cancel; | |
| 201 | + if (nla_put_u8(msg, nla_type, val.vu8)) | |
| 202 | + return -EMSGSIZE; | |
| 215 | 203 | break; |
| 216 | 204 | case DEVLINK_PARAM_TYPE_U16: |
| 217 | − if (nla_put_u16(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, val.vu16)) | |
| 218 | − goto value_nest_cancel; | |
| 205 | + if (nla_put_u16(msg, nla_type, val.vu16)) | |
| 206 | + return -EMSGSIZE; | |
| 219 | 207 | break; |
| 220 | 208 | case DEVLINK_PARAM_TYPE_U32: |
| 221 | − if (nla_put_u32(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, val.vu32)) | |
| 222 | − goto value_nest_cancel; | |
| 209 | + if (nla_put_u32(msg, nla_type, val.vu32)) | |
| 210 | + return -EMSGSIZE; | |
| 223 | 211 | break; |
| 224 | 212 | case DEVLINK_PARAM_TYPE_U64: |
| 225 | − if (devlink_nl_put_u64(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, | |
| 226 | − val.vu64)) | |
| 227 | − goto value_nest_cancel; | |
| 213 | + if (devlink_nl_put_u64(msg, nla_type, val.vu64)) | |
| 214 | + return -EMSGSIZE; | |
| 228 | 215 | break; |
| 229 | 216 | case DEVLINK_PARAM_TYPE_STRING: |
| 230 | − if (nla_put_string(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, | |
| 231 | − val.vstr)) | |
| 232 | − goto value_nest_cancel; | |
| 217 | + if (nla_put_string(msg, nla_type, val.vstr)) | |
| 218 | + return -EMSGSIZE; | |
| 233 | 219 | break; |
| 234 | 220 | case DEVLINK_PARAM_TYPE_BOOL: |
| 235 | − if (val.vbool && | |
| 236 | − nla_put_flag(msg, DEVLINK_ATTR_PARAM_VALUE_DATA)) | |
| 237 | − goto value_nest_cancel; | |
| 221 | + if (val.vbool && nla_put_flag(msg, nla_type)) | |
| 222 | + return -EMSGSIZE; | |
| 238 | 223 | break; |
| 239 | 224 | } |
| 225 | + return 0; | |
| 226 | +} | |
| 227 | + | |
| 228 | +static int | |
| 229 | +devlink_nl_param_value_fill_one(struct sk_buff *msg, | |
| 230 | + enum devlink_param_type type, | |
| 231 | + enum devlink_param_cmode cmode, | |
| 232 | + union devlink_param_value val) | |
| 233 | +{ | |
| 234 | + struct nlattr *param_value_attr; | |
| 235 | + int err = -EMSGSIZE; | |
| 236 | + | |
| 237 | + param_value_attr = nla_nest_start_noflag(msg, | |
| 238 | + DEVLINK_ATTR_PARAM_VALUE); | |
| 239 | + if (!param_value_attr) | |
| 240 | + return -EMSGSIZE; | |
| 241 | + | |
| 242 | + if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_VALUE_CMODE, cmode)) | |
| 243 | + goto value_nest_cancel; | |
| 244 | + | |
| 245 | + err = devlink_nl_param_value_put(msg, type, | |
| 246 | + DEVLINK_ATTR_PARAM_VALUE_DATA, val); | |
| 247 | + if (err) | |
| 248 | + goto value_nest_cancel; | |
| 240 | 249 | |
| 241 | 250 | nla_nest_end(msg, param_value_attr); |
| 242 | 251 | return 0; |
| 243 | 252 | |
| 244 | 253 | value_nest_cancel: |
| 245 | 254 | nla_nest_cancel(msg, param_value_attr); |
| 246 | −nla_put_failure: | |
| 247 | − return -EMSGSIZE; | |
| 255 | + return err; | |
| 248 | 256 | } |
| 249 | 257 | |
| 250 | 258 | static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink, |