From nobody Fri Feb 17 18:16:46 2023 X-Original-To: dev-commits-src-main@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 4PJKlL3tTBz3rGj5; Fri, 17 Feb 2023 18:16:46 +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 4PJKlL37rrz3sm4; Fri, 17 Feb 2023 18:16:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676657806; 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=Gl2Ugm7vC0QjVLZvJN6eoiRbBLW6+elOt8/5WsbEIa4=; b=RduTfNsscgJRpofh2e03G0RGYzzA9BgHyANrbjyg35WPg/2JBeuKraifg9GCuzg6LiybPF oKzwIIu82aW8Pt16LGBx6MKVWubvQCulKl5E6ysOUpd7xBKQO/95gFcJut5bZHM3fuPktI OCpkEA3NTaqRvNKCvjB9yD7lKwS4gm7nQCQz0yf/QlF43BSHZuBZPa+V7s1dQvmDSZIFJT OK8CjKKI0078KRpNkliD+xrbeANCZU+holxtnwPMuUNMbVbMQBtpcXSuIDySjvyFZv/r3f Alsy7bWHdchCaPwAZBYEIBGTQHhqHypKqET/Gi6y/zEFUYkFQ/4qwuV00HPjxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676657806; 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=Gl2Ugm7vC0QjVLZvJN6eoiRbBLW6+elOt8/5WsbEIa4=; b=xDyiHUZFMd4Da1wgSM0GUaurgL3nVQoYa4FJBO+1mPZO227N9fSOOSFVlMF0qD8mw0jnMp lJ4q9mBLgDSs68I3jbxNQuUc7EJwkqTJ1OegRLX8W0AROnX1NecUq3B9tc2RNUeSCF43an yUX9jUTfcmEl2fIqOID4JbbjS8iWO/2K9Q9cEbH/kaaNUchCpQT/CxKxZjBHTMiqV3fDMz 65qAaqwxauc0a4+ZOw2VtO62lVHZM6ef/ugSrNo5Ns/Nk7wSCK3Ikk+0WZyPAVzC9sXrAl 89YqcH491sfN/sYkdw6zJBrk/JKwTEU8oYpKn6pj5KouzetexWUvtI3htxtX7Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676657806; a=rsa-sha256; cv=none; b=sHaJTY3kPOqbNrCnZR64kgot5ts+yyDSU0CWpdv7sSYKHKcWON5/ARtmoGXO50PVya8vW5 FbYHPOYoNnwD2j4Ec1za0eZoRTLQEUxy/x+u8JONJpgy0/FHh4LQwLNjKUcFyQY2UnzaPV ExrnVNy3IMsrZsQrc647O3hyf4tKISlNW43ytmlom9OmGrwgcnZ4q9ldr+v27DlZy2aOew bRt3RahqAgpaN1CwJbTzZI3/GeKsCtx1DjGV68gzKixQnW3Wf+upcCLSn0MYB1RXDNMkp6 x4KdFQ0SsCBCRyPjW+KPqHrvVl6Wx/FVe2yDFuuUxPY8SrnkkZYHwIPsaUD0+w== 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 4PJKlL2BsMzsmM; Fri, 17 Feb 2023 18:16:46 +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 31HIGkWH054359; Fri, 17 Feb 2023 18:16:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31HIGkYd054358; Fri, 17 Feb 2023 18:16:46 GMT (envelope-from git) Date: Fri, 17 Feb 2023 18:16:46 GMT Message-Id: <202302171816.31HIGkYd054358@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 45356a1864c7 - main - netlink: simplify temporary address allocation in rtnl_handle_getlink(). List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 45356a1864c79680c6911b48a18b14a88a7d07fa Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=45356a1864c79680c6911b48a18b14a88a7d07fa commit 45356a1864c79680c6911b48a18b14a88a7d07fa Author: Alexander V. Chernikov AuthorDate: 2023-02-17 17:57:44 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-02-17 18:16:07 +0000 netlink: simplify temporary address allocation in rtnl_handle_getlink(). MFC after: 3 days --- 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; }