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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56E65C433F5 for ; Fri, 4 Mar 2022 09:13:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E8ABA8D0003; Fri, 4 Mar 2022 04:13:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E3B4F8D0001; Fri, 4 Mar 2022 04:13:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2A658D0003; Fri, 4 Mar 2022 04:13:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0252.hostedemail.com [216.40.44.252]) by kanga.kvack.org (Postfix) with ESMTP id C67768D0001 for ; Fri, 4 Mar 2022 04:13:28 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 8CBE3181C34FE for ; Fri, 4 Mar 2022 09:13:28 +0000 (UTC) X-FDA: 79206140496.30.2FA88D9 Received: from out203-205-251-72.mail.qq.com (out203-205-251-72.mail.qq.com [203.205.251.72]) by imf03.hostedemail.com (Postfix) with ESMTP id 4C7342000F for ; Fri, 4 Mar 2022 09:13:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1646385204; bh=MFtNbgIXbDVYsyzREIkAA943SlaomrM4H8gjb3zCarY=; h=From:To:Cc:Subject:Date; b=YD6xkKqiFRjFLY04Ywe+GvPWb7hfRPTKwmuGan/Bxp3FHmO9tZiFJ2M4JzBNntFNm nvSE7ud0LJeYMXB6oMZrBVYQgU4mvPOXnaGLtw1gDGhmeBLiFjxF/CRXLtSak3fmRs fvmhxnjARIuOHhVWnrvL7VG0c5XtL7Empr55Ef/s= Received: from localhost.localdomain ([43.227.136.188]) by newxmesmtplogicsvrszc8.qq.com (NewEsmtp) with SMTP id 35411C58; Fri, 04 Mar 2022 17:13:20 +0800 X-QQ-mid: xmsmtpt1646385200tv9kqwm1e Message-ID: X-QQ-XMAILINFO: MW5hkHoBpWXyzmHxf9zmL9Onu1wMWH1/HEiW8k8MSqzddz/IqZsCKIA5qpo+8F 0n/Ho17vhLCvXrrDR/zRjg3R1YQbXsklAvqNqaOmCHVrU3zX+x0m0sZxcCpWSFgTUWtPA5srcym3 9IH5CiBUpkMzwxd02+cDmYufHAKFibztn8Uk4iLi8E2eo77kcQH7EzPeFTVBh7pSj4RhZvECIb9b +x/zQN7R3vzVUpCJh0nGAdeEwRUjhaHhF0Y1N3txGBPWrduJJOOFGQT/5kXp8evhulBrHXtkGhNz ELQzFQeh1TgNoYDQf8JDwztpOJp131M1FlfIWxmOwgEqWSMbyaecyRLySo+h+qDS821dgoBTyZfQ +yGAvhr7CJGGhfo1S5Cai+PW2V1ZlOn5n+1fp6v14nk141xs+d3PziH0Z6HWMYjRFrnuZz0zqJHR vei84zyzCdRj9+vIByTvBCBmj/b98EYnUNs0ogAc/1kvxsIC2zKavHFs3PnZQHgvw2p93f9RF4uW 82lnbwaWcGxyYWueQsOywu3LYp7zEs62Lw35Q0N3sV6lDvmdIIdEhUpymHuL8YvB/4nYzpj5aHDI qCYLcTTx8Jgyz4cX59LuNmnm1ytZx7hpr0x4JsPZpDi+aWJIOx4HagVlBc9H/SNMujegilF4/kkg H/jyzJefXR1LI5DTNsWGXN5dWvhTcHtpxee/gXC+oj06QmhCgNrNJEztxHufRi0tTS2LeIsxQ+OZ 5AnP3KWaHfxEvBX3IkeEMoLxgw7r9iVgV2WugeP4mbIXbxoQkBWC6u40RPQTBMBR/GQaTRTDCp2L SPBgYMn3PiA6VkyXs1cWiBzu+/9BsC1Gb/0QmFN2MngUq6TFr4tBF2E8wwYDMv2MwqeJjREHiWlL VD3vfzjmXHNZQKbF779gFd20nQ6+DuhOv4noq0qHSGk9rqDHo67qqw1vIQFMnNDgdntkejZ/BO From: xkernel.wang@foxmail.com To: glider@google.com, akpm@linux-foundation.org Cc: andreyknvl@gmail.com, elver@google.com, dvyukov@google.com, ryabinin.a.a@gmail.com, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Xiaoke Wang Subject: [PATCH] lib/test_meminit: add checks for the allocation functions Date: Fri, 4 Mar 2022 17:12:15 +0800 X-OQ-MSGID: <20220304091215.5063-1-xkernel.wang@foxmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4C7342000F X-Stat-Signature: bxt7gh1k4nxjimukun81drsydgpj1b7s Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=foxmail.com header.s=s201512 header.b=YD6xkKqi; spf=pass (imf03.hostedemail.com: domain of xkernel.wang@foxmail.com designates 203.205.251.72 as permitted sender) smtp.mailfrom=xkernel.wang@foxmail.com; dmarc=pass (policy=none) header.from=foxmail.com X-HE-Tag: 1646385206-347213 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000022, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Xiaoke Wang alloc_pages(), kmalloc() and vmalloc() are all memory allocation functions which can return NULL when some internal memory failures happen. So it is better to check the return of them to catch the failure in time for better test them. Signed-off-by: Xiaoke Wang --- lib/test_meminit.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/test_meminit.c b/lib/test_meminit.c index e4f706a..2f4c4bc 100644 --- a/lib/test_meminit.c +++ b/lib/test_meminit.c @@ -67,17 +67,24 @@ static int __init do_alloc_pages_order(int order, int= *total_failures) size_t size =3D PAGE_SIZE << order; =20 page =3D alloc_pages(GFP_KERNEL, order); + if (!page) + goto err; buf =3D page_address(page); fill_with_garbage(buf, size); __free_pages(page, order); =20 page =3D alloc_pages(GFP_KERNEL, order); + if (!page) + goto err; buf =3D page_address(page); if (count_nonzero_bytes(buf, size)) (*total_failures)++; fill_with_garbage(buf, size); __free_pages(page, order); return 1; +err: + (*total_failures)++; + return 1; } =20 /* Test the page allocator by calling alloc_pages with different orders.= */ @@ -100,15 +107,22 @@ static int __init do_kmalloc_size(size_t size, int = *total_failures) void *buf; =20 buf =3D kmalloc(size, GFP_KERNEL); + if (!buf) + goto err; fill_with_garbage(buf, size); kfree(buf); =20 buf =3D kmalloc(size, GFP_KERNEL); + if (!buf) + goto err; if (count_nonzero_bytes(buf, size)) (*total_failures)++; fill_with_garbage(buf, size); kfree(buf); return 1; +err: + (*total_failures)++; + return 1; } =20 /* Test vmalloc() with given parameters. */ @@ -117,15 +131,22 @@ static int __init do_vmalloc_size(size_t size, int = *total_failures) void *buf; =20 buf =3D vmalloc(size); + if (!buf) + goto err; fill_with_garbage(buf, size); vfree(buf); =20 buf =3D vmalloc(size); + if (!buf) + goto err; if (count_nonzero_bytes(buf, size)) (*total_failures)++; fill_with_garbage(buf, size); vfree(buf); return 1; +err: + (*total_failures)++; + return 1; } =20 /* Test kmalloc()/vmalloc() by allocating objects of different sizes. */ --=20