Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 Jan 2018 13:37:07 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r328329 - head/sys/compat/linuxkpi/common/src
Message-ID:  <201801241337.w0ODb7Z3033195@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Wed Jan 24 13:37:07 2018
New Revision: 328329
URL: https://svnweb.freebsd.org/changeset/base/328329

Log:
  Properly implement the "id" callback argument in the "idr_for_each" function
  in the LinuxKPI. The old implementation assumed only one IDR layer was present.
  Take additional IDR layers into account when computing the "id" value.
  
  MFC after:	1 week
  Found by:	Karthik Palanichamy <karthikp@chelsio.com>
  Tested by:	Karthik Palanichamy <karthikp@chelsio.com>
  Sponsored by:	Mellanox Technologies

Modified:
  head/sys/compat/linuxkpi/common/src/linux_idr.c

Modified: head/sys/compat/linuxkpi/common/src/linux_idr.c
==============================================================================
--- head/sys/compat/linuxkpi/common/src/linux_idr.c	Wed Jan 24 13:12:21 2018	(r328328)
+++ head/sys/compat/linuxkpi/common/src/linux_idr.c	Wed Jan 24 13:37:07 2018	(r328329)
@@ -680,7 +680,7 @@ idr_alloc_cyclic(struct idr *idr, void *ptr, int start
 }
 
 static int
-idr_for_each_layer(struct idr_layer *il, int layer,
+idr_for_each_layer(struct idr_layer *il, int offset, int layer,
     int (*f)(int id, void *p, void *data), void *data)
 {
 	int i, err;
@@ -691,7 +691,7 @@ idr_for_each_layer(struct idr_layer *il, int layer,
 		for (i = 0; i < IDR_SIZE; i++) {
 			if (il->ary[i] == NULL)
 				continue;
-			err = f(i, il->ary[i],  data);
+			err = f(i + offset, il->ary[i],  data);
 			if (err)
 				return (err);
 		}
@@ -700,7 +700,8 @@ idr_for_each_layer(struct idr_layer *il, int layer,
 	for (i = 0; i < IDR_SIZE; i++) {
 		if (il->ary[i] == NULL)
 			continue;
-		err = idr_for_each_layer(il->ary[i], layer - 1, f, data);
+		err = idr_for_each_layer(il->ary[i],
+		    (i + offset) * IDR_SIZE, layer - 1, f, data);
 		if (err)
 			return (err);
 	}
@@ -711,7 +712,7 @@ idr_for_each_layer(struct idr_layer *il, int layer,
 int
 idr_for_each(struct idr *idp, int (*f)(int id, void *p, void *data), void *data)
 {
-	return (idr_for_each_layer(idp->top, idp->layers - 1, f, data));
+	return (idr_for_each_layer(idp->top, 0, idp->layers - 1, f, data));
 }
 
 int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801241337.w0ODb7Z3033195>