Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp508426pxb; Thu, 21 Oct 2021 04:10:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynkY7yUV54xZhZ3Xk23tiM7VeUSVUz5jesfEAaOQR1t9biIPnNzZsZ14JK4v4IVbC//Y+k X-Received: by 2002:a63:ef58:: with SMTP id c24mr3842559pgk.299.1634814609973; Thu, 21 Oct 2021 04:10:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634814609; cv=none; d=google.com; s=arc-20160816; b=p0wT5wOwNmxTWHdM/gfkOgvMZyx8luVeM7fjo2tWoL8QcR5MVhaSzPoUmzQc8gJ7VP 3TPaG6Hct/RKVelBsE56I8w863NYNYAiktupeJtAFeRf+kF8ANwzHPGz44dV529lRV1i ZjJXBW8ksAtebEfVeCatNf94SZmXEOj3/zySIqMEqs2K7AKUE2ryARnZe8uxpp3q/d+h WrFBqM8rXdRjnVOdVwcybDpHIolRrvc5BKAf84ynzwBOCT4VPdm5c5FPjqZwPSd/b4yi OwRA+QsVxSSLkNa1VR6zsfdedp3VjHPJ0Um29nGLfjpF/jQ2d5zGhyekPgIzYTQU2UQ+ FkmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=q001XmKkxSRKN0SshPrgK3z3VWsueEgGrFxooyBiLww=; b=VMsY9fh8V+eM4/c8Lbk14cW3hELl6DhaFnYtdufZPFbb6eALNaqdBaPO7JVY57+w11 0m5jKYSMVYSXIg7xfkMnCwxnaqZY7nREbV88JtHkdVjFAw2bCtWhqr5kC3tUJHcnDnSp VBV0hA9s21BUHT6n+YaYgFn8k+wgwyrJ9XQc1mBNYwM0djzZ4Z5p8BbZwiLAOzrvlyYa hAGS9WE2qxDynmCPWq3cBAkOasspPCnXpFeT7Lure+VCOuYLgageKLtCf4nyY9w86Fhv ScnM0045GPNc+drraInUvvtC20b+QlL4F3EioqkRjXBiQwtn8djC9iputIvoidAk+DvD MtBw== 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v11si6608006plp.339.2021.10.21.04.09.57; Thu, 21 Oct 2021 04:10:09 -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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230340AbhJULIx (ORCPT + 99 others); Thu, 21 Oct 2021 07:08:53 -0400 Received: from mail-oo1-f47.google.com ([209.85.161.47]:46997 "EHLO mail-oo1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230329AbhJULIv (ORCPT ); Thu, 21 Oct 2021 07:08:51 -0400 Received: by mail-oo1-f47.google.com with SMTP id c29-20020a4ad21d000000b002b6cf3f9aceso7609oos.13; Thu, 21 Oct 2021 04:06:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=q001XmKkxSRKN0SshPrgK3z3VWsueEgGrFxooyBiLww=; b=dZjdDv97jHQ9n7Wd6EQ9yKKgPh5s3LrwNl+nZjS8dfI6RrHQzuq54g/Fe6jhbNrNDa yZQKUAVnrACoXrz6WoHWN/7wdRGTZ6Hj9UdUIb/DiMC0ljXxWc9iJ1F9cCdNkJBOVchI vbsBY4YhRwvGEU84dGdyDMIb9A3IoVeXifKrCG+j7FOXdLokMN9dNsd4ZffIv0vcDJ+9 aeXoeN6rCZYBNIfD2sYcbZyh44WMD1oNX8+32pOhtcRiCkzdQlV9OiVScDQSYy+sY1uz 9YLVdMkRYzn+zQQSBrlgNa+07DSei45VEQt7t+WSH8dctNX6wQ2Hv7Y0fCtyFnmSAuSg y6xQ== X-Gm-Message-State: AOAM530lNfqoUIVfNfw4xqLytjqgYdYltAeOmC/Y9EWRxr798fMq1ncZ 0EDsiF9ptBN5i/PNBJWdGhS4RJ98L7VGsH4Fiiu0mzNE X-Received: by 2002:a4a:eb12:: with SMTP id f18mr3752150ooj.91.1634814395699; Thu, 21 Oct 2021 04:06:35 -0700 (PDT) MIME-Version: 1.0 References: <20211018131622.275-1-caihuoqing@baidu.com> In-Reply-To: <20211018131622.275-1-caihuoqing@baidu.com> From: "Rafael J. Wysocki" Date: Thu, 21 Oct 2021 13:06:24 +0200 Message-ID: Subject: Re: [PATCH] kernel: power: swap: Make use of vzalloc() and kzalloc() To: Cai Huoqing Cc: "Rafael J. Wysocki" , Pavel Machek , Len Brown , Linux PM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 18, 2021 at 3:16 PM Cai Huoqing wrote: > > 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; > > -- Applied as 5.16 material with some edits in the subject and changelog, thanks!