From owner-svn-src-all@freebsd.org Sun Jan 7 18:30:08 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 923CBE79E08; Sun, 7 Jan 2018 18:30:08 +0000 (UTC) (envelope-from srs0=cu0q=ec=freebsd.org=kp@codepro.be) Received: from venus.codepro.be (venus.codepro.be [IPv6:2a01:4f8:162:1127::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.codepro.be", Issuer "Gandi Standard SSL CA 2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 59B3B722E3; Sun, 7 Jan 2018 18:30:08 +0000 (UTC) (envelope-from srs0=cu0q=ec=freebsd.org=kp@codepro.be) Received: from [10.0.2.164] (ptr-8ripyyhthbnp0l0tszn.18120a2.ip6.access.telenet.be [IPv6:2a02:1811:2419:4e02:e0f1:72a1:d72b:ec03]) (Authenticated sender: kp) by venus.codepro.be (Postfix) with ESMTPSA id 181FBAE7A; Sun, 7 Jan 2018 19:30:06 +0100 (CET) From: "Kristof Provost" To: rgrimes@freebsd.org Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r327676 - head/sys/compat/linuxkpi/common/include/linux Date: Sun, 07 Jan 2018 19:30:04 +0100 X-Mailer: MailMate (2.0BETAr6102) Message-ID: <219974D5-0240-49D9-8DE4-C1FBCEF74776@FreeBSD.org> In-Reply-To: <201801071802.w07I2YEB017699@pdx.rh.CN85.dnsmgr.net> References: <201801071802.w07I2YEB017699@pdx.rh.CN85.dnsmgr.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Jan 2018 18:30:08 -0000 On 7 Jan 2018, at 19:02, Rodney W. Grimes wrote: > [ Charset UTF-8 unsupported, converting... ] >> Author: kp >> Date: Sun Jan 7 13:39:12 2018 >> New Revision: 327676 >> URL: https://svnweb.freebsd.org/changeset/base/327676 >> >> Log: >> linuxkpi: Implement kcalloc() based on mallocarray() >> >> This means we now get integer overflow protection, which Linux code >> might expect as it is also provided by kcalloc() in Linux. >> >> Modified: >> head/sys/compat/linuxkpi/common/include/linux/slab.h >> >> Modified: head/sys/compat/linuxkpi/common/include/linux/slab.h >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D >> --- head/sys/compat/linuxkpi/common/include/linux/slab.h Sun Jan 7 = >> 13:35:15 2018 (r327675) >> +++ head/sys/compat/linuxkpi/common/include/linux/slab.h Sun Jan 7 = >> 13:39:12 2018 (r327676) >> @@ -46,7 +46,6 @@ MALLOC_DECLARE(M_KMALLOC); >> #define kzalloc(size, flags) kmalloc(size, (flags) | __GFP_ZERO) >> #define kzalloc_node(size, flags, node) kmalloc(size, (flags) | = >> __GFP_ZERO) >> #define kfree_const(ptr) kfree(ptr) >> -#define kcalloc(n, size, flags) kmalloc((n) * (size), = >> (flags) | __GFP_ZERO) > > Would not: > #define kcalloc(n, size, flags) mallocarray(mallocarray((n), = > (size), M_KMALLOC, linux_check_m_flags((flags | __GFP_ZERO)) > work just fine, saving a call and stack use of about framesize + 32 = > bytes? > > It would also work, but it=E2=80=99d have to be split up into multiple li= nes = then. I thought it=E2=80=99d be more readable as a function. It=E2=80=99s an inline function, so it won=E2=80=99t actually use stack s= pace in = practice. Also, it used to call kmalloc(), which is also an inline function, so at = worst we=E2=80=99ve traded one function for another. Regards, Kristof