From patchwork Sun May 28 16:20:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 13257865 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F49AC77B7C for ; Sun, 28 May 2023 16:20:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35FF36B0071; Sun, 28 May 2023 12:20:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30EE26B0074; Sun, 28 May 2023 12:20:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D6386B0075; Sun, 28 May 2023 12:20:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0D3A26B0071 for ; Sun, 28 May 2023 12:20:33 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BC682ADC6C for ; Sun, 28 May 2023 16:20:32 +0000 (UTC) X-FDA: 80840176704.12.D5B06DF Received: from smtp.smtpout.orange.fr (smtp-17.smtpout.orange.fr [80.12.242.17]) by imf20.hostedemail.com (Postfix) with ESMTP id E8A241C0015 for ; Sun, 28 May 2023 16:20:30 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=wanadoo.fr header.s=t20230301 header.b=KVeczUZ2; dmarc=none; spf=pass (imf20.hostedemail.com: domain of christophe.jaillet@wanadoo.fr designates 80.12.242.17 as permitted sender) smtp.mailfrom=christophe.jaillet@wanadoo.fr ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685290831; a=rsa-sha256; cv=none; b=mdESdVlgILldPO9ZyDBAm5Be9ctxXbDkNzYjRTJAzCjE2peSIgWC9VJtYKjlHpexaKBkfb G0F+zpSPeswPrsaYFwUqmagYDJnqE66D2LkXxp8nLEpKdVqTmYMsMAmlLJgAVgAy6+vNGG aMTgQEerG2bFG2hkh6J/iBSD+65SyCs= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=wanadoo.fr header.s=t20230301 header.b=KVeczUZ2; dmarc=none; spf=pass (imf20.hostedemail.com: domain of christophe.jaillet@wanadoo.fr designates 80.12.242.17 as permitted sender) smtp.mailfrom=christophe.jaillet@wanadoo.fr ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685290831; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=a2vlfOS/zd156pwgWbEvLCkl+o6nZ4EPHRWlCYI1/Dc=; b=xVE+pmuFBFywaX/6iEcKqb1brN7qljH9nW9AM4XbBd+u40Vmv736s+Dbc4gYh6+ffeUdlo xKgmjdWLXRl86dVBR+t8uDtVHgs5f30I1lD1ffSyc1nkMUTnTizXfA0mv6QqJlbSrRUAot r6QWh/cPcRYZJRWVJlUjtGnxuIH7/z4= Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id 3J87qJcsWrDwx3J87qjZRk; Sun, 28 May 2023 18:20:29 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1685290829; bh=a2vlfOS/zd156pwgWbEvLCkl+o6nZ4EPHRWlCYI1/Dc=; h=From:To:Cc:Subject:Date; b=KVeczUZ2SyAWnA9n3+aJnOifGCiTgEBfhm1Wso9EJlktFte7I/K8YRWaX0PD1LAA+ TyZ45qzvlxznn3FHzzU/LgAHEWWLn5J1J/FW9lQFLfhvBA0W+f/l2ZD5tz2osdtA0x Rnzuzet0WwEtNtln/r545IpoMMkikmB/3McAaG56VrZucC2AFhJN8xHSvcCce5aDU0 kdMGUJzsigwyY+rtfN2seE6H1bMQFwOB248InKFtDuqb5TAvEqi/l4PGejxwsz8Hwl CHwz7QDQcX+mOs3cme9JFRxThY7U6uqMBO1tMEipxYN4CAgH/WOy+9Tcc2IRhAjSne iXOfKYaNp6gfw== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 28 May 2023 18:20:29 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Alexander Viro , Christian Brauner , Eric Biederman , Kees Cook Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/2] binfmt: Use struct_size() Date: Sun, 28 May 2023 18:20:24 +0200 Message-Id: <53150beae5dc04dac513dba391a2e4ae8696a7f3.1685290790.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E8A241C0015 X-Stat-Signature: oezp1531sduqxwqjrxeq6hp8dpm73d43 X-HE-Tag: 1685290830-881265 X-HE-Meta: U2FsdGVkX1/z775x+ZdczVnzcJAkxImTsShunceuN7gF7P5vf9rTBM5qrvOprzTkjX//Dd+9byGDcxQ23n66M2GVWXJcezwOkKoLuteTzPx5CQXz0cMqrHz6FnRETyuxvoDRoQYYS0K/8M2bHGS5UIUEBQ27L7RB+sNEW8eSiOwn+L3fF7js55SIGTsderUgiNf+EcmyGyOT2fYJFra/+wAN76O9QrYcdWlrZrbEPIu7ozYWP30MfqOK6noB/VmmfCRbBnoshx0ZL1xyN6lTbAIhya+PK8PIIT33WyW92eROCc5WlaSboiFkyP2CiytUuGVE60RDeRskD9ONYslO9j5PQsrA5raabwfwuUYRQSE5eruzVXT+2DVK6TTV9sEkiqvsuO10hd0eDnZlS72J+MV+IoFUGmXykYv6X2QEkM7t2PdDtdWRtvrgxbXUKdBpajFECLL79z+7CDWf0XisMV4gqauFaU7EXKqPgFN4cBoSUm0OdgBVGxkjkA1Sv+xGciJsRShopL3KDs4HEolbZfPIQkOxRRmZ0VRmb18mU2pKrgY1fzRDg6lBFns4HB9VXpEVR1xEfKzqFaUtehUgl53CtVropmOjeUz4rKf/lNbl4YTjocIFDdb4cN71dWRVDtRoJULO4jGUbugS827KYCZv1+++UMOdUbmhrWOO5Gvu9GaQpnwJfC9bMDEljjS3KERSGj9Y7PJAjy0ZHgOQ9tLeY/dC3F8VVFX6QiZ3QZyc5v+1ThP2OzxNbaEcIa1hfjzmUR5aKLKOF/u6ColXW9W3tSJTzAZ+LC59lIISW/8+01raed5bBAwarsQi5f0YvCjpBZ8/fCKgVQqDu3yfgEbUcTL8GKahtIx8vSnpkvjm3A2NtbkUj4WbqRhlPb37qhTK0XxJWCJ7Ck+j5Rayp7JZUEEQXHj7ozQUQQfrx6+erF+YMFHj4wo2cyoULiURYjrNAl7GGVhJqG1SNst 6R4RApjX h0w3Wigx9Rd2G+t/+mMrK3m+TmL09RUEwV3OMeaXTlLrHOsjdGxwSxrUXzJ50kxpq4l8NQhKhtQsemZJvU3/79gbkeBv8M2cN6IiWrcjJ/Mh58bXtCd1UkojeeLhZt6Kc0HLN49TT/SYIYtP1eM0d6AGrhKM25EV8cBC9YDNRf1CRnOeZDgE1ryPU21nouaql6gNcLkN0Kjhl3UUN/riexA35Yi/ZBFWQJKRv X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use struct_size() instead of hand-writing it. It is less verbose, more robust and more informative. Signed-off-by: Christophe JAILLET Acked-by: "Eric W. Biederman" --- Compile tested on arm --- fs/binfmt_elf_fdpic.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index d76ad3d4f676..237ce388d06d 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -748,7 +748,6 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params, struct elf32_phdr *phdr; unsigned long load_addr, stop; unsigned nloads, tmp; - size_t size; int loop, ret; /* allocate a load map table */ @@ -760,8 +759,7 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params, if (nloads == 0) return -ELIBBAD; - size = sizeof(*loadmap) + nloads * sizeof(*seg); - loadmap = kzalloc(size, GFP_KERNEL); + loadmap = kzalloc(struct_size(loadmap, segs, nloads), GFP_KERNEL); if (!loadmap) return -ENOMEM;