Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1267082pxb; Thu, 14 Apr 2022 02:09:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtR7/Xm0+I1sa4FbM4G4x/wNr7yFyekEIL+W313at4Z7ZbK5eXPdbSQiMzE0u/eCQPtfVW X-Received: by 2002:aa7:8094:0:b0:505:b544:d1ca with SMTP id v20-20020aa78094000000b00505b544d1camr2997357pff.26.1649927347161; Thu, 14 Apr 2022 02:09:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649927347; cv=none; d=google.com; s=arc-20160816; b=y7QWiKegAnD6Qkl85ZgRka/QHPxLVP8ogWSQvRppL3105p8HCkTYcL9nVg5/uiB+Gk qpNWe3nMH1o6mUgXkYHIruDMPV9AKMEr/X5G9RWPHOi6zpg9KYX/cwi5Kv9+i0aig2iB FqC5/Y7FXCY4i+jQnJKpuUu9eMjW+8A5qA1R+PpzP9MG7A00rQLR+Mc4zcSceLAj6oRZ h2x22eY+ZMrA+n8QgL3AFAPTnErj95amaypdw2cIPdMkFT2ni1UfrqztOWHTZ/vfO3ri 2ThC81oONyUrcsfqGsOlGTwKiAiBiEOIytK9+Zq6gxvQScWlptrZ1YJnqMszasq50/Ox OTMg== 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=ICXFv2vFTWA/EfToNSXNFej0aDLg/UzwH2y+FUBsnf8=; b=Ot/37vMevZEz7JZo2DwQoVjYBNNQDgPT/xG+4ug6CJaUYGmGb1B20cIcH3GGvjJvdN k8ChJuHMsLsHGhf57VaBaBupERuQE9aXkAxm7Httwjadsy4rLdoRnA7aWSmg9vYYQFpz c/WZZXlGzv3H21hAPH7AAwbWH3HJT7sDNMmFzQ7HqvH/a7BuWepK6qx3K36OJPD2g9tO EsnYj/hsaInvZdku2X5qbkwp9Gb9RaE1ZVpXJU5KaZyND69zEc7sdr6p0nS1V6im8WIp LOgKOZ3EC+4fWL25HGzq4mFwMP3blY4qZLxxPu3ESv9ODmtnk3TsDkB7MTHceOvZ3/eW heEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 125-20020a630483000000b0039f79dbe674si1325103pge.309.2022.04.14.02.08.54; Thu, 14 Apr 2022 02:09:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236235AbiDMPBU (ORCPT + 99 others); Wed, 13 Apr 2022 11:01:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234367AbiDMPBT (ORCPT ); Wed, 13 Apr 2022 11:01:19 -0400 Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F0CFE0DD; Wed, 13 Apr 2022 07:58:58 -0700 (PDT) Received: by mail-yb1-f171.google.com with SMTP id m132so4250374ybm.4; Wed, 13 Apr 2022 07:58:58 -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=ICXFv2vFTWA/EfToNSXNFej0aDLg/UzwH2y+FUBsnf8=; b=ucIfUPnhBBucUyxJsRIMkWlhPT+08Y0+VrishMUN8nPab1K9E9FNLRfMIZL4UmA9NI UpqDWU9M/AlkR+8F96trf371dMVK5zVRxHfs1Y2fjvdHZ3lE/sBDhvXPTRUCdO0B3+HV vc7b7w9RAv8JeNj/kNpSO4swPPKqPjvcRYj3ZaK2sVp5g5egMtUqLIrtPqrygGwNHwq3 XMvlcWHCXtmTUk4KDOa91Zuo5Vw+XVwySf8MdNj5HqUrEGjQ5PoxUb2bzZlRoRZEFgXy wlYrkIO+O07Bqlw78P+15UAUMZL85x1OYIfAg9T5nM4AqGpqSmdNnxUaHgqwOmsnFQt3 9ZkA== X-Gm-Message-State: AOAM531qWG859WEmlLFuR84KWzdhPM9EjqK0uHkx9FrAcfqQfYyZXJKx Y8BqGVxXtsf/G/zDO9UBlxv0q8pIAsn2lG5FDG4= X-Received: by 2002:a05:6902:352:b0:63e:94c:883c with SMTP id e18-20020a056902035200b0063e094c883cmr28647821ybs.365.1649861937643; Wed, 13 Apr 2022 07:58:57 -0700 (PDT) MIME-Version: 1.0 References: <20220325073030.91919-1-kant@allwinnertech.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Wed, 13 Apr 2022 16:58:46 +0200 Message-ID: Subject: Re: [PATCH v2] thermal: devfreq_cooling: use local ops instead of global ops To: Lukasz Luba , Kant Fan Cc: Amit Kucheria , "Zhang, Rui" , Linux PM , Linux Kernel Mailing List , allwinner-opensource-support@allwinnertech.com, Stable , "Rafael J. Wysocki" , Daniel Lezcano , Ionela Voinescu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 25, 2022 at 10:02 AM Lukasz Luba wrote: > > Hi Kant, > > On 3/25/22 07:30, Kant Fan wrote: > > Fix access illegal address problem in following condition: > > There are muti devfreq cooling devices in system, some of them has > > em model but other does not, energy model ops such as state2power will > > append to global devfreq_cooling_ops when the cooling device with > > em model register. It makes the cooling device without em model > > also use devfreq_cooling_ops after appending when register later by > > of_devfreq_cooling_register_power() or of_devfreq_cooling_register(). > > > > IPA governor regards the cooling devices without em model as a power actor > > because they also have energy model ops, and will access illegal address > > at dfc->em_pd when execute cdev->ops->get_requested_power, > > cdev->ops->state2power or cdev->ops->power2state. > > > > Fixes: 615510fe13bd2 ("thermal: devfreq_cooling: remove old power model and use EM") > > Cc: stable@vger.kernel.org # 5.13+ > > Signed-off-by: Kant Fan > > --- > > drivers/thermal/devfreq_cooling.c | 25 ++++++++++++++++++------- > > 1 file changed, 18 insertions(+), 7 deletions(-) > > > > diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c > > index 4310cb342a9f..d38a80adec73 100644 > > --- a/drivers/thermal/devfreq_cooling.c > > +++ b/drivers/thermal/devfreq_cooling.c > > @@ -358,21 +358,28 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df, > > struct thermal_cooling_device *cdev; > > struct device *dev = df->dev.parent; > > struct devfreq_cooling_device *dfc; > > + struct thermal_cooling_device_ops *ops; > > char *name; > > int err, num_opps; > > > > - dfc = kzalloc(sizeof(*dfc), GFP_KERNEL); > > - if (!dfc) > > + ops = kmemdup(&devfreq_cooling_ops, sizeof(*ops), GFP_KERNEL); > > + if (!ops) > > return ERR_PTR(-ENOMEM); > > > > + dfc = kzalloc(sizeof(*dfc), GFP_KERNEL); > > + if (!dfc) { > > + err = -ENOMEM; > > + goto free_ops; > > + } > > + > > dfc->devfreq = df; > > > > dfc->em_pd = em_pd_get(dev); > > if (dfc->em_pd) { > > - devfreq_cooling_ops.get_requested_power = > > + ops->get_requested_power = > > devfreq_cooling_get_requested_power; > > - devfreq_cooling_ops.state2power = devfreq_cooling_state2power; > > - devfreq_cooling_ops.power2state = devfreq_cooling_power2state; > > + ops->state2power = devfreq_cooling_state2power; > > + ops->power2state = devfreq_cooling_power2state; > > > > dfc->power_ops = dfc_power; > > > > @@ -407,8 +414,7 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df, > > if (!name) > > goto remove_qos_req; > > > > - cdev = thermal_of_cooling_device_register(np, name, dfc, > > - &devfreq_cooling_ops); > > + cdev = thermal_of_cooling_device_register(np, name, dfc, ops); > > kfree(name); > > > > if (IS_ERR(cdev)) { > > @@ -429,6 +435,8 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df, > > kfree(dfc->freq_table); > > free_dfc: > > kfree(dfc); > > +free_ops: > > + kfree(ops); > > > > return ERR_PTR(err); > > } > > @@ -510,11 +518,13 @@ EXPORT_SYMBOL_GPL(devfreq_cooling_em_register); > > void devfreq_cooling_unregister(struct thermal_cooling_device *cdev) > > { > > struct devfreq_cooling_device *dfc; > > + const struct thermal_cooling_device_ops *ops; > > struct device *dev; > > > > if (IS_ERR_OR_NULL(cdev)) > > return; > > > > + ops = cdev->ops; > > dfc = cdev->devdata; > > dev = dfc->devfreq->dev.parent; > > > > @@ -525,5 +535,6 @@ void devfreq_cooling_unregister(struct thermal_cooling_device *cdev) > > > > kfree(dfc->freq_table); > > kfree(dfc); > > + kfree(ops); > > } > > EXPORT_SYMBOL_GPL(devfreq_cooling_unregister); > > > Thank you for updating it, LGTM > > Reviewed-by: Lukasz Luba Applied as 5.19 material. Lukasz, this had a conflict with your EM series, please double check if my resolution in the bleeding-edge branch is correct. Thanks!