From nobody Mon Mar 06 19:38:21 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PVpld3RsGz3wHmB; Mon, 6 Mar 2023 19:38:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PVpld2fYbz4Mtv; Mon, 6 Mar 2023 19:38:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678131501; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6F8dzPYmamA5oNOLyokaCYRntLF9Jh00aJNJnlyl6LA=; b=nAwkZlN/JS3b2lHO2dny4vs3mYpVzPKTiN/jwNtjf14vtocGTmrWe4kZPY5LSTthvNa96L ksLsexXKEteVsoShtWfLZ59ettDv3JrBgYJ7z3mzhfJ9Nuqn0imvKmtfvsyLF6i/uR76VB OFNITbDCwCv+p1gyciYkoQROjmWU4C88aiF4o8mAw+mSZov1mkfqKkx2+34zpvaIVgUk0h 24XEGTFCel5dSNlKNMGiSC8w9s7Sujy1NpYa9luJ7MiQfUiDsrBV0y9KhTkbUiBXGCi9Gc KC3FEuhh/vJ7lEY9VCKZta6yuwRSgZtijHDjuUiezcFuDCNrkppLkwpVZ6wmyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678131501; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6F8dzPYmamA5oNOLyokaCYRntLF9Jh00aJNJnlyl6LA=; b=cEKeX1vLtgYE1RlcPg3yUkNOpWddZ9BYWGQLV7JcrHT3g/Q6NUrhOHCRxpFKTIx3TRJ00y E72WZLMJSzpsp5yENZvHUgTek5aPNiS8AXWzg1ymdgAYw7VhP1jC7w0JDQp0oJv9XWq3/I gSv1fcarsEp1vssCLyQb2fJ9TJ3d5uw3UDRKa5Q2ZAfuqyKDOztZzB41bjqsNHBC/dwFAc KtDRiZ45jMO/tAWRqExyGhytkZxihvBPffHIKHjvzFWVJOMG2rXOydXGMKMz2cp702dMYJ Onm4DKNxjck6RA6pxPfXvYxxYxagEoI+hVewqBM1T6O9beLsteEj8FKSUMm2Ug== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678131501; a=rsa-sha256; cv=none; b=KyrrYQeqbjwAU/K6gm7hnaJhlEDVFoTKkhbldfLn1Nhzs/HmsdBjEkhT1bi/dQZlaDMFMh AZ1zJAV2ks0y5vGi4Fw7SqUonhFKQQqdw8NuNPI4GvX70qhuutbmbUQzEYQ3JeAERAG7Y2 iWI1bGzs9c1FBbJFW0Train8eBVkx+SolU4PVckofu+yDQ3iUHLrD/+Pb4IJkKQvTUlf1Q lffSmWc5HeMSdatDHvnL751lcEhQGuv0/nQNH6CqRnWp/ziGlW6Cz+b9TtzIUggz8qO8qp FhZOpPo0R78og437Nedof5IcLtEIA4i/HtDBrAVfqRkMRAigGYwLTX+D86oYBg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PVpld1VL8zF19; Mon, 6 Mar 2023 19:38:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 326JcLAM020323; Mon, 6 Mar 2023 19:38:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 326JcLwV020322; Mon, 6 Mar 2023 19:38:21 GMT (envelope-from git) Date: Mon, 6 Mar 2023 19:38:21 GMT Message-Id: <202303061938.326JcLwV020322@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: 6f68483d3f72 - releng/13.2 - netlink: simplify temporary address allocation in rtnl_handle_getlink(). List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.2 X-Git-Reftype: branch X-Git-Commit: 6f68483d3f725052dba22b7c6bdebb71b482760d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.2 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=6f68483d3f725052dba22b7c6bdebb71b482760d commit 6f68483d3f725052dba22b7c6bdebb71b482760d Author: Alexander V. Chernikov AuthorDate: 2023-02-17 17:57:44 +0000 Commit: Ed Maste CommitDate: 2023-03-06 19:37:56 +0000 netlink: simplify temporary address allocation in rtnl_handle_getlink(). Approved by: re (cperciva) (cherry picked from commit 45356a1864c79680c6911b48a18b14a88a7d07fa) (cherry picked from commit 4c1ef49999c6687905664eecd73ea9473ffe5fda) --- sys/netlink/route/iface.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/sys/netlink/route/iface.c b/sys/netlink/route/iface.c index 0eafacff4775..96f21a79a369 100644 --- a/sys/netlink/route/iface.c +++ b/sys/netlink/route/iface.c @@ -439,9 +439,8 @@ rtnl_handle_getlink(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate *n NL_LOG(LOG_DEBUG2, "Start dump"); - struct ifnet **match_array; - int offset = 0, base_count = 16; /* start with 128 bytes */ - match_array = malloc(base_count * sizeof(void *), M_TEMP, M_NOWAIT); + struct ifnet **match_array = NULL; + int offset = 0, base_count = 0; NLP_LOG(LOG_DEBUG3, nlp, "MATCHING: index=%u type=%d name=%s", attrs.ifi_index, attrs.ifi_type, attrs.ifla_ifname); @@ -452,14 +451,14 @@ rtnl_handle_getlink(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate *n if (offset >= base_count) { /* Too many matches, need to reallocate */ struct ifnet **new_array; - int sz = base_count * sizeof(void *); - base_count *= 2; - new_array = malloc(sz * 2, M_TEMP, M_NOWAIT); + /* Start with 128 bytes, do 2x increase on each realloc */ + base_count = (base_count != 0) ? base_count * 2 : 16; + new_array = malloc(base_count * sizeof(void *), M_TEMP, M_NOWAIT); if (new_array == NULL) { error = ENOMEM; break; } - memcpy(new_array, match_array, sz); + memcpy(new_array, match_array, offset * sizeof(void *)); free(match_array, M_TEMP); match_array = new_array; }