genetlink: use idr_alloc_cyclic for family->id assignment [Linux 5.1]

genetlink: use idr_alloc_cyclic for family->id assignment [Linux 5.1]

This Linux kernel change "genetlink: use idr_alloc_cyclic for family->id assignment" is included in the Linux 5.1 release. This change is authored by Marcel Holtmann <marcel [at] holtmann.org> on Wed Apr 24 22:18:53 2019 +0200. The commit for this change in Linux stable tree is 4e43df3 (patch).

genetlink: use idr_alloc_cyclic for family->id assignment

When allocating the next family->id it makes more sense to use
idr_alloc_cyclic to avoid re-using a previously used family->id as much
as possible.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

There are 4 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 net/netlink/genetlink.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index f0ec068..cb69d35 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -362,8 +362,8 @@ int genl_register_family(struct genl_family *family)
    } else
        family->attrbuf = NULL;

-   family->id = idr_alloc(&genl_fam_idr, family,
-                  start, end + 1, GFP_KERNEL);
+   family->id = idr_alloc_cyclic(&genl_fam_idr, family,
+                     start, end + 1, GFP_KERNEL);
    if (family->id < 0) {
        err = family->id;
        goto errout_free;

Leave a Reply

Your email address will not be published. Required fields are marked *