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=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 42CD4C433DB for ; Thu, 14 Jan 2021 02:35:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B3366235FA for ; Thu, 14 Jan 2021 02:35:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B3366235FA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C55DA6B01AE; Wed, 13 Jan 2021 21:35:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C07B06B01B1; Wed, 13 Jan 2021 21:35:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B1C606B01B3; Wed, 13 Jan 2021 21:35:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0054.hostedemail.com [216.40.44.54]) by kanga.kvack.org (Postfix) with ESMTP id 9971B6B01AE for ; Wed, 13 Jan 2021 21:35:03 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 62A3C3633 for ; Thu, 14 Jan 2021 02:35:03 +0000 (UTC) X-FDA: 77702813286.13.team62_4716b1e27523 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 45A0E18140B60 for ; Thu, 14 Jan 2021 02:35:03 +0000 (UTC) X-HE-Tag: team62_4716b1e27523 X-Filterd-Recvd-Size: 2547 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Thu, 14 Jan 2021 02:35:02 +0000 (UTC) Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DGSzm4Pmdzl4qj; Thu, 14 Jan 2021 10:33:40 +0800 (CST) Received: from [10.174.176.197] (10.174.176.197) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.498.0; Thu, 14 Jan 2021 10:34:57 +0800 Subject: Re: [PATCH] mm/swap_slots.c: Remove unnecessary NULL pointer check To: Matthew Wilcox CC: , , References: <20210109080943.34832-1-linmiaohe@huawei.com> <20210109174016.GA35215@casper.infradead.org> From: Miaohe Lin Message-ID: <404e6c17-dd1f-84f9-86ca-8a39cbdbffd1@huawei.com> Date: Thu, 14 Jan 2021 10:34:57 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20210109174016.GA35215@casper.infradead.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.176.197] X-CFilter-Loop: Reflected X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi: On 2021/1/10 1:40, Matthew Wilcox wrote: > On Sat, Jan 09, 2021 at 03:09:43AM -0500, Miaohe Lin wrote: >> The cache->slots and cache->slots_ret is already checked before we try to >> drain it. And kvfree can handle the NULL pointer itself. So remove the >> NULL pointer check here. > >> @@ -178,7 +178,7 @@ static void drain_slots_cache_cpu(unsigned int cpu, unsigned int type, >> swapcache_free_entries(cache->slots + cache->cur, cache->nr); >> cache->cur = 0; >> cache->nr = 0; >> - if (free_slots && cache->slots) { >> + if (free_slots) { > > Prove that swapcache_free_entries() doesn't change cache->slots. > Yeh... I see. I thought swap_slots_cache_mutex could totally guard against this. >> @@ -188,13 +188,12 @@ static void drain_slots_cache_cpu(unsigned int cpu, unsigned int type, >> spin_lock_irq(&cache->free_lock); >> swapcache_free_entries(cache->slots_ret, cache->n_ret); >> cache->n_ret = 0; >> - if (free_slots && cache->slots_ret) { >> + if (free_slots) { > > ... or ->slots_ret > >> - if (slots) >> - kvfree(slots); >> + kvfree(slots); > > This is fine. > . > Many thanks for your review and reply!