Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2276364pxa; Fri, 7 Aug 2020 07:29:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxQYtDekSoimWXMQA0Ft8AMnmk7Zdx47ROykH14NrGXZroMRD9jn46DtxKlvyg3Sp3DxpD X-Received: by 2002:a17:906:858:: with SMTP id f24mr9421204ejd.543.1596810548862; Fri, 07 Aug 2020 07:29:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596810548; cv=none; d=google.com; s=arc-20160816; b=qr2YbonpLblZ7ivuT0A8xcWy4BAhuleuRpheZnMWdofEr9rgjeYCJdKTSEC8DxxS/v kn5Okw0iVrbTh1wsQm6+/jZNoxqDkAAi/SpCgOyGkL+mzYaRVWtDLqqr69XYsPuxgReP QlRrjt/lK3AqqTf5k4Ygu1IAyBbXdatGv7b3x2JAlc5k/a9GHfmprO3cYjb3o894T36v OK3/FePHBH1ISFo6BVZ8k//C9y67LiMeFbpJRYaKAiO6LkzFkPljf4M5YphKnaCA+U6b T03vEyWhoW6xAe6s8YQ0Zu/26w7ZAelZEwqfXHIlNf1EuEb8bGcinwsLG79OWFbiwTui yqYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:reply-to:message-id:subject:cc:to:from:date; bh=LYTyuYQS0gQrjkeMbVOHccYEBRrYFrhVGK+LYqhwSsQ=; b=BLCbIP556Vq1TDuqCrF7fyZ7kKqQL+H5cgMYG18Tx7KSgYRCZLaj77woQ2FqMNQBnR ytwIw8FTDIP21TyYZx77P40gprUwoUmWayrDxTJu1KsZ/5QoL/G46R83jsiaSntc8JuY wr/4lEaRxYpKWFQEzSwr5txepWGdzkAhqIWz5eJLZPPsFTr7NmqfsFPN3JIbNeauDjLY hw3QGrFLMS3aLqR8ysgQ60FUF+9ZXRFtXrEEmOlZuWuoUSk8m6axfl1mBtfegV0scGNA EDwU4PTU5c6gU5acoZu/NwO1fs73eyVZiu+sk7amYLVpUslNNVDPvkwxC64zNOcfU/Zy Lhig== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fi14si5461919ejb.628.2020.08.07.07.28.44; Fri, 07 Aug 2020 07:29:08 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726224AbgHGO2G (ORCPT + 99 others); Fri, 7 Aug 2020 10:28:06 -0400 Received: from out30-44.freemail.mail.aliyun.com ([115.124.30.44]:33169 "EHLO out30-44.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725815AbgHGO2G (ORCPT ); Fri, 7 Aug 2020 10:28:06 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01355;MF=richard.weiyang@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0U50nlUT_1596810480; Received: from localhost(mailfrom:richard.weiyang@linux.alibaba.com fp:SMTPD_---0U50nlUT_1596810480) by smtp.aliyun-inc.com(127.0.0.1); Fri, 07 Aug 2020 22:28:00 +0800 Date: Fri, 7 Aug 2020 22:28:00 +0800 From: Wei Yang To: Baoquan He Cc: Wei Yang , 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: <20200807142800.GA14692@L-31X9LVDL-1304.local> Reply-To: Wei Yang References: <20200807091251.12129-1-richard.weiyang@linux.alibaba.com> <20200807091251.12129-3-richard.weiyang@linux.alibaba.com> <20200807124951.GM14854@MiWiFi-R3L-srv> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200807124951.GM14854@MiWiFi-R3L-srv> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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()? >> list_del(&nrg->link); >> >> -- >> 2.20.1 (Apple Git-117) >> >> -- Wei Yang Help you, Help me