Received: by 10.223.185.116 with SMTP id b49csp1109950wrg; Fri, 16 Feb 2018 12:39:01 -0800 (PST) X-Google-Smtp-Source: AH8x226cT83+8FwSHXmgzs+QQaw9kiEWpyV9wISURHK4C6/kndr3YedDzh6dSpEqHqIuiFr9SG9u X-Received: by 10.101.82.1 with SMTP id o1mr6033762pgp.259.1518813541392; Fri, 16 Feb 2018 12:39:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518813541; cv=none; d=google.com; s=arc-20160816; b=exOScK9fbcJB6JCHBmbqIJLpJmjEPPKjUeEnWFxjUr4eRVY1fM3w9KsVfSWhhudAzn 9b1NHP6Ak22RP42UUL9IdhBdjo/m+oalGIcSftuP9QvOTtyKmvhWTe96fnOA1HQGcFoD tEuGVsyoiH6k7sK3utxOiMsPM/rga7ZephPBeRC0ZH+b+khLx0fJkVHoUCCLZ/p+L2Kh XzS0MX6uo+GW6B5buFiXmwJ2KyBVRv9mM7Yukbb+B6FVGnkJPr+OszUEVsRvWpONOfhT gKk4cFe/7qUaZEHRkAdCpea5PaMdSYLRoTxL8KRbpQwvFSjLStUlMi+y4YPf6UQNgueV lZPA== 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=0zlDj1bVdWmd4Q7B68wHXQKD+s+sjrN4wljyvc9nNlCdLaDzeNSD6GzippzqPfcXE8 sOa/UUer1X1rZC9TJE2V5ZAa08j/dbTLEfEQuO/4g/dNuDTY6XLaI824VmICabgGK23q H5Nk8ins08GxhM1uhLnTM4F/CPJ5d2A8C9dJwi5NbXZ7PGL1gEmle6CoPXXttkIdNoSf vM3seBe86OGGvkIUL2CFBQQo5NT+roJ9mtWRE+S+J5JxeGy/eEZ56en5HrIv6P2t90MH 2jHjpOBiG7j+1JqEHoBQsRsAOCU+kr/ePirHXmrUd8feM8jgNbDdLNwtz/TWLVUl7xXa H/og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=kmG/0WdO; 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 f188si422248pgc.140.2018.02.16.12.38.46; Fri, 16 Feb 2018 12:39:01 -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=kmG/0WdO; 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 S1751032AbeBPUeF (ORCPT + 99 others); Fri, 16 Feb 2018 15:34:05 -0500 Received: from rcdn-iport-5.cisco.com ([173.37.86.76]:37473 "EHLO rcdn-iport-5.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750783AbeBPUd7 (ORCPT ); Fri, 16 Feb 2018 15:33:59 -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=1518813239; x=1520022839; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=7ti1CmKalB2rOy6NHEJ+DZLJMKGu7wCBQHH/kiDtVEo=; b=kmG/0WdO4oZV60wz9NqXUEO2MfEC3TfHa1RjegV/Ek8OE+JfOVx1XnWU uXwEilHbrdhvMWadTcT02qesuLYZc6gpcWZnX4VHG9XuWImdXH5QSUCXl k07K/1VwFno75wuJ3Pm9MP6n7C7oXICM46RCAfgboHDKANXcQgvhMMMcC U=; X-IronPort-AV: E=Sophos;i="5.46,520,1511827200"; d="scan'208";a="139025483" Received: from rcdn-core-6.cisco.com ([173.37.93.157]) by rcdn-iport-5.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Feb 2018 20:33:58 +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 w1GKXsMS015412 (version=TLSv1/SSLv3 cipher=AES128-SHA256 bits=128 verify=NO); Fri, 16 Feb 2018 20:33:57 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 v3 03/15] initramfs: store file name in name_buf Date: Fri, 16 Feb 2018 20:33:39 +0000 Message-Id: <1518813234-5874-4-git-send-email-takondra@cisco.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518813234-5874-1-git-send-email-takondra@cisco.com> References: <1518813234-5874-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