From patchwork Mon Apr 4 09:34:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 12800053 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B62D8C433EF for ; Mon, 4 Apr 2022 09:35:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354446AbiDDJhl (ORCPT ); Mon, 4 Apr 2022 05:37:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354379AbiDDJhi (ORCPT ); Mon, 4 Apr 2022 05:37:38 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F62B2FFE8 for ; Mon, 4 Apr 2022 02:35:42 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 317B21F383; Mon, 4 Apr 2022 09:35:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1649064941; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iDMC93HcmGE4d4iP45Rmb3DTrhyTD7MhyFklq+M0cvM=; b=KHp1rIXTMER3lYVeoocsdbV9mWckr09W5Q16L3i1xwBb+6g6SgcG3io2N3BFZKUQvJ1bVu Bry7BjYD6Vmr9hCVqvHW3tT25cMG4VvEmLfYEleE9wd/CgbOqwoJdovWOkSxi+NieBwQgE Cf6aXcHU4UJpZ/+nrXbxvC+ADPGqKLA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1649064941; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iDMC93HcmGE4d4iP45Rmb3DTrhyTD7MhyFklq+M0cvM=; b=X8fmqi4ikZTv5BMO4VjKaqDNCmDCL6uBI54CB9q/DZZseqWQXFQAyDEn0nNHSW1ULSfvz4 EtCMinKUSWOFctCA== Received: from echidna.suse.de (unknown [10.163.47.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 056F7A3B8A; Mon, 4 Apr 2022 09:35:41 +0000 (UTC) From: David Disseldorp To: linux-fsdevel@vger.kernel.org, Andrew Morton Cc: viro@zeniv.linux.org.uk, willy@infradead.org, David Disseldorp , Christian Brauner Subject: [PATCH v7 2/6] initramfs: make dir_entry.name a flexible array member Date: Mon, 4 Apr 2022 11:34:26 +0200 Message-Id: <20220404093429.27570-3-ddiss@suse.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220404093429.27570-1-ddiss@suse.de> References: <20220404093429.27570-1-ddiss@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org dir_entry.name is currently allocated via a separate kstrdup(). Change it to a flexible array member and allocate it along with struct dir_entry. Signed-off-by: David Disseldorp Acked-by: Christian Brauner --- init/initramfs.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/init/initramfs.c b/init/initramfs.c index 2f79b3ec0b40..656d2d71349f 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -130,17 +130,20 @@ static long __init do_utime(char *filename, time64_t mtime) static __initdata LIST_HEAD(dir_list); struct dir_entry { struct list_head list; - char *name; time64_t mtime; + char name[]; }; static void __init dir_add(const char *name, time64_t mtime) { - struct dir_entry *de = kmalloc(sizeof(struct dir_entry), GFP_KERNEL); + size_t nlen = strlen(name) + 1; + struct dir_entry *de; + + de = kmalloc(sizeof(struct dir_entry) + nlen, GFP_KERNEL); if (!de) panic_show_mem("can't allocate dir_entry buffer"); INIT_LIST_HEAD(&de->list); - de->name = kstrdup(name, GFP_KERNEL); + strscpy(de->name, name, nlen); de->mtime = mtime; list_add(&de->list, &dir_list); } @@ -151,7 +154,6 @@ static void __init dir_utime(void) list_for_each_entry_safe(de, tmp, &dir_list, list) { list_del(&de->list); do_utime(de->name, de->mtime); - kfree(de->name); kfree(de); } }