diff mbox series

[v2,2/2] thermal: netlink: Add thermal_group_has_listeners() helper

Message ID 20231228100248.180721-2-stanislaw.gruszka@linux.intel.com (mailing list archive)
State Mainlined, archived
Headers show
Series [v2,1/2] thermal: netlink: Add enum for mutlicast groups indexes | expand

Commit Message

Stanislaw Gruszka Dec. 28, 2023, 10:02 a.m. UTC
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 <stanislaw.gruszka@linux.intel.com>
---
v2: Do not return -ESRCH error when there are no listeners

 drivers/thermal/thermal_netlink.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Rafael J. Wysocki Dec. 28, 2023, 11:57 a.m. UTC | #1
On Thu, Dec 28, 2023 at 11:49 AM Stanislaw Gruszka
<stanislaw.gruszka@linux.intel.com> wrote:
>
> 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 <stanislaw.gruszka@linux.intel.com>
> ---
> v2: Do not return -ESRCH error when there are no listeners

Both patches in the series look good to me.

Daniel, any objections?

>
>  drivers/thermal/thermal_netlink.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/drivers/thermal/thermal_netlink.c b/drivers/thermal/thermal_netlink.c
> index aca36c4ddbf3..332052e24a86 100644
> --- a/drivers/thermal/thermal_netlink.c
> +++ b/drivers/thermal/thermal_netlink.c
> @@ -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 Dec. 28, 2023, 12:43 p.m. UTC | #2
On 28/12/2023 12:57, Rafael J. Wysocki wrote:
> On Thu, Dec 28, 2023 at 11:49 AM Stanislaw Gruszka
> <stanislaw.gruszka@linux.intel.com> wrote:
>>
>> 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 <stanislaw.gruszka@linux.intel.com>
>> ---
>> v2: Do not return -ESRCH error when there are no listeners
> 
> Both patches in the series look good to me.
> 
> Daniel, any objections?
> 

No objections,

Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>

for both of them

Thanks
Rafael J. Wysocki Dec. 28, 2023, 7:01 p.m. UTC | #3
On Thu, Dec 28, 2023 at 1:43 PM Daniel Lezcano
<daniel.lezcano@linaro.org> wrote:
>
> On 28/12/2023 12:57, Rafael J. Wysocki wrote:
> > On Thu, Dec 28, 2023 at 11:49 AM Stanislaw Gruszka
> > <stanislaw.gruszka@linux.intel.com> wrote:
> >>
> >> 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 <stanislaw.gruszka@linux.intel.com>
> >> ---
> >> v2: Do not return -ESRCH error when there are no listeners
> >
> > Both patches in the series look good to me.
> >
> > Daniel, any objections?
> >
>
> No objections,
>
> Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
>
> for both of them

OK

Both applied as 6.8 material, thanks!
diff mbox series

Patch

diff --git a/drivers/thermal/thermal_netlink.c b/drivers/thermal/thermal_netlink.c
index aca36c4ddbf3..332052e24a86 100644
--- a/drivers/thermal/thermal_netlink.c
+++ b/drivers/thermal/thermal_netlink.c
@@ -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;