From owner-svn-src-head@freebsd.org Thu Aug 23 05:06:14 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5AA1110801FE; Thu, 23 Aug 2018 05:06:14 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id CE5397FB28; Thu, 23 Aug 2018 05:06:13 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 714241D72B; Thu, 23 Aug 2018 05:06:12 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7N56CxD062889; Thu, 23 Aug 2018 05:06:12 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7N56CvH062888; Thu, 23 Aug 2018 05:06:12 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201808230506.w7N56CvH062888@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Thu, 23 Aug 2018 05:06:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r338235 - head/sbin/devmatch X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/sbin/devmatch X-SVN-Commit-Revision: 338235 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Aug 2018 05:06:14 -0000 Author: imp Date: Thu Aug 23 05:06:11 2018 New Revision: 338235 URL: https://svnweb.freebsd.org/changeset/base/338235 Log: Remove sorting of matches and print all the matches as we find them. This backs out the hack we added in r329458. Now that we can freeze / thaw probing, this is a much better solution to that problem. Revert to simply printing the results as we find them, and relying on an external sort | uniq to clean up the list. Differential Revision: https://reviews.freebsd.org/D16735 Modified: head/sbin/devmatch/devmatch.c Modified: head/sbin/devmatch/devmatch.c ============================================================================== --- head/sbin/devmatch/devmatch.c Thu Aug 23 05:06:07 2018 (r338234) +++ head/sbin/devmatch/devmatch.c Thu Aug 23 05:06:11 2018 (r338235) @@ -56,12 +56,6 @@ static struct option longopts[] = { #define DEVMATCH_MAX_HITS 256 -static struct match_data { - char *descr; - int priority; -} match_data[DEVMATCH_MAX_HITS]; - -static int hit_index; static int all_flag; static int dump_flag; static char *linker_hints; @@ -240,35 +234,6 @@ pnpval_as_str(const char *val, const char *pnpinfo) return retval; } -static int -match_data_compare(const void *_pa, const void *_pb) -{ - const struct match_data *pa = _pa; - const struct match_data *pb = _pb; - - /* biggest value first */ - if (pa->priority > pb->priority) - return (-1); - else if (pa->priority < pb->priority) - return (1); - - /* then sort by string */ - return (strcmp(pa->descr, pb->descr)); -} - -static int -bitrev16(int input) -{ - int retval = 0; - int x; - - for (x = 0; x != 16; x++) { - if ((input >> x) & 1) - retval |= (0x8000 >> x); - } - return (retval); -} - static void search_hints(const char *bus, const char *dev, const char *pnpinfo) { @@ -417,22 +382,12 @@ search_hints(const char *bus, const char *dev, const c printf("\n"); else if (!notme) { if (!unbound_flag) { - char *descr = NULL; - if (all_flag) - asprintf(&descr, "%s: %s", *dev ? dev : "unattached", lastmod); + printf("%s: %s", *dev ? dev : "unattached", lastmod); else - asprintf(&descr, "%s", lastmod); + printf("%s", lastmod); if (verbose_flag) printf("Matches --- %s ---\n", lastmod); - - if (descr != NULL && hit_index < DEVMATCH_MAX_HITS) { - match_data[hit_index].descr = descr; - match_data[hit_index].priority = bitrev16(mask); - hit_index++; - } else { - free(descr); - } } found++; } @@ -445,19 +400,6 @@ search_hints(const char *bus, const char *dev, const c } walker = (void *)(len - sizeof(int) + (intptr_t)walker); } - if (hit_index != 0) { - /* sort hits by priority */ - mergesort(match_data, hit_index, sizeof(match_data[0]), &match_data_compare); - - /* printout */ - for (i = 0; i != hit_index; i++) { - puts(match_data[i].descr); - free(match_data[i].descr); - } - - /* reset hit_index */ - hit_index = 0; - } if (unbound_flag && found == 0 && *pnpinfo) { if (verbose_flag) printf("------------------------- ");