Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

devlink: refactor devlink_nl_param_value_fill_one()

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.

Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
Link: https://patch.msgid.link/20251119025038.651131-3-daniel.zahka@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Daniel Zahka and committed by
Jakub Kicinski
17a42aa4 011d133b

+40 -32
+40 -32
net/devlink/param.c
··· 193 193 } 194 194 195 195 static int 196 + devlink_nl_param_value_put(struct sk_buff *msg, enum devlink_param_type type, 197 + int nla_type, union devlink_param_value val) 198 + { 199 + switch (type) { 200 + case DEVLINK_PARAM_TYPE_U8: 201 + if (nla_put_u8(msg, nla_type, val.vu8)) 202 + return -EMSGSIZE; 203 + break; 204 + case DEVLINK_PARAM_TYPE_U16: 205 + if (nla_put_u16(msg, nla_type, val.vu16)) 206 + return -EMSGSIZE; 207 + break; 208 + case DEVLINK_PARAM_TYPE_U32: 209 + if (nla_put_u32(msg, nla_type, val.vu32)) 210 + return -EMSGSIZE; 211 + break; 212 + case DEVLINK_PARAM_TYPE_U64: 213 + if (devlink_nl_put_u64(msg, nla_type, val.vu64)) 214 + return -EMSGSIZE; 215 + break; 216 + case DEVLINK_PARAM_TYPE_STRING: 217 + if (nla_put_string(msg, nla_type, val.vstr)) 218 + return -EMSGSIZE; 219 + break; 220 + case DEVLINK_PARAM_TYPE_BOOL: 221 + if (val.vbool && nla_put_flag(msg, nla_type)) 222 + return -EMSGSIZE; 223 + break; 224 + } 225 + return 0; 226 + } 227 + 228 + static int 196 229 devlink_nl_param_value_fill_one(struct sk_buff *msg, 197 230 enum devlink_param_type type, 198 231 enum devlink_param_cmode cmode, 199 232 union devlink_param_value val) 200 233 { 201 234 struct nlattr *param_value_attr; 235 + int err = -EMSGSIZE; 202 236 203 237 param_value_attr = nla_nest_start_noflag(msg, 204 238 DEVLINK_ATTR_PARAM_VALUE); 205 239 if (!param_value_attr) 206 - goto nla_put_failure; 240 + return -EMSGSIZE; 207 241 208 242 if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_VALUE_CMODE, cmode)) 209 243 goto value_nest_cancel; 210 244 211 - switch (type) { 212 - case DEVLINK_PARAM_TYPE_U8: 213 - if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, val.vu8)) 214 - goto value_nest_cancel; 215 - break; 216 - case DEVLINK_PARAM_TYPE_U16: 217 - if (nla_put_u16(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, val.vu16)) 218 - goto value_nest_cancel; 219 - break; 220 - case DEVLINK_PARAM_TYPE_U32: 221 - if (nla_put_u32(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, val.vu32)) 222 - goto value_nest_cancel; 223 - break; 224 - 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; 228 - break; 229 - case DEVLINK_PARAM_TYPE_STRING: 230 - if (nla_put_string(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, 231 - val.vstr)) 232 - goto value_nest_cancel; 233 - break; 234 - case DEVLINK_PARAM_TYPE_BOOL: 235 - if (val.vbool && 236 - nla_put_flag(msg, DEVLINK_ATTR_PARAM_VALUE_DATA)) 237 - goto value_nest_cancel; 238 - break; 239 - } 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,