Message ID | 53150beae5dc04dac513dba391a2e4ae8696a7f3.1685290790.git.christophe.jaillet@wanadoo.fr |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1041585vqr; Sun, 28 May 2023 09:26:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6rCzOC8HvHiRjORH7bTLKSkmjxCb1DJhUrG0J3uff0FsIeBFkJmUoIa6lRPPvSTrDZEFjW X-Received: by 2002:a05:6a20:3955:b0:10f:243c:a6e7 with SMTP id r21-20020a056a20395500b0010f243ca6e7mr7255463pzg.13.1685291208949; Sun, 28 May 2023 09:26:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685291208; cv=none; d=google.com; s=arc-20160816; b=WtIrGVDyl0ejLcR0QJ1id6R8j1ukPyz8QJchq2QH/x5iacRTUVXxMiamf8WRRkuX4W zwx/gO2Y9dumRCOdhfXbDsPZhpTdOblWuEHv2bqxcH8aUFCKo5Xn3QYctiVitBot6D5t EGpMoPLC6poSEw84FLjS3yhu8XQ7pxkxwpVQsPUCGfp4BE8iv8HYM6hcBW1Oir5KY+b7 2SSaePuaXp7jF7cVUdyb9f5eJRlyTmN5hKhv0TsEu3rHdeb6st8nDbgJ6782vyHyy9UT HvM3QizdA3t8DYwGH841Nq9xgL6ulOGYs33Av8Cb70VA+wbey3qTXHMR9LowF7vdMC0k iwkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=a2vlfOS/zd156pwgWbEvLCkl+o6nZ4EPHRWlCYI1/Dc=; b=XmXR3zb0+E8yaaSRZyXpqLFhijhciexab0JR2OcoufBk2ksHj4tpMYvI4BmUJZz5sr hWPiLROIMN4mpgfaRC0xK0UsSrxbX4HRN8ttjN0HMa04nK+YF/B6wA59h827crPm8aOt 4n6LKowS+PmT+kTYkzm6VnJjyekTeWUUnpqx3w3I8jeqwPx5p9AObjLcq/U1Tb5QM2bH L0U7yv7YesB2bzN0YrMuFQBoqs4jtDmD6OMstltr3KhmOdMPUYYCU09+2V2GMbG6qA09 wI88WeLHzLHJrT6rxfp1S1L/MH+HLWQ4pFEDMZjUFuDvfglHzTmdY5gxU2akMpeVX7Nt kCwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=KVeczUZ2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m5-20020a633f05000000b0053f3e6ec82bsi6596754pga.774.2023.05.28.09.26.36; Sun, 28 May 2023 09:26:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=KVeczUZ2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229629AbjE1QUe (ORCPT <rfc822;zhuangel570@gmail.com> + 99 others); Sun, 28 May 2023 12:20:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbjE1QUc (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 28 May 2023 12:20:32 -0400 Received: from smtp.smtpout.orange.fr (smtp-18.smtpout.orange.fr [80.12.242.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ECC3BD for <linux-kernel@vger.kernel.org>; Sun, 28 May 2023 09:20:31 -0700 (PDT) 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 <christophe.jaillet@wanadoo.fr> To: Alexander Viro <viro@zeniv.linux.org.uk>, Christian Brauner <brauner@kernel.org>, Eric Biederman <ebiederm@xmission.com>, Kees Cook <keescook@chromium.org> Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET <christophe.jaillet@wanadoo.fr>, 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767155914506282779?= X-GMAIL-MSGID: =?utf-8?q?1767155914506282779?= |
Series |
[1/2] binfmt: Use struct_size()
|
|
Commit Message
Christophe JAILLET
May 28, 2023, 4:20 p.m. UTC
Use struct_size() instead of hand-writing it. It is less verbose, more
robust and more informative.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested on arm
---
fs/binfmt_elf_fdpic.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
Comments
Christophe JAILLET <christophe.jaillet@wanadoo.fr> writes: > Use struct_size() instead of hand-writing it. It is less verbose, more > robust and more informative. Acked-by: "Eric W. Biederman" <ebiederm@xmission.com> Obviously correct transform. > > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > --- > 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;
On Sun, 28 May 2023 18:20:24 +0200, Christophe JAILLET wrote: > Use struct_size() instead of hand-writing it. It is less verbose, more > robust and more informative. > > Applied to for-next/execve, thanks! [1/2] binfmt: Use struct_size() https://git.kernel.org/kees/c/e6302d5a285b [2/2] binfmt: Slightly simplify elf_fdpic_map_file() https://git.kernel.org/kees/c/36650a357eac
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;