Re: [PATCH 2/2] thermal: netlink: Add thermal_group_has_listeners() helper

Daniel Lezcano
2023-12-27T14:11:07Z

Hi Stanislaw,

thanks for this optimization. One question below.

On Wed, Dec 27, 2023 at 03:00:57PM +0100, Stanislaw Gruszka 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>
> ---
> 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..b4e758d22077 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 -ESRCH;
> +

Do really want to return an error ? Shall we just bail out instead ?

[ ... ]

--

<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 |