Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'for-thermal-genetlink-family-bind-unbind-callbacks'

Stanislaw Gruszka says:

====================
thermal/netlink/intel_hfi: Enable HFI feature only when required

The patchset introduces a new genetlink family bind/unbind callbacks
and thermal/netlink notifications, which allow drivers to send netlink
multicast events based on the presence of actual user-space consumers.
This functionality optimizes resource usage by allowing disabling
of features when not needed.

v1: https://lore.kernel.org/linux-pm/20240131120535.933424-1-stanislaw.gruszka@linux.intel.com//
v2: https://lore.kernel.org/linux-pm/20240206133605.1518373-1-stanislaw.gruszka@linux.intel.com/
v3: https://lore.kernel.org/linux-pm/20240209120625.1775017-1-stanislaw.gruszka@linux.intel.com/
====================

Link: https://lore.kernel.org/r/20240212161615.161935-1-stanislaw.gruszka@linux.intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+34
+4
include/net/genetlink.h
··· 41 41 * do additional, common, filtering and return an error 42 42 * @post_doit: called after an operation's doit callback, it may 43 43 * undo operations done by pre_doit, for example release locks 44 + * @bind: called when family multicast group is added to a netlink socket 45 + * @unbind: called when family multicast group is removed from a netlink socket 44 46 * @module: pointer to the owning module (set to THIS_MODULE) 45 47 * @mcgrps: multicast groups used by this family 46 48 * @n_mcgrps: number of multicast groups ··· 86 84 void (*post_doit)(const struct genl_split_ops *ops, 87 85 struct sk_buff *skb, 88 86 struct genl_info *info); 87 + int (*bind)(int mcgrp); 88 + void (*unbind)(int mcgrp); 89 89 const struct genl_ops * ops; 90 90 const struct genl_small_ops *small_ops; 91 91 const struct genl_split_ops *split_ops;
+30
net/netlink/genetlink.c
··· 1836 1836 !ns_capable(net->user_ns, CAP_SYS_ADMIN)) 1837 1837 ret = -EPERM; 1838 1838 1839 + if (family->bind) 1840 + family->bind(i); 1841 + 1839 1842 break; 1840 1843 } 1841 1844 1842 1845 up_read(&cb_lock); 1843 1846 return ret; 1847 + } 1848 + 1849 + static void genl_unbind(struct net *net, int group) 1850 + { 1851 + const struct genl_family *family; 1852 + unsigned int id; 1853 + 1854 + down_read(&cb_lock); 1855 + 1856 + idr_for_each_entry(&genl_fam_idr, family, id) { 1857 + int i; 1858 + 1859 + if (family->n_mcgrps == 0) 1860 + continue; 1861 + 1862 + i = group - family->mcgrp_offset; 1863 + if (i < 0 || i >= family->n_mcgrps) 1864 + continue; 1865 + 1866 + if (family->unbind) 1867 + family->unbind(i); 1868 + 1869 + break; 1870 + } 1871 + 1872 + up_read(&cb_lock); 1844 1873 } 1845 1874 1846 1875 static int __net_init genl_pernet_init(struct net *net) ··· 1878 1849 .input = genl_rcv, 1879 1850 .flags = NL_CFG_F_NONROOT_RECV, 1880 1851 .bind = genl_bind, 1852 + .unbind = genl_unbind, 1881 1853 .release = genl_release, 1882 1854 }; 1883 1855