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=-8.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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 3C85BC433E0 for ; Sat, 9 Jan 2021 17:40:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 664C923A01 for ; Sat, 9 Jan 2021 17:40:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 664C923A01 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 69A5C8D000A; Sat, 9 Jan 2021 12:40:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 64B478D0002; Sat, 9 Jan 2021 12:40:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5110A8D000A; Sat, 9 Jan 2021 12:40:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id 0857C8D0002 for ; Sat, 9 Jan 2021 12:40:40 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id BEB5C824556B for ; Sat, 9 Jan 2021 17:40:39 +0000 (UTC) X-FDA: 77686951398.28.loaf94_3114490274fd Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 9C1A66C11 for ; Sat, 9 Jan 2021 17:40:39 +0000 (UTC) X-HE-Tag: loaf94_3114490274fd X-Filterd-Recvd-Size: 2542 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Sat, 9 Jan 2021 17:40:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=wjy+oUPsZ8buL5dmm9rElHwglZCYmMO+xrU2yMPZN2E=; b=tRqJ5VUxjTQU9l+KsBws/ekINg rZfbXAMqdRe/BRVgV1tyMywHtunnRuVai9jN9irMHBUItzZViRDc1sTf2mcYudpwLx8wEXqSwvvdi rFb52P+lp7vEcZnNJlnL92pb+PgZaWfxBRJc17fMregodGGWeBQgRCjRGQmgcd55juhR7iOZQrMIs 3RvaF8Tym5FwD3MDEVdHn/fXixV7EVaEyN+hKB5DfY4x/z47uYGQqp/vlLqzDsjd8kAIB4bxw2Aty hyssByaCY1A82oBEzTgBg64ThwMGf/aPiRwIeUa38MJDk7gO4OLVpP/bfc8EC23B0iNEuK9e/AeQ9 gmBiDomQ==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1kyIDo-000ll2-7I; Sat, 09 Jan 2021 17:40:20 +0000 Date: Sat, 9 Jan 2021 17:40:16 +0000 From: Matthew Wilcox To: Miaohe Lin Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/swap_slots.c: Remove unnecessary NULL pointer check Message-ID: <20210109174016.GA35215@casper.infradead.org> References: <20210109080943.34832-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210109080943.34832-1-linmiaohe@huawei.com> 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: 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. > @@ -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.