thermal: netlink: Add enum for mutlicast groups indexes
PATCH v2 1/2 thermal: netlink: Add enum for mutlicast groups indexes
Use enum instead of hard-coded numbers for indexing multicast groups.
---
v2: No change
drivers/thermal/thermal_netlink.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/thermal/thermal_netlink.c +9 -4
@@ -13,9 +13,14 @@#include "thermal_core.h" +enum thermal_genl_multicast_groups { +THERMAL_GENL_SAMPLING_GROUP =0 , +THERMAL_GENL_EVENT_GROUP =1 , +}; +static const struct genl_multicast_group thermal_genl_mcgrps[] = { - { .name =THERMAL_GENL_SAMPLING_GROUP_NAME , }, - { .name =THERMAL_GENL_EVENT_GROUP_NAME , }, + [THERMAL_GENL_SAMPLING_GROUP ] = { .name =THERMAL_GENL_SAMPLING_GROUP_NAME , }, + [THERMAL_GENL_EVENT_GROUP ] = { .name =THERMAL_GENL_EVENT_GROUP_NAME , }, };static const struct nla_policy thermal_genl_policy[THERMAL_GENL_ATTR_MAX +1 ] = {
@@ -95,7 +100,7 @@ int thermal_genl_sampling_temp(int id, int temp)genlmsg_end (skb, hdr); -genlmsg_multicast (&thermal_gnl_family, skb,0 ,0 ,GFP_KERNEL ); +genlmsg_multicast (&thermal_gnl_family, skb,0 ,THERMAL_GENL_SAMPLING_GROUP ,GFP_KERNEL );return 0 ; out_cancel:
@@ -290,7 +295,7 @@ static int thermal_genl_send_event(enum thermal_genl_event event,genlmsg_end (msg, hdr); -genlmsg_multicast (&thermal_gnl_family, msg,0 ,1 ,GFP_KERNEL ); +genlmsg_multicast (&thermal_gnl_family, msg,0 ,THERMAL_GENL_EVENT_GROUP ,GFP_KERNEL );return 0 ;
Signature · 1 line
2.34.1
PATCH v2 2/2 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.
---
v2: Do not return -ESRCH error when there are no listeners
drivers/thermal/thermal_netlink.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/thermal/thermal_netlink.c +11 -0
@@ -76,6 +76,11 @@ typedef int (*cb_t)(struct param *);static struct genl_family thermal_gnl_family; +static int thermal_group_has_listeners (enum thermal_genl_multicast_groups group) +{ +return genl_has_listeners (&thermal_gnl_family, &init_net, group); +} +/************************** Sampling encoding *******************************/ int thermal_genl_sampling_temp (int id,int temp)
@@ -83,6 +88,9 @@ int thermal_genl_sampling_temp(int id, int temp)struct sk_buff *skb;void *hdr; +if (!thermal_group_has_listeners (THERMAL_GENL_SAMPLING_GROUP )) +return 0 ; + skb =genlmsg_new (NLMSG_GOODSIZE ,GFP_KERNEL );if (!skb)return -ENOMEM ;
@@ -280,6 +288,9 @@ static int thermal_genl_send_event(enum thermal_genl_event event,int ret = -EMSGSIZE ;void *hdr; +if (!thermal_group_has_listeners (THERMAL_GENL_EVENT_GROUP )) +return 0 ; + msg =genlmsg_new (NLMSG_GOODSIZE ,GFP_KERNEL );if (!msg)return -ENOMEM ;
Signature · 1 line
2.34.1
Rafael J. Wysocki
maintainerRe: [PATCH v2 2/2] thermal: netlink: Add thermal_group_has_listeners() helper
Quoted 7 lines · Stanislaw Gruszka
Add a helper function to check if there are listeners for
thermal_gnl_familymulticast groups.For now use it to avoid unnecessary allocations and sending thermal genl messages when there are no recipients.
Quoted 8 lines
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]>---
v2: Do not return-ESRCHerror when there are no listeners
Both patches in the series look good to me.
Daniel, any objections?
Quoted 44 lines
drivers/thermal/thermal_netlink.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/thermal/thermal_netlink.c +11
-1@@ -76,6 +76,11 @@ typedef int (*cb_t)(struct param *);static struct genl_family thermal_gnl_family; +static int thermal_group_has_listeners (enum thermal_genl_multicast_groups group) +{ +return genl_has_listeners (&thermal_gnl_family, &init_net, group); +} +/************************** Sampling encoding *******************************/ int thermal_genl_sampling_temp (int id,int temp)@@ -83,6 +88,9 @@ int thermal_genl_sampling_temp(int id, int temp)struct sk_buff *skb;void *hdr; +if (!thermal_group_has_listeners (THERMAL_GENL_SAMPLING_GROUP )) +return 0 ; + skb =genlmsg_new (NLMSG_GOODSIZE ,GFP_KERNEL );if (!skb)return -ENOMEM ;@@ -280,6 +288,9 @@ static int thermal_genl_send_event(enum thermal_genl_event event,int ret = -EMSGSIZE ;void *hdr; +if (!thermal_group_has_listeners (THERMAL_GENL_EVENT_GROUP )) +return 0 ; + msg =genlmsg_new (NLMSG_GOODSIZE ,GFP_KERNEL );if (!msg)return -ENOMEM ; --2.34.1
Daniel Lezcano
Acked-byRe: [PATCH v2 2/2] thermal: netlink: Add thermal_group_has_listeners() helper
Quoted 14 lines · Rafael J. Wysocki
Quoted 12 lines · Stanislaw Gruszka
Add a helper function to check if there are listeners for
thermal_gnl_familymulticast 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.
Quoted 8 lines
Quoted 3 lines
Signed-off-by Stanislaw Gruszka <[email protected]>---
v2: Do not return-ESRCHerror when there are no listenersBoth patches in the series look good to me.
Daniel, any objections?
No objections,
for both of them
Thanks
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Rafael J. Wysocki
maintainerRe: [PATCH v2 2/2] thermal: netlink: Add thermal_group_has_listeners() helper
Quoted 22 lines · Daniel Lezcano
Quoted 20 lines · Rafael J. Wysocki
Quoted 7 lines · Stanislaw Gruszka
Add a helper function to check if there are listeners for
thermal_gnl_familymulticast groups.For now use it to avoid unnecessary allocations and sending thermal genl messages when there are no recipients.
Quoted 8 lines
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]>---
v2: Do not return-ESRCHerror when there are no listenersBoth patches in the series look good to me.
Quoted 8 lines
Quoted 2 lines
Daniel, any objections?
No objections,
Acked-by Daniel Lezcano <[email protected]>for both of them
OK
Both applied as 6.8 material, thanks!