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 X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D9D5C433DF for ; Wed, 19 Aug 2020 11:05:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 33D5720772 for ; Wed, 19 Aug 2020 11:05:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597835119; bh=qPmqAtB5kIlL9CLvyvLMssKURPyMFOvitfa8TYvP0fA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=RNRnkfeF+Zy7DxOXlWBz6Kezthvzbz/k0Sst89y6T5aSh8d5nzuKS5kEt/Qr8YTQC +EL6mbChfESBJmjdIH8mRoi6spW9iEgdOYOAwqL1uVBo/CdhW1JoFA49/NBF5XHFrO 4hl7GrnE2k2AU7jE5a3xRIO2sX2WEc0A8PXTKik8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727900AbgHSLFS (ORCPT ); Wed, 19 Aug 2020 07:05:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:45496 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726820AbgHSLFP (ORCPT ); Wed, 19 Aug 2020 07:05:15 -0400 Received: from mail-ua1-f54.google.com (mail-ua1-f54.google.com [209.85.222.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 792CE20855 for ; Wed, 19 Aug 2020 11:05:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597835114; bh=qPmqAtB5kIlL9CLvyvLMssKURPyMFOvitfa8TYvP0fA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=0J3VhVx8LMcvrlzwxlwsuXkv8inwZY/nckToHljNV9ideetAqMXYPTD9/cfdQ80bY BSRm3deJCd7YEJx4yhg26v4rApWzuPsuZj3n9YRcssqChXBE8hGrWAr6/thzOGOG41 81UlfMfbTbMeD0Unup77kbrNc8vZZ/iyvuoQx6e8= Received: by mail-ua1-f54.google.com with SMTP id d20so6741092ual.13 for ; Wed, 19 Aug 2020 04:05:14 -0700 (PDT) X-Gm-Message-State: AOAM5312Qtwicu4bbfuPJ4mB2l1OPvAjLZjmdVlIBb55bZQhkQi6Ik5f bGuY3LWdX/9SSczzTcYexJa525PXGvSZNNR9Yk9Azg== X-Google-Smtp-Source: ABdhPJyD0UglYBq8i1MxNJwsh1Hl91rwRFZ202eXtS0Tb7JGoCFVZhhpi1lQID75+bQ14YBE2fGt+CFQO79gZ0/0+S4= X-Received: by 2002:ab0:20b6:: with SMTP id y22mr13393349ual.77.1597835113615; Wed, 19 Aug 2020 04:05:13 -0700 (PDT) MIME-Version: 1.0 References: <20200818063005.13828-1-zbestahu@gmail.com> In-Reply-To: <20200818063005.13828-1-zbestahu@gmail.com> From: Amit Kucheria Date: Wed, 19 Aug 2020 16:35:02 +0530 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] thermal: sysfs: fall back to vzalloc for cooling device's statistics To: Yue Hu Cc: Zhang Rui , Daniel Lezcano , Viresh Kumar , Linux PM list , LKML , huyue2@yulong.com, zbestahu@163.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 18, 2020 at 12:00 PM Yue Hu wrote: > > From: Yue Hu > > We observed warning about kzalloc() when register thermal cooling device > in backlight_device_register(). backlight display can be a cooling device > since reducing screen brightness will can help reduce temperature. > > However, ->get_max_state of backlight will assign max brightness of 1024 > to states. The memory size can be getting 1MB+ due to states * states. > That is so large to trigger kmalloc() warning. > > So, let's remove it and try vzalloc() if kzalloc() fails. If we can do with vzalloc()'ed memory i.e. we don't need contiguous physical memory, why even attempt kzalloc? > > Signed-off-by: Yue Hu > --- > drivers/thermal/thermal_sysfs.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c > index aa99edb..9bae0b6 100644 > --- a/drivers/thermal/thermal_sysfs.c > +++ b/drivers/thermal/thermal_sysfs.c > @@ -16,6 +16,8 @@ > #include > #include > #include > +#include > +#include > #include > #include > > @@ -919,7 +921,9 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev) > var += sizeof(*stats->time_in_state) * states; > var += sizeof(*stats->trans_table) * states * states; > > - stats = kzalloc(var, GFP_KERNEL); > + stats = kzalloc(var, GFP_KERNEL | __GFP_NOWARN); > + if (!stats) > + stats = vzalloc(var); > if (!stats) > return; > > @@ -938,7 +942,7 @@ static void cooling_device_stats_setup(struct thermal_cooling_device *cdev) > > static void cooling_device_stats_destroy(struct thermal_cooling_device *cdev) > { > - kfree(cdev->stats); > + kvfree(cdev->stats); > cdev->stats = NULL; > } > > -- > 1.9.1 >