On 27/09/18 20:27, Spencer E. Olson wrote:
Adds interface and associated unittests for accessing/looking-up/validating
the new ni routing table information.
Signed-off-by: Spencer E. Olson <olso...@umich.edu>
---
Changes since last submission:
- [PATCH v2 05/13]: Tweak Makefile to build routing info for newly added
hardware in updates to [PATCH v2 04/13].
- [PATCH v2 05/13]: Fixes placement of "select COMEDI_NI_ROUTING" as per
Ian's
suggestion.
- [PATCH v2 05/13]: Removes a few inline function declarations in unit test.
drivers/staging/comedi/Kconfig | 4 +
drivers/staging/comedi/drivers/Makefile | 27 +
drivers/staging/comedi/drivers/ni_routes.c | 521 +++++++++++++++
drivers/staging/comedi/drivers/ni_routes.h | 329 ++++++++++
drivers/staging/comedi/drivers/ni_stc.h | 4 +
drivers/staging/comedi/drivers/tests/Makefile | 3 +-
.../comedi/drivers/tests/ni_routes_test.c | 613 ++++++++++++++++++
7 files changed, 1500 insertions(+), 1 deletion(-)
create mode 100644 drivers/staging/comedi/drivers/ni_routes.c
create mode 100644 drivers/staging/comedi/drivers/ni_routes.h
create mode 100644 drivers/staging/comedi/drivers/tests/ni_routes_test.c
[snip]
diff --git a/drivers/staging/comedi/drivers/ni_routes.c
b/drivers/staging/comedi/drivers/ni_routes.c
new file mode 100644
index 000000000000..9e999bc4f3c4
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routes.c
[snip]
+/* **** BEGIN Routes search routines **** */
+static int _ni_bsearch_destcmp(const int *key, const struct ni_route_set *elt)
+{
+ if (*key < elt->dest)
+ return -1;
+ else if (*key > elt->dest)
+ return 1;
+ return 0;
+}
+
+static int _ni_bsearch_srccmp(const int *key, const int *elt)
+{
+ if (*key < *elt)
+ return -1;
+ else if (*key > *elt)
+ return 1;
+ return 0;
+}
Can those be changed to use 'const void *' parameters, like you did for
for the 'sort' callbacks?
+
+/**
+ * ni_find_route_set() - Finds the proper route set with the specified
+ * destination.
+ * @destination: Destination of which to search for the route set.
+ * @valid_routes: Pointer to device routes within which to search.
+ *
+ * Return: NULL if no route_set is found with the specified @destination;
+ * otherwise, a pointer to the route_set if found.
+ */
+const struct ni_route_set *
+ni_find_route_set(const int destination,
+ const struct ni_device_routes *valid_routes)
+{
+ typedef int (*cmp_ftype)(const void *, const void *);
+
+ return bsearch(&destination, valid_routes->routes,
+ valid_routes->n_route_sets, sizeof(struct ni_route_set),
+ (cmp_ftype)_ni_bsearch_destcmp);
+}
+EXPORT_SYMBOL_GPL(ni_find_route_set);
+
+/**
+ * ni_route_set_has_source() - Determines whether the given source is in
+ * included given route_set.
+ *
+ * Return: true if found; false otherwise.
+ */
+bool ni_route_set_has_source(const struct ni_route_set *routes,
+ const int source)
+{
+ typedef int (*cmp_ftype)(const void *, const void *);
+
+ if (!bsearch(&source, routes->src, routes->n_src, sizeof(int),
+ (cmp_ftype)_ni_bsearch_srccmp))
+ return false;
+ return true;
+}
+EXPORT_SYMBOL_GPL(ni_route_set_has_source);
Then you wouldn't need those nasty '(cmp_ftype)' type casts.
--
-=( Ian Abbott <abbo...@mev.co.uk> || Web: www.mev.co.uk )=-
-=( MEV Ltd. is a company registered in England & Wales. )=-
-=( Registered number: 02862268. Registered address: )=-
-=( 15 West Park Road, Bramhall, STOCKPORT, SK7 3JZ, UK. )=-
_______________________________________________
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel