Skip to content

Commit 04c3b03

Browse files
sgruszkarafaeljw
authored andcommitted
thermal: netlink: Add thermal_group_has_listeners() helper
Add a helper function to check if there are listeners for thermal_gnl_family multicast groups. For now use it to avoid unnecessary allocations and sending thermal genl messages when there are no recipients. In the future, in conjunction with (not yet implemented) notification of change in the netlink socket group membership, this helper can be used to open/close hardware interfaces based on the presence of user space subscribers. Signed-off-by: Stanislaw Gruszka <[email protected]> Acked-by: Daniel Lezcano <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 5eb4f41 commit 04c3b03

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/thermal/thermal_netlink.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,21 @@ typedef int (*cb_t)(struct param *);
7676

7777
static struct genl_family thermal_gnl_family;
7878

79+
static int thermal_group_has_listeners(enum thermal_genl_multicast_groups group)
80+
{
81+
return genl_has_listeners(&thermal_gnl_family, &init_net, group);
82+
}
83+
7984
/************************** Sampling encoding *******************************/
8085

8186
int thermal_genl_sampling_temp(int id, int temp)
8287
{
8388
struct sk_buff *skb;
8489
void *hdr;
8590

91+
if (!thermal_group_has_listeners(THERMAL_GENL_SAMPLING_GROUP))
92+
return 0;
93+
8694
skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
8795
if (!skb)
8896
return -ENOMEM;
@@ -280,6 +288,9 @@ static int thermal_genl_send_event(enum thermal_genl_event event,
280288
int ret = -EMSGSIZE;
281289
void *hdr;
282290

291+
if (!thermal_group_has_listeners(THERMAL_GENL_EVENT_GROUP))
292+
return 0;
293+
283294
msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
284295
if (!msg)
285296
return -ENOMEM;

0 commit comments

Comments
 (0)