From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1BAAEE77180 for ; Thu, 12 Dec 2024 13:35:28 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Y8D4F62Wzz3cBT for ; Fri, 13 Dec 2024 00:35:25 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=115.124.30.133 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1734010521; cv=none; b=kdPoL4rcGO7/9CywVm7jHzUcm0W7YydXpOsj7/fQqGiH2+MuTD9MF6JlMIKpyZWbeCSfZxwC4Zn6rF/ZCRtx8w6GzQAqBgHeUepMXnR/xSioK9OK8WxWhUGguFKMoO/i4s5Fw+eo38z1XCtek3Pk9fi5cvh+b52ikZ3W3AdHZHmmj1+5h/7RxkeX5l/w89Fwp64FupQfWSeD9hiOCNDmLBkvzewhtklI3a9OoF2JairVBXieXazqIw6KBX2kPA17Tca9/bs+WO9m3LiHYwUryPm/V9RULJd/zBpJmv5p2D8WD0dXyNw+MNwY7y325YuqFtjPkgaSRM+/BTwFlVE3ww== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1734010521; c=relaxed/relaxed; bh=Bep53u066GuA/RqqrsrzhZPJEa3VMPrE3kZ/DxaEDko=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FAIG6ptFDSlSFcHmZfX83hicngckXgwI9McYWTOpHd/9FKC3BpW/NmIZ7cQxZKpxdZxKccM5CD8sw6CpONZIgvGBhzHt71hXuQQOi9PdYvcFjKtEVVlYjHq3jpzXI2SDyORKkOAbAjkc34PPLntjCXZaVOIovEJ2drT/Xa//vmEuJHpmBL/dmABgoDyvaDH5z2znZRZ1ba1dx3X3g3/s7CHEO/8LoFp5LeokJPlyJkZYAeV+BIEFyWTG9HDVyvgPI2Qn0f20ns953gcWlIMaGC1ab8+4s+wJIGSSfBBOmIxXeQBnCG9apAA6GpAZNe8wBAuw9Xj97XzrDFOUNtx+hA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; dkim=pass (1024-bit key; unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=ro4D/85n; dkim-atps=neutral; spf=pass (client-ip=115.124.30.133; helo=out30-133.freemail.mail.aliyun.com; envelope-from=hsiangkao@linux.alibaba.com; receiver=lists.ozlabs.org) smtp.mailfrom=linux.alibaba.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=ro4D/85n; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.alibaba.com (client-ip=115.124.30.133; helo=out30-133.freemail.mail.aliyun.com; envelope-from=hsiangkao@linux.alibaba.com; receiver=lists.ozlabs.org) Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Y8D4703MXz30WD for ; Fri, 13 Dec 2024 00:35:17 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1734010513; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Bep53u066GuA/RqqrsrzhZPJEa3VMPrE3kZ/DxaEDko=; b=ro4D/85npPupCh4ig7cKRCaBahSSgEeMnCL+hmj9u+Aaq0pY4yuQC2DQ8gkY04flNlJiYvEG7w9uxse3MMJT4yHSiN93IyukND8rtXB7I7LUtkh+9ZyDDO2IKpWB7cF7qcJzzzjlKtqjxOg4JL7+Ix4lIjhYt90BenGThoi9iB0= Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0WLLvJn5_1734010505 cluster:ay36) by smtp.aliyun-inc.com; Thu, 12 Dec 2024 21:35:10 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Subject: [PATCH 1/4] erofs: add erofs_sb_free() helper Date: Thu, 12 Dec 2024 21:35:01 +0800 Message-ID: <20241212133504.2047178-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: linux-erofs@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development of Linux EROFS file system List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gao Xiang , LKML Errors-To: linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Sender: "Linux-erofs" Unify the common parts of erofs_fc_free() and erofs_kill_sb() as erofs_sb_free(). Thus, fput() in erofs_fc_get_tree() is no longer needed, too. Signed-off-by: Gao Xiang --- fs/erofs/super.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index c235a8e4315e..1ce5ca11d32b 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -703,16 +703,19 @@ static int erofs_fc_get_tree(struct fs_context *fc) GET_TREE_BDEV_QUIET_LOOKUP : 0); #ifdef CONFIG_EROFS_FS_BACKED_BY_FILE if (ret == -ENOTBLK) { + struct file *file; + if (!fc->source) return invalf(fc, "No source specified"); - sbi->fdev = filp_open(fc->source, O_RDONLY | O_LARGEFILE, 0); - if (IS_ERR(sbi->fdev)) - return PTR_ERR(sbi->fdev); + + file = filp_open(fc->source, O_RDONLY | O_LARGEFILE, 0); + if (IS_ERR(file)) + return PTR_ERR(file); + sbi->fdev = file; if (S_ISREG(file_inode(sbi->fdev)->i_mode) && sbi->fdev->f_mapping->a_ops->read_folio) return get_tree_nodev(fc, erofs_fc_fill_super); - fput(sbi->fdev); } #endif return ret; @@ -763,19 +766,24 @@ static void erofs_free_dev_context(struct erofs_dev_context *devs) kfree(devs); } -static void erofs_fc_free(struct fs_context *fc) +static void erofs_sb_free(struct erofs_sb_info *sbi) { - struct erofs_sb_info *sbi = fc->s_fs_info; - - if (!sbi) - return; - erofs_free_dev_context(sbi->devs); kfree(sbi->fsid); kfree(sbi->domain_id); + if (sbi->fdev) + fput(sbi->fdev); kfree(sbi); } +static void erofs_fc_free(struct fs_context *fc) +{ + struct erofs_sb_info *sbi = fc->s_fs_info; + + if (sbi) /* free here if an error occurs before transferring to sb */ + erofs_sb_free(sbi); +} + static const struct fs_context_operations erofs_context_ops = { .parse_param = erofs_fc_parse_param, .get_tree = erofs_fc_get_tree, @@ -813,15 +821,9 @@ static void erofs_kill_sb(struct super_block *sb) kill_anon_super(sb); else kill_block_super(sb); - - erofs_free_dev_context(sbi->devs); fs_put_dax(sbi->dax_dev, NULL); erofs_fscache_unregister_fs(sb); - kfree(sbi->fsid); - kfree(sbi->domain_id); - if (sbi->fdev) - fput(sbi->fdev); - kfree(sbi); + erofs_sb_free(sbi); sb->s_fs_info = NULL; } -- 2.43.5 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73B6A2144A8 for ; Thu, 12 Dec 2024 13:35:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010522; cv=none; b=d61MfAJV7jstzWRlFrCcB0SOzGXBDmvAXUp5hjZqkooEj6/pqZ0HHPr7q2R8jHUq5KobzllhXC+pMxyQ5ln3MH5TRRM8jHct4rEI1/WfeN6PjCmKEwcFZCqrhb+yukIz29Avaz5PS7QmSL+2hZYwxal18Cb/jgtnpS4MJf9CZ2U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734010522; c=relaxed/simple; bh=mQELmEZTY+F/nXn85f1TGczJdjITkLw9mx5HUBS1N70=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=NIIwY94Ws5VpeMdgpnRbOPouQ3sRXf2Kx+juhWr1lU1FDAsqXN4sNefIjwzd45i7hQJWMZo3VGr0eNT37XrXK1EEjsSM17ik38aVO2xQYvekJjUSJHc92sbJ+n3+z6b+g4Cv9Sjd2VqSGAjfXgd0LOGrFoW7ZkVQiYcOCQmq75k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=X1trIlOb; arc=none smtp.client-ip=115.124.30.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="X1trIlOb" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1734010510; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Bep53u066GuA/RqqrsrzhZPJEa3VMPrE3kZ/DxaEDko=; b=X1trIlOboc4SQ/A5T/Z9nw46qFyHfsooAjzgWBmMcOEOuuk52NEY+8fHtRLv7+ZXCwwjHy4Hz9RnZEjSst6MKiJfN7HQarAMgfbWip0pIWzlqmnFnqnsk+3jLX8kKePfFi1FjRf4SPmZDMLgDLmC1XXke8c8YwWM8sV3T6pVH6Y= Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0WLLvJn5_1734010505 cluster:ay36) by smtp.aliyun-inc.com; Thu, 12 Dec 2024 21:35:10 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Cc: LKML , Gao Xiang Subject: [PATCH 1/4] erofs: add erofs_sb_free() helper Date: Thu, 12 Dec 2024 21:35:01 +0800 Message-ID: <20241212133504.2047178-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Unify the common parts of erofs_fc_free() and erofs_kill_sb() as erofs_sb_free(). Thus, fput() in erofs_fc_get_tree() is no longer needed, too. Signed-off-by: Gao Xiang --- fs/erofs/super.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index c235a8e4315e..1ce5ca11d32b 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -703,16 +703,19 @@ static int erofs_fc_get_tree(struct fs_context *fc) GET_TREE_BDEV_QUIET_LOOKUP : 0); #ifdef CONFIG_EROFS_FS_BACKED_BY_FILE if (ret == -ENOTBLK) { + struct file *file; + if (!fc->source) return invalf(fc, "No source specified"); - sbi->fdev = filp_open(fc->source, O_RDONLY | O_LARGEFILE, 0); - if (IS_ERR(sbi->fdev)) - return PTR_ERR(sbi->fdev); + + file = filp_open(fc->source, O_RDONLY | O_LARGEFILE, 0); + if (IS_ERR(file)) + return PTR_ERR(file); + sbi->fdev = file; if (S_ISREG(file_inode(sbi->fdev)->i_mode) && sbi->fdev->f_mapping->a_ops->read_folio) return get_tree_nodev(fc, erofs_fc_fill_super); - fput(sbi->fdev); } #endif return ret; @@ -763,19 +766,24 @@ static void erofs_free_dev_context(struct erofs_dev_context *devs) kfree(devs); } -static void erofs_fc_free(struct fs_context *fc) +static void erofs_sb_free(struct erofs_sb_info *sbi) { - struct erofs_sb_info *sbi = fc->s_fs_info; - - if (!sbi) - return; - erofs_free_dev_context(sbi->devs); kfree(sbi->fsid); kfree(sbi->domain_id); + if (sbi->fdev) + fput(sbi->fdev); kfree(sbi); } +static void erofs_fc_free(struct fs_context *fc) +{ + struct erofs_sb_info *sbi = fc->s_fs_info; + + if (sbi) /* free here if an error occurs before transferring to sb */ + erofs_sb_free(sbi); +} + static const struct fs_context_operations erofs_context_ops = { .parse_param = erofs_fc_parse_param, .get_tree = erofs_fc_get_tree, @@ -813,15 +821,9 @@ static void erofs_kill_sb(struct super_block *sb) kill_anon_super(sb); else kill_block_super(sb); - - erofs_free_dev_context(sbi->devs); fs_put_dax(sbi->dax_dev, NULL); erofs_fscache_unregister_fs(sb); - kfree(sbi->fsid); - kfree(sbi->domain_id); - if (sbi->fdev) - fput(sbi->fdev); - kfree(sbi); + erofs_sb_free(sbi); sb->s_fs_info = NULL; } -- 2.43.5