From patchwork Wed Jun 7 16:15:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 104612 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp324995vqr; Wed, 7 Jun 2023 09:29:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ys1tokvOtLqe9D7VH459bmG/jTrBm3K+3JhTh8VJab0R8yMyETtVgzRAUXEsiixuG0eUk X-Received: by 2002:a17:90a:94c9:b0:258:6eb3:44c3 with SMTP id j9-20020a17090a94c900b002586eb344c3mr2258851pjw.44.1686155342362; Wed, 07 Jun 2023 09:29:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686155342; cv=none; d=google.com; s=arc-20160816; b=R67m8ItjzidhLYNhTJfjr2UDsDn7TMj+h1QealxRKL4KDqPyypsebpmiEBhO9Ahs3O EYVa5wMKb5xYgJR09r0Amyuw9eZLAFalEqxV9V/njpUNmHysgJZg18oTg4oxNZDZA1Iy Lo+PAtQKnntYUtGHr+HrgR2nBfVRMwHMAqyF/sYK2zTpPH1lQvGvn/bRTrfC3Su8qbrL /Ma+gBwpgTVmJVXSJAFwajj7f4x5gykzXhvZuTZRf563ejPswtXCUIjY3mKtVzPEAQXu KIcan2lzBcUnM5LDAPLJUr7EpLidk6NRQJlaQ73NwgtJjxeiqFYOJI4QFMBvklLSxfjF kxBw== 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; bh=wZlRLu2oa+cEAiiHwuArjtX68YyOq6OsWZDKYx0QQDM=; b=PCEluoNaxcC8y/W+EG6e+LJiVH1dq3Gf1U7z7JK1XGwj8oaPmdojhIaAwWb24NYIVD 1YLaAQYGcyMZKkKmt1wAt0UqTUW8Qn9uc9PSm8jQWVd9wnJZNmd0VZitrhVWVg5hupKx O4D0Eh2RZFVGZa8qx0zTGmyJ6RoAEzI59lhX3fRqOJFfyQhe4O+OIpMr8kgZCPeUwouv hwESPfLVEyT9aGAtO7o+CqCqxTsvTfdCxgRhwzm4ajNoQ/q6aE27v7YIm6JRW7ENGQDo 53BgqGuKCPBhJw8C0TC4LTjQokCJsdwVqwC57ictaUQBRdJdlbcPNStLnsrlwpTxnLj7 axsQ== ARC-Authentication-Results: i=1; mx.google.com; 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 q65-20020a632a44000000b0053fb354c194si9282371pgq.659.2023.06.07.09.28.48; Wed, 07 Jun 2023 09:29:02 -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; 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 S241596AbjFGQQA (ORCPT + 99 others); Wed, 7 Jun 2023 12:16:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240581AbjFGQP6 (ORCPT ); Wed, 7 Jun 2023 12:15:58 -0400 Received: from frasgout11.his.huawei.com (unknown [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9D39199D; Wed, 7 Jun 2023 09:15:53 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4Qbscz46shz9v7N7; Thu, 8 Jun 2023 00:05:23 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP2 (Coremail) with SMTP id GxC2BwDXhz4mrYBkJHoTAw--.4340S2; Wed, 07 Jun 2023 17:15:39 +0100 (CET) From: Roberto Sassu To: hughd@google.com, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, Roberto Sassu , stable@vger.kernel.org Subject: [PATCH] shmem: Use ramfs_kill_sb() for kill_sb method of ramfs-based tmpfs Date: Wed, 7 Jun 2023 18:15:23 +0200 Message-Id: <20230607161523.2876433-1-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: GxC2BwDXhz4mrYBkJHoTAw--.4340S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Kw17Gw17ArW8ZrW5JFy8AFb_yoW8Aw4xpF 1DAFyrCr40gFyUZ3s2ka1vy34fWaykKrWvk34kuw1fJa43tr1vqF1vyr4akryrXrW8WryF qr4j9ryjka4jyrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUk0b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_Gr1j6F4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkF7I0En4kS14v26r4a6rW5MxAIw28IcxkI 7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxV Cjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY 6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6x AIw20EY4v20xvaj40_Zr0_Wr1UMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIE c7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjxUInYwUUUUU X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgABBF1jj4pc5gAAsG X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, MAY_BE_FORGED,PDS_RDNS_DYNAMIC_FP,RDNS_DYNAMIC,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768062024434655354?= X-GMAIL-MSGID: =?utf-8?q?1768062024434655354?= From: Roberto Sassu As the ramfs-based tmpfs uses ramfs_init_fs_context() for the init_fs_context method, which allocates fc->s_fs_info, use ramfs_kill_sb() to free it and avoid a memory leak. Cc: stable@vger.kernel.org # v5.4.x Fixes: f32356261d44 ("vfs: Convert ramfs, shmem, tmpfs, devtmpfs, rootfs to use the new mount API") Signed-off-by: Roberto Sassu --- fs/ramfs/inode.c | 2 +- include/linux/ramfs.h | 1 + mm/shmem.c | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c index 5ba580c7883..fef477c7810 100644 --- a/fs/ramfs/inode.c +++ b/fs/ramfs/inode.c @@ -278,7 +278,7 @@ int ramfs_init_fs_context(struct fs_context *fc) return 0; } -static void ramfs_kill_sb(struct super_block *sb) +void ramfs_kill_sb(struct super_block *sb) { kfree(sb->s_fs_info); kill_litter_super(sb); diff --git a/include/linux/ramfs.h b/include/linux/ramfs.h index 917528d102c..d506dc63dd4 100644 --- a/include/linux/ramfs.h +++ b/include/linux/ramfs.h @@ -7,6 +7,7 @@ struct inode *ramfs_get_inode(struct super_block *sb, const struct inode *dir, umode_t mode, dev_t dev); extern int ramfs_init_fs_context(struct fs_context *fc); +extern void ramfs_kill_sb(struct super_block *sb); #ifdef CONFIG_MMU static inline int diff --git a/mm/shmem.c b/mm/shmem.c index e40a08c5c6d..74abb97ea55 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -4196,7 +4196,7 @@ static struct file_system_type shmem_fs_type = { .name = "tmpfs", .init_fs_context = ramfs_init_fs_context, .parameters = ramfs_fs_parameters, - .kill_sb = kill_litter_super, + .kill_sb = ramfs_kill_sb, .fs_flags = FS_USERNS_MOUNT, };