Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2070676pxa; Fri, 7 Aug 2020 02:16:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzaH+gkkXOTTAvs5HHRJUkOhQQDqCn+ap6BY34psKXwO2Oe/1EA2iJJmoIsN08oK2doKGKL X-Received: by 2002:aa7:d5d0:: with SMTP id d16mr7748555eds.212.1596791773636; Fri, 07 Aug 2020 02:16:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596791773; cv=none; d=google.com; s=arc-20160816; b=ZMQuHuI6JcbP8j+D+R1/ioDcNmTeE1eGdD6Gl+C7aYU1DK603d9kqLCKnhKdQ/Fg9z vi9j8nIWdAa3Q9XxwylxDvLzbzRkeoKlQDWyGhiddAmJ6zb2djuvQeAsWwOIIjx86kdj qOTsWmf+Nzo0YiCrdbSDiL6fhF6TM17Ep8mmyL1GDalEfQonwezwA2ZkNsz9rhDxf8rr Uif4GtkO2a6dkOAva7JUvfsPeHYTqFARm2ePUD21sgwxCw+bFJk2jn1e7h4wA1wIEmX+ Qhl1F30Jb0680nSQrF3vRDSW8XItwmAgcX6cUJTo4RVmjM5jw+XSvP4q60l8liXhYcjG ZPLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=T9BYCikv9wfN/hBHSqIMlr0b5lxQPtEon6+uZL/4odI=; b=k2bbX5hbVmHAV0ULohznWac0vSKXivGCfvNcv+vhlyOOSUAUcLFACjow/nXses/8VI DvTf0n/ZCv81S5rIfr8xA5HbesvX5Zk2IohWFT7dI8KJkFjox733eAx5ki8sYl1/4Xft ZBQPQzf/g81kFxxSBvreJLMK4d7jGamRFRe+xLFI1vlbnF3k+Gbkb86TTj8XCiAkGz53 J2x3VSvVZD6EKMsdMhLoIXxICS42bn/uFO547APQeiyUGUBCiXfa8j6fAcpXg9rXjjHp 81NoY/xPJ15V0L3GL3x0NyMvZhMAofWsTM8gESC/TU/Zp+C/l3nS4WQbMJPg0wH4vWUK IXTQ== 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 m4si4829078edr.500.2020.08.07.02.15.50; Fri, 07 Aug 2020 02:16:13 -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 S1727079AbgHGJOb (ORCPT + 99 others); Fri, 7 Aug 2020 05:14:31 -0400 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:35184 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726979AbgHGJOb (ORCPT ); Fri, 7 Aug 2020 05:14:31 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R971e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01358;MF=richard.weiyang@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0U5.Byex_1596791596; Received: from localhost(mailfrom:richard.weiyang@linux.alibaba.com fp:SMTPD_---0U5.Byex_1596791596) by smtp.aliyun-inc.com(127.0.0.1); Fri, 07 Aug 2020 17:13:16 +0800 From: Wei Yang To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wei Yang Subject: [PATCH 02/10] mm/hugetlb: make sure to get NULL when list is empty Date: Fri, 7 Aug 2020 17:12:43 +0800 Message-Id: <20200807091251.12129-3-richard.weiyang@linux.alibaba.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20200807091251.12129-1-richard.weiyang@linux.alibaba.com> References: <20200807091251.12129-1-richard.weiyang@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); 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); list_del(&nrg->link); -- 2.20.1 (Apple Git-117)