Received: by 10.223.176.46 with SMTP id f43csp1572425wra; Wed, 24 Jan 2018 19:42:23 -0800 (PST) X-Google-Smtp-Source: AH8x225CjLd2qUIwZztuC/v4Ye7oTTMVbwiZtL5Jxk9cRNk9QSeI325Jr+2lshs8+ktTQZqR+2NM X-Received: by 10.99.152.10 with SMTP id q10mr3309094pgd.212.1516851742938; Wed, 24 Jan 2018 19:42:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516851742; cv=none; d=google.com; s=arc-20160816; b=hTDqxhswm5U+iG2A/Qe2Mn6lJrGg7tFfwJtxiwXRt5DBOu5KattrXGIiy3pWH10ny3 sz/XofnwHDRqcAvPKee9SVuS+1ykUAnFJWqjSV2WmT1nFpIu3rU6gzRV3BjnQfX0ZdsU gdA+uPpDm+hVoUR5qJScL9rhWjtsw+id1hISg2dIP5lisVyYtDrvaF0r+4AqDhVDYIIt DEU6v8U/mawoWIcVpmMJ66wmv7PmCKtQxN6GR7+V2N4RsMnBKJS9x9DXqLyu89sP6mwc qhJPOAvVY6RyuODxI2f2jzAE8QzBSgW3qAzKZ3d2rWZ9brQqG192L1NpG08dvgjQASHI UAjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=T3+h26Ts4KgWbEfHuqEiBOacZKTpQohhkCnF/cpkrKY=; b=G+Y1kz/R3cpwCdQhUHCDEqotSCFPlQR1itSwKv7oY8eabdhsFtTyR6AFvTN1kleGW9 N5FzwqYOjdy0swWuPXtwKKRzdPOAxf7VpFkhTrRopnxJ1XM6OFNlBOZcYuIROrusCqK/ xs+zA7un4WgdogbxLjnrBWxBOJEgxiOjLQfdWQvrexk6uCPOTOehVHdtuXiFsI1ssW4f FY2bDlI7+/5i/Zr9eUx2AVx6eRj1/mj1FlV2rlYqOhMSFe3rcYYT5p8ciFnieo4DqH3l ckAruM2Ghh3YvCtyBe+DefZ3zGOlCRjiRG4tMuDHeK7Qr0WZctCDKEKcQWllBwdZh/IU fgUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=RW6UqDFN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cisco.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u125si987592pgc.453.2018.01.24.19.42.08; Wed, 24 Jan 2018 19:42:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=RW6UqDFN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cisco.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933751AbeAYDlB (ORCPT + 99 others); Wed, 24 Jan 2018 22:41:01 -0500 Received: from alln-iport-2.cisco.com ([173.37.142.89]:23533 "EHLO alln-iport-2.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933369AbeAYDha (ORCPT ); Wed, 24 Jan 2018 22:37:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=1686; q=dns/txt; s=iport; t=1516851450; x=1518061050; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=7ti1CmKalB2rOy6NHEJ+DZLJMKGu7wCBQHH/kiDtVEo=; b=RW6UqDFNg6js/uUWmxlUgtO4eWJT0r+HgENdSQaOGoHQ3GZLunOxdR24 axqVWD0LWWFuCfb6jrG2tQEaQXn2teEZN6yXU8QCJanTSX/qljsH/QUeH Fp+3yxF4MrZTUKrDz6wc/KTipADmAB/5xaBxLnDlYeMQqhyqOqvqsXF8w o=; X-IronPort-AV: E=Sophos;i="5.46,409,1511827200"; d="scan'208";a="61314487" Received: from rcdn-core-6.cisco.com ([173.37.93.157]) by alln-iport-2.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jan 2018 03:28:00 +0000 Received: from sjc-ads-7132.cisco.com (sjc-ads-7132.cisco.com [10.30.217.207]) (authenticated bits=0) by rcdn-core-6.cisco.com (8.14.5/8.14.5) with ESMTP id w0P3Ruis007601 (version=TLSv1/SSLv3 cipher=AES128-SHA256 bits=128 verify=NO); Thu, 25 Jan 2018 03:27:59 GMT From: Taras Kondratiuk To: "H. Peter Anvin" , Al Viro , Arnd Bergmann , Rob Landley , Mimi Zohar , Jonathan Corbet , James McMechan Cc: initramfs@vger.kernel.org, Victor Kamensky , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, xe-linux-external@cisco.com Subject: [PATCH v2 03/15] initramfs: store file name in name_buf Date: Thu, 25 Jan 2018 03:27:43 +0000 Message-Id: <1516850875-25066-4-git-send-email-takondra@cisco.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516850875-25066-1-git-send-email-takondra@cisco.com> References: <1516850875-25066-1-git-send-email-takondra@cisco.com> X-Auto-Response-Suppress: DR, OOF, AutoReply X-Authenticated-User: takondra@cisco.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is already name_buf buffer pre-allocated for a file name. No need to allocate vcollected for every file. More over a name can be already stored in name_buf by read_info() function. Add memcpy_optional() function to handle such case. Signed-off-by: Taras Kondratiuk --- init/initramfs.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index 49cd2681a26f..b6ee675e5cdb 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -210,7 +210,6 @@ static inline void __init eat(unsigned n) byte_count -= n; } -static __initdata char *vcollected; static __initdata char *collected; static long remains __initdata; static __initdata char *collect; @@ -324,6 +323,13 @@ static void __init clean_path(char *path, umode_t fmode) } } +static void *memcpy_optional(void *dest, const void *src, size_t n) +{ + if (dest != src) + return memcpy(dest, src, n); + return dest; +} + static __initdata int wfd; static int __init do_name(void) @@ -348,7 +354,8 @@ static int __init do_name(void) sys_fchmod(wfd, mode); if (body_len) sys_ftruncate(wfd, body_len); - vcollected = kstrdup(collected, GFP_KERNEL); + memcpy_optional(name_buf, collected, + N_ALIGN(name_len)); state = do_copy; } } @@ -375,8 +382,7 @@ static int __init do_copy(void) if (xwrite(wfd, victim, body_len) != body_len) error("write error"); sys_close(wfd); - do_utime(vcollected, mtime); - kfree(vcollected); + do_utime(name_buf, mtime); eat(body_len); state = do_skip; return 0; -- 2.10.3.dirty