From: krw Date: Wed, 6 Apr 2022 17:39:13 +0000 (+0000) Subject: Avoid traversing SLIST twice to remove a link. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2922073908da1959571aa59f0897ddfceb19a867;p=openbsd Avoid traversing SLIST twice to remove a link. From millert@ --- diff --git a/sys/scsi/scsiconf.c b/sys/scsi/scsiconf.c index 48648fc8ffa..ed0e1115b18 100644 --- a/sys/scsi/scsiconf.c +++ b/sys/scsi/scsiconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scsiconf.c,v 1.252 2022/04/06 13:23:58 krw Exp $ */ +/* $OpenBSD: scsiconf.c,v 1.253 2022/04/06 17:39:13 krw Exp $ */ /* $NetBSD: scsiconf.c,v 1.57 1996/05/02 01:09:01 neil Exp $ */ /* @@ -844,14 +844,17 @@ void scsi_remove_link(struct scsi_link *link) { struct scsibus_softc *sb = link->bus; - struct scsi_link *elm, *tmp; + struct scsi_link *elm, *prev = NULL; - SLIST_FOREACH_SAFE(elm, &sb->sc_link_list, bus_list, tmp) { + SLIST_FOREACH(elm, &sb->sc_link_list, bus_list) { if (elm == link) { - SLIST_REMOVE(&sb->sc_link_list, elm, scsi_link, - bus_list); + if (prev == NULL) + SLIST_REMOVE_HEAD(&sb->sc_link_list, bus_list); + else + SLIST_REMOVE_AFTER(prev, bus_list); break; } + prev = elm; } }