Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2996510pxb; Mon, 18 Oct 2021 06:18:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxG71CQiZ9rTMgHVpRkMaG/EJMEXZvZsMiE5NknIVDLJC9ZiAWNz0R0BzXTFhrujatz138p X-Received: by 2002:a17:90a:4dc6:: with SMTP id r6mr47637362pjl.5.1634563085934; Mon, 18 Oct 2021 06:18:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634563085; cv=none; d=google.com; s=arc-20160816; b=jweU8xOC2FaT4isIdX7YzUhQ4ah9yiXRRCbdsXzTfFUN15hmbjw4spXQPBcuhimM62 MIYvKqPyIQ/VePtRMxNmsLXw3+WuTca/g3mM0Q5NfzUdBWKCZ0lGvxcSxvmL+3Y744NM YUdvz+wpQnbl2bbLw39lbLLJl2qG/Tm35ph+YaLI5z5PCLLj8BjcnRlEI7gN628CeQUu sH10/kECBXEcp+OBT+TI7XFCxhiyTgXnePGMvI7nwG+yHQL3GX//99mD5kAAha9evx6S aiHWZ4D+v1MubiGJeHal157ih/FgG5lAcnZ8HuHhNuT86+ZW0+eNWsRZ3swvMuIv5R8+ Fdig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=p+3RlkBhTqi95IUFYxC513I37UMY26Uu43SkKoW9cE8=; b=hhxtn6esl116+e/qAYRM/9AG+L/nhBd1qF6bfzz+1NCf0d1eQMsYMeKanRUacAX3Ew I5+1dzFIMlzElQvCWJ6hhoC6rdxoEIuP4iFJgK0dOF7WYLrgdYLhmu23PHUeChbcwmZN igeCylm3iLzq99vof/RwnzQmCN6OjvKUrHnWdOhf20KZTZboW6hiWPyruVATIA2wsUms veTV+CuhZLcxSyfwCYyiUhApRZJMjyuxg+S48cDAkX2Tc0RTaVsngjgyM+/BZwulw2p5 ULj436tDk+JWSAiw1Zp2uLf9VQztIO5yXrU/C292+2FPUk+if3R++pcCvrOjVhaWG65B rcHg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c19si20417452plo.375.2021.10.18.06.17.47; Mon, 18 Oct 2021 06:18:05 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231775AbhJRNSq (ORCPT + 99 others); Mon, 18 Oct 2021 09:18:46 -0400 Received: from mx22.baidu.com ([220.181.50.185]:59552 "EHLO baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231565AbhJRNSi (ORCPT ); Mon, 18 Oct 2021 09:18:38 -0400 Received: from BJHW-Mail-Ex05.internal.baidu.com (unknown [10.127.64.15]) by Forcepoint Email with ESMTPS id D707ED9772475B8D42DD; Mon, 18 Oct 2021 21:16:23 +0800 (CST) Received: from BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) by BJHW-Mail-Ex05.internal.baidu.com (10.127.64.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Mon, 18 Oct 2021 21:16:23 +0800 Received: from LAPTOP-UKSR4ENP.internal.baidu.com (172.31.63.8) by BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Mon, 18 Oct 2021 21:16:23 +0800 From: Cai Huoqing To: CC: "Rafael J. Wysocki" , Pavel Machek , "Len Brown" , , Subject: [PATCH] kernel: power: swap: Make use of vzalloc() and kzalloc() Date: Mon, 18 Oct 2021 21:16:21 +0800 Message-ID: <20211018131622.275-1-caihuoqing@baidu.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.31.63.8] X-ClientProxiedBy: BC-Mail-EX02.internal.baidu.com (172.31.51.42) To BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) X-Baidu-BdMsfe-DateCheck: 1_BJHW-Mail-Ex05_2021-10-18 21:16:23:876 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Replacing vmalloc()/memset() with vzalloc() and replacing kmalloc()/memset() with kzalloc() to simplify the code. Signed-off-by: Cai Huoqing --- kernel/power/swap.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/kernel/power/swap.c b/kernel/power/swap.c index 9ec418955556..5e8368fa348c 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c @@ -705,22 +705,19 @@ static int save_image_lzo(struct swap_map_handle *handle, goto out_clean; } - data = vmalloc(array_size(nr_threads, sizeof(*data))); + data = vzalloc(array_size(nr_threads, sizeof(*data))); if (!data) { pr_err("Failed to allocate LZO data\n"); ret = -ENOMEM; goto out_clean; } - for (thr = 0; thr < nr_threads; thr++) - memset(&data[thr], 0, offsetof(struct cmp_data, go)); - crc = kmalloc(sizeof(*crc), GFP_KERNEL); + crc = kzalloc(sizeof(*crc), GFP_KERNEL); if (!crc) { pr_err("Failed to allocate crc\n"); ret = -ENOMEM; goto out_clean; } - memset(crc, 0, offsetof(struct crc_data, go)); /* * Start the compression threads. @@ -1198,22 +1195,19 @@ static int load_image_lzo(struct swap_map_handle *handle, goto out_clean; } - data = vmalloc(array_size(nr_threads, sizeof(*data))); + data = vzalloc(array_size(nr_threads, sizeof(*data))); if (!data) { pr_err("Failed to allocate LZO data\n"); ret = -ENOMEM; goto out_clean; } - for (thr = 0; thr < nr_threads; thr++) - memset(&data[thr], 0, offsetof(struct dec_data, go)); - crc = kmalloc(sizeof(*crc), GFP_KERNEL); + crc = kzalloc(sizeof(*crc), GFP_KERNEL); if (!crc) { pr_err("Failed to allocate crc\n"); ret = -ENOMEM; goto out_clean; } - memset(crc, 0, offsetof(struct crc_data, go)); clean_pages_on_decompress = true; -- 2.25.1