Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3949331pxa; Sun, 9 Aug 2020 17:59:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvloaFBAyOsXC7cnxlBQe+2M/dyu837qXTzWc0nqPtUSI5/gjv+z/WKt46p6rViMk9GFp+ X-Received: by 2002:a17:906:4f0f:: with SMTP id t15mr18881919eju.337.1597021160244; Sun, 09 Aug 2020 17:59:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597021160; cv=none; d=google.com; s=arc-20160816; b=cYs4GyuM5ydofCVQV7aWT9Ma6oSJutoYFztYdOV/RzjWwEbEAnIVff5eS1/SvGbRQK 35Vo29++pFABnLBn53g6iJ3TRcFCPoDgx1UX36aPsL9CHlp0GsWUpu98JufJUeSztya4 geyPPYfUl5I2GeGtniAclsiDpqZq38MfK8XdYJLrSdtcGf9uYeUzWVof4mgKOdJWTR1J 5diZDgL0ckr25TR7svUhTMvCJh1p0vHRC+rTOT4TY5GZH+yiWJI+7XxIeDs2kNI/uOC3 TCLGkA9b53jnKoJ4FmKhMQnaug9HQmm0ftYN6kwSx1AoCivOOI6HebUuPhsT9jIyK0+2 0AmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=kCTZ+EBI9FQTeiqg16DaYSGV21VlDbKz4raMpmUYwf0=; b=yfAu8aEQ4G2sJ2MBTgNuJb7YUf9JviE/YmjcJyQO986IEB2ekISVUNQV/hazzKcpne AdS4kE5KYHmXju/7YIo7IUpBJiLVZDPihF/t1eGH4p382zgv+0sG2ao31C3kApl1ncQl LhbJITpJB7BWiLPas5MCeunPUdfTNWo2dyxpBBuoIzc9YXVXPOnyKZhYECeEnnpUPrWA maEl4YZ5MScpJS10JRNeH97dx2Dg1LMW5pO92Fe4uU5OYgBpTC1VOc5ml35duSnDcQmC w2qnUgWKKdMVI1QUEDL7keUaWThbWZUlBRyPuLLdwXtYrCvJVZJ1RXf2/U6kFKo0+JYt QSTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DS0d7uCE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d30si12865099edn.97.2020.08.09.17.58.55; Sun, 09 Aug 2020 17:59:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DS0d7uCE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726398AbgHJA6F (ORCPT + 99 others); Sun, 9 Aug 2020 20:58:05 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:47103 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726335AbgHJA6F (ORCPT ); Sun, 9 Aug 2020 20:58:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597021083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kCTZ+EBI9FQTeiqg16DaYSGV21VlDbKz4raMpmUYwf0=; b=DS0d7uCE8gccNK1o87uzNlydCi9S/VbUN7DeTcK+CrhG8nRgAI0dFmFLB4J/ivEXWyuWre lcIxM59INJtR1CtZSR69XqXhcNRpaF1WYFp0dQpJm+Rg2A7xMsyTI9CteoKOvxMyQP5GMP MsuE3JCyToREwUU9s4rQV+IZDg6JVmA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-149-DAftb58wORqGISqKS68kzg-1; Sun, 09 Aug 2020 20:58:01 -0400 X-MC-Unique: DAftb58wORqGISqKS68kzg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5620C1DE1; Mon, 10 Aug 2020 00:58:00 +0000 (UTC) Received: from localhost (ovpn-12-116.pek2.redhat.com [10.72.12.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 56E9569318; Mon, 10 Aug 2020 00:57:58 +0000 (UTC) Date: Mon, 10 Aug 2020 08:57:55 +0800 From: Baoquan He To: Wei Yang Cc: mike.kravetz@oracle.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 02/10] mm/hugetlb: make sure to get NULL when list is empty Message-ID: <20200810005755.GU14854@MiWiFi-R3L-srv> References: <20200807091251.12129-1-richard.weiyang@linux.alibaba.com> <20200807091251.12129-3-richard.weiyang@linux.alibaba.com> <20200807124951.GM14854@MiWiFi-R3L-srv> <20200807142800.GA14692@L-31X9LVDL-1304.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200807142800.GA14692@L-31X9LVDL-1304.local> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/07/20 at 10:28pm, Wei Yang wrote: > On Fri, Aug 07, 2020 at 08:49:51PM +0800, Baoquan He wrote: > >On 08/07/20 at 05:12pm, Wei Yang wrote: > >> list_first_entry() may not return NULL even when the list is empty. > >> > >> Let's make sure the behavior by using list_first_entry_or_null(), > >> otherwise it would corrupt the list. > >> > >> Signed-off-by: Wei Yang > >> --- > >> mm/hugetlb.c | 3 ++- > >> 1 file changed, 2 insertions(+), 1 deletion(-) > >> > >> diff --git a/mm/hugetlb.c b/mm/hugetlb.c > >> index 62ec74f6d03f..0a2f3851b828 100644 > >> --- a/mm/hugetlb.c > >> +++ b/mm/hugetlb.c > >> @@ -237,7 +237,8 @@ get_file_region_entry_from_cache(struct resv_map *resv, long from, long to) > >> VM_BUG_ON(resv->region_cache_count <= 0); > > > > > >We have had above line, is it possible to be NULL from list_first_entry? > > > >> > >> resv->region_cache_count--; > >> - nrg = list_first_entry(&resv->region_cache, struct file_region, link); > >> + nrg = list_first_entry_or_null(&resv->region_cache, > >> + struct file_region, link); > >> VM_BUG_ON(!nrg); > > Or we can remove this VM_BUG_ON()? Yeah, it's fine to me. > > >> list_del(&nrg->link); > >> > >> -- > >> 2.20.1 (Apple Git-117) > >> > >> > > -- > Wei Yang > Help you, Help me >