From owner-dev-commits-src-all@freebsd.org Sat Sep 25 13:11:30 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A6A086A8F2D; Sat, 25 Sep 2021 13:11:30 +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 4HGq6V47w4z4X21; Sat, 25 Sep 2021 13:11:30 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 6E7AF2CA4; Sat, 25 Sep 2021 13:11:30 +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 18PDBUOD077193; Sat, 25 Sep 2021 13:11:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 18PDBUtg077192; Sat, 25 Sep 2021 13:11:30 GMT (envelope-from git) Date: Sat, 25 Sep 2021 13:11:30 GMT Message-Id: <202109251311.18PDBUtg077192@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 71d31f1cf601 - main - malloc_aligned(9): allow zero size and alignment MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 71d31f1cf6012b143fd676f099430818ae949c3f Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Sep 2021 13:11:30 -0000 The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=71d31f1cf6012b143fd676f099430818ae949c3f commit 71d31f1cf6012b143fd676f099430818ae949c3f Author: Konstantin Belousov AuthorDate: 2021-09-24 19:38:53 +0000 Commit: Konstantin Belousov CommitDate: 2021-09-25 12:58:12 +0000 malloc_aligned(9): allow zero size and alignment For alignment we do not need to do anything to make it operational. For size, upgrade zero sized request to one byte so that we do not request insane amount of memory for placeholder. Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D32127 --- sys/kern/kern_malloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index 0bdce47b37b4..b1c5909db2a4 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -797,7 +797,7 @@ malloc_domainset_aligned(size_t size, size_t align, void *res; size_t asize; - KASSERT(align != 0 && powerof2(align), + KASSERT(powerof2(align), ("malloc_domainset_aligned: wrong align %#zx size %#zx", align, size)); KASSERT(align <= PAGE_SIZE, @@ -812,6 +812,8 @@ malloc_domainset_aligned(size_t size, size_t align, * align, since malloc zones provide alignment equal to their * size. */ + if (size == 0) + size = 1; asize = size <= align ? align : 1UL << flsl(size - 1); res = malloc_domainset(asize, mtp, ds, flags);