Skip to content

Commit 24b216b

Browse files
dlezcanorafaeljw
authored andcommitted
tools/lib/thermal: Make more generic the command encoding function
The thermal netlink has been extended with more commands which require an encoding with more information. The generic encoding function puts the thermal zone id with the command name. It is the unique parameters. The next changes will provide more parameters to the command. Set the scene for those new parameters by making the encoding function more generic. Signed-off-by: Daniel Lezcano <[email protected]> Reviewed-by: Lukasz Luba <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 1773572 commit 24b216b

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

tools/lib/thermal/commands.c

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,23 @@ static struct genl_ops thermal_cmd_ops = {
261261
.o_ncmds = ARRAY_SIZE(thermal_cmds),
262262
};
263263

264-
static thermal_error_t thermal_genl_auto(struct thermal_handler *th, int id, int cmd,
265-
int flags, void *arg)
264+
struct cmd_param {
265+
int tz_id;
266+
};
267+
268+
typedef int (*cmd_cb_t)(struct nl_msg *, struct cmd_param *);
269+
270+
static int thermal_genl_tz_id_encode(struct nl_msg *msg, struct cmd_param *p)
271+
{
272+
if (p->tz_id >= 0 && nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_ID, p->tz_id))
273+
return -1;
274+
275+
return 0;
276+
}
277+
278+
static thermal_error_t thermal_genl_auto(struct thermal_handler *th, cmd_cb_t cmd_cb,
279+
struct cmd_param *param,
280+
int cmd, int flags, void *arg)
266281
{
267282
struct nl_msg *msg;
268283
void *hdr;
@@ -276,7 +291,7 @@ static thermal_error_t thermal_genl_auto(struct thermal_handler *th, int id, int
276291
if (!hdr)
277292
return THERMAL_ERROR;
278293

279-
if (id >= 0 && nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_ID, id))
294+
if (cmd_cb && cmd_cb(msg, param))
280295
return THERMAL_ERROR;
281296

282297
if (nl_send_msg(th->sk_cmd, th->cb_cmd, msg, genl_handle_msg, arg))
@@ -289,30 +304,38 @@ static thermal_error_t thermal_genl_auto(struct thermal_handler *th, int id, int
289304

290305
thermal_error_t thermal_cmd_get_tz(struct thermal_handler *th, struct thermal_zone **tz)
291306
{
292-
return thermal_genl_auto(th, -1, THERMAL_GENL_CMD_TZ_GET_ID,
307+
return thermal_genl_auto(th, NULL, NULL, THERMAL_GENL_CMD_TZ_GET_ID,
293308
NLM_F_DUMP | NLM_F_ACK, tz);
294309
}
295310

296311
thermal_error_t thermal_cmd_get_cdev(struct thermal_handler *th, struct thermal_cdev **tc)
297312
{
298-
return thermal_genl_auto(th, -1, THERMAL_GENL_CMD_CDEV_GET,
313+
return thermal_genl_auto(th, NULL, NULL, THERMAL_GENL_CMD_CDEV_GET,
299314
NLM_F_DUMP | NLM_F_ACK, tc);
300315
}
301316

302317
thermal_error_t thermal_cmd_get_trip(struct thermal_handler *th, struct thermal_zone *tz)
303318
{
304-
return thermal_genl_auto(th, tz->id, THERMAL_GENL_CMD_TZ_GET_TRIP,
305-
0, tz);
319+
struct cmd_param p = { .tz_id = tz->id };
320+
321+
return thermal_genl_auto(th, thermal_genl_tz_id_encode, &p,
322+
THERMAL_GENL_CMD_TZ_GET_TRIP, 0, tz);
306323
}
307324

308325
thermal_error_t thermal_cmd_get_governor(struct thermal_handler *th, struct thermal_zone *tz)
309326
{
310-
return thermal_genl_auto(th, tz->id, THERMAL_GENL_CMD_TZ_GET_GOV, 0, tz);
327+
struct cmd_param p = { .tz_id = tz->id };
328+
329+
return thermal_genl_auto(th, thermal_genl_tz_id_encode, &p,
330+
THERMAL_GENL_CMD_TZ_GET_GOV, 0, tz);
311331
}
312332

313333
thermal_error_t thermal_cmd_get_temp(struct thermal_handler *th, struct thermal_zone *tz)
314334
{
315-
return thermal_genl_auto(th, tz->id, THERMAL_GENL_CMD_TZ_GET_TEMP, 0, tz);
335+
struct cmd_param p = { .tz_id = tz->id };
336+
337+
return thermal_genl_auto(th, thermal_genl_tz_id_encode, &p,
338+
THERMAL_GENL_CMD_TZ_GET_TEMP, 0, tz);
316339
}
317340

318341
thermal_error_t thermal_cmd_exit(struct thermal_handler *th)

0 commit comments

Comments
 (0)