From 272e4f538467f41eebf611cf7ce92c5c80afcbff Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Thu, 13 Jan 2022 15:22:13 -0700 Subject: [PATCH] cam: Fix wiring fence post error If the last matching device entry partially matched in camperiphunit, but then hit a continue case, we'd mistakenly think we had a match on that entry. This lead to a number of problems downstream (usually a belief that we had a duplicate wiring hint because unit = 0 is the default). Fix this by using a for loop that does the assignment before the loop termination test. Sponsored by: Netflix Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D33873 --- sys/cam/cam_periph.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sys/cam/cam_periph.c b/sys/cam/cam_periph.c index 1203ac2d9b2..869691f59a7 100644 --- a/sys/cam/cam_periph.c +++ b/sys/cam/cam_periph.c @@ -611,8 +611,9 @@ camperiphunit(struct periph_driver *p_drv, path_id_t pathid, unit = 0; i = 0; dname = periph_name; - while (resource_find_dev(&i, dname, &dunit, NULL, NULL) == 0) { - wired = false; + + for (wired = false; resource_find_dev(&i, dname, &dunit, NULL, NULL) == 0; + wired = false) { if (resource_string_value(dname, dunit, "at", &strval) == 0) { if (strcmp(strval, pathbuf) != 0) continue;