History

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.

Daniel Zahka committed 12 months ago

Commit 17a42aa1 parent 011d1331 file · +39 −31Browse files

Unified · Split

net/devlink/param.c+39−31
@@ -193,58 +193,66 @@ static int devlink_param_set(struct devlink *devlink, · 192 unmodified lines
193}193}
194 194
195static int195static int
196devlink_nl_param_value_fill_one(struct sk_buff *msg,196devlink_nl_param_value_put(struct sk_buff *msg, enum devlink_param_type type,
197 enum devlink_param_type type,197 int nla_type, union devlink_param_value val)
198 enum devlink_param_cmode cmode,
199 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 switch (type) {199 switch (type) {
212 case DEVLINK_PARAM_TYPE_U8:200 case DEVLINK_PARAM_TYPE_U8:
213 if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, val.vu8))201 if (nla_put_u8(msg, nla_type, val.vu8))
214 goto value_nest_cancel;202 return -EMSGSIZE;
215 break;203 break;
216 case DEVLINK_PARAM_TYPE_U16:204 case DEVLINK_PARAM_TYPE_U16:
217 if (nla_put_u16(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, val.vu16))205 if (nla_put_u16(msg, nla_type, val.vu16))
218 goto value_nest_cancel;206 return -EMSGSIZE;
219 break;207 break;
220 case DEVLINK_PARAM_TYPE_U32:208 case DEVLINK_PARAM_TYPE_U32:
221 if (nla_put_u32(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, val.vu32))209 if (nla_put_u32(msg, nla_type, val.vu32))
222 goto value_nest_cancel;210 return -EMSGSIZE;
223 break;211 break;
224 case DEVLINK_PARAM_TYPE_U64:212 case DEVLINK_PARAM_TYPE_U64:
225 if (devlink_nl_put_u64(msg, DEVLINK_ATTR_PARAM_VALUE_DATA,213 if (devlink_nl_put_u64(msg, nla_type, val.vu64))
226 val.vu64))214 return -EMSGSIZE;
227 goto value_nest_cancel;
228 break;215 break;
229 case DEVLINK_PARAM_TYPE_STRING:216 case DEVLINK_PARAM_TYPE_STRING:
230 if (nla_put_string(msg, DEVLINK_ATTR_PARAM_VALUE_DATA,217 if (nla_put_string(msg, nla_type, val.vstr))
231 val.vstr))218 return -EMSGSIZE;
232 goto value_nest_cancel;
233 break;219 break;
234 case DEVLINK_PARAM_TYPE_BOOL:220 case DEVLINK_PARAM_TYPE_BOOL:
235 if (val.vbool &&221 if (val.vbool && nla_put_flag(msg, nla_type))
236 nla_put_flag(msg, DEVLINK_ATTR_PARAM_VALUE_DATA))222 return -EMSGSIZE;
237 goto value_nest_cancel;
238 break;223 break;
239 }224 }
225 return 0;
226}
227
228static int
229devlink_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 nla_nest_end(msg, param_value_attr);250 nla_nest_end(msg, param_value_attr);
242 return 0;251 return 0;
243 252
244value_nest_cancel:253value_nest_cancel:
245 nla_nest_cancel(msg, param_value_attr);254 nla_nest_cancel(msg, param_value_attr);
246nla_put_failure:255 return err;
247 return -EMSGSIZE;
248}256}
249 257
250static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,258static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t