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 X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F2CBC2D0A3 for ; Mon, 9 Nov 2020 11:47:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A95D020789 for ; Mon, 9 Nov 2020 11:47:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729565AbgKILr1 (ORCPT ); Mon, 9 Nov 2020 06:47:27 -0500 Received: from out30-57.freemail.mail.aliyun.com ([115.124.30.57]:36524 "EHLO out30-57.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727774AbgKILr0 (ORCPT ); Mon, 9 Nov 2020 06:47:26 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R931e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0UEjNPeQ_1604922442; Received: from aliy8.localdomain(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0UEjNPeQ_1604922442) by smtp.aliyun-inc.com(127.0.0.1); Mon, 09 Nov 2020 19:47:22 +0800 From: Alex Shi To: linmiaohe@huawei.com, akpm@linux-foundation.org Cc: "Darrick J. Wong" , Hugh Dickins , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [REF PATCH] mm/swap: fix swapon failure Date: Mon, 9 Nov 2020 19:47:16 +0800 Message-Id: <1604922436-16597-1-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org One of my VM guest has a swapon issue: root #swapon -v -f /swap1 swapon /swap1 swapon: /swap1: found swap signature: version 1, page-size 4, same byte order swapon: /swap1: pagesize=4096, swapsize=1607467008, devsize=1607467008 swapon: /swap1: swapon failed: Invalid argument and bisection report commit 822bca52ee7e "mm/swapfile.c: fix potential memory leak in sys_swapon" cause the trouble. Go through the context I found the exit_swap_address_space(p->type) shouldn't be used in good result path. So just move it to error path. Fixes: 822bca52ee7e ("mm/swapfile.c: fix potential memory leak in sys_swapon") Signed-off-by: Alex Shi Cc: Andrew Morton Cc: "Darrick J. Wong" Cc: Miaohe Lin Cc: Hugh Dickins Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- mm/swapfile.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index c8966b8fc6ac..1ac1f737fee3 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3339,7 +3339,8 @@ static bool swap_discardable(struct swap_info_struct *si) error = inode_drain_writes(inode); if (error) { inode->i_flags &= ~S_SWAPFILE; - goto free_swap_address_space; + exit_swap_address_space(p->type); + goto bad_swap_unlock_inode; } mutex_lock(&swapon_mutex); @@ -3364,8 +3365,6 @@ static bool swap_discardable(struct swap_info_struct *si) error = 0; goto out; -free_swap_address_space: - exit_swap_address_space(p->type); bad_swap_unlock_inode: inode_unlock(inode); bad_swap: -- 1.8.3.1