Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3525891ybt; Tue, 30 Jun 2020 05:12:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwXkcsgaYfaWv1X1TLlyy+CyvZSVdpnxAgZbyrjg5S0ylBgu6ar8L3Y2SB/Sfn8MW1mIOH X-Received: by 2002:a05:6402:1777:: with SMTP id da23mr22213686edb.260.1593519165098; Tue, 30 Jun 2020 05:12:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593519165; cv=none; d=google.com; s=arc-20160816; b=yVL0SCQ6mvGt5u0xFIv4WvqJ9/eNr/SdUNZyA6Hrw0tIaQ1vi3tgDbSSfJHRpEioBX m2C9KH5LwVaf0Ig0XLb7xL4RB04Xm/azlBKvmaqD9AuyOBeniErtPGzLfge5eWVHDS0N jhOBqCKSIADs2xC3LtBsy+qO9/RGYEiQ1wKazZdOVOz3EEPLwBJb0kU5a2rS7cxHsmVn 2RNnD+6Fyr6Pp/X+kKPIrhuqTaxT1EpKQIZuRJq/QvGGc0pFvMEnf5nR+rOh5aZrH9zC eZPYNwDyzYB9lOQL14Tj4QGd4vEwcNuHnS1lt/uOXlviFZQ+AX+u7MidCDYJZIST+32t I1DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=sFhX7QV1ZJHlGJSXvrR+TtCCSjWX8gXgJM2sQ/0NzMQ=; b=nowltgHFmh3lwV1yQhChXrSeoB/O3/t5zskbKgaQIZveHX1ZYuKppcs50SIwUKBObm mAg2oxHfygjH26GcZjKKnbUpmRZRvLaHYCyd3PL9jwzHdO4wVbLAyU1GWQdf/RkXDYbq X9r0G0Fw6NLS+b/T7Y6eHAJi1EN4nUXJDMOvM/P1U614Y0Ic5mkt9Y5CEb3ZCh58ffBH NPFwM0bqKcpOxzrzoM0QU93sJ3//AiY9pHTzatd8Hrn0oY1PIekrUnvxyNRyQI8RQ90t uwHi+Kt/GVIuiNs9WCd9r539fS1TOLddjuDs95UOyQITbEuwqoC+HUWWgXaopJQyzkJn qI5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=azIpapjS; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r8si1500200ejs.462.2020.06.30.05.12.21; Tue, 30 Jun 2020 05:12:45 -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; dkim=pass header.i=@linaro.org header.s=google header.b=azIpapjS; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733093AbgF3Lqd (ORCPT + 99 others); Tue, 30 Jun 2020 07:46:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731944AbgF3Lqc (ORCPT ); Tue, 30 Jun 2020 07:46:32 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9938C061755 for ; Tue, 30 Jun 2020 04:46:31 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id q7so8832187ljm.1 for ; Tue, 30 Jun 2020 04:46:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sFhX7QV1ZJHlGJSXvrR+TtCCSjWX8gXgJM2sQ/0NzMQ=; b=azIpapjSNCTUdv0mtHkly/y2XXN947eAPmIZuK8SfeXM1VHpZP9cHWZ5oGzUX0rlST sajoLuEIiLdBKscbgH5D7Sy15AY04RIhKOi6OJ+OBVk8ys2xViLzu0+KrkuoxzuYCPtb nQst/6BNoaMcf39ngth3XHDQmjUjU8CxZeO8Jc59KpXOmP6gaLejwMUajk+l8igKNirA GWXcX4L3LELlT8PWPYoOKAC7GIgnFJHi+LOBSG7a0ByQQgHA7ENhjrtbEYM+Mk/RD73S MslyP0qTOcy9o+M6bbj9ruF301TueNMmSihmEgvd+Phm+4VLaukfFXuqGjcxaX7DGrO3 UHRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sFhX7QV1ZJHlGJSXvrR+TtCCSjWX8gXgJM2sQ/0NzMQ=; b=ZGHz3D8PAY02HQvcZ+Jmqo5r/acbnMMOk9OqKv+7Exf1ZHSrBd6RA0wqAkS58eEI+y fMxR1E4x5FA1a/2F9T11moBgFWx26Cr0Z1a1JV8oU+oNitqY1q9hXq7EnETgQulcRYJ4 4X8qRPlh/CXsSgdBAo4v7c5MmulEv60Pzn1IMGHiu3Ol7ghL0X5jRssa3Kg1pz+HNPir sEbZ+BKpwOUlcXvdTM0tP+Pm9RGMHGUgoLYUtNCLrAPsiwmcAsW2phxEsqV7mKweg+9c JT7aS51OaTrGWddEdOr4//l2DXRqZ8JExXV9mWPM2PsFPv8iZIueGZBHfYmpqJOgXkhD RpQA== X-Gm-Message-State: AOAM533MV179aZ5g1XbtdxQfN5HzJ7GpImw+2/NdV4IRpOP8Jnr8ugZH AtNti36HIk7kgGH1FOgxrU8Y6e9yINPDF1m4+dnqCA== X-Received: by 2002:a2e:8855:: with SMTP id z21mr5660314ljj.325.1593517590395; Tue, 30 Jun 2020 04:46:30 -0700 (PDT) MIME-Version: 1.0 References: <20200625144509.17918-1-daniel.lezcano@linaro.org> In-Reply-To: <20200625144509.17918-1-daniel.lezcano@linaro.org> From: Amit Kucheria Date: Tue, 30 Jun 2020 17:16:19 +0530 Message-ID: Subject: Re: [PATCH v2 1/5] thermal: core: Add helpers to browse the cdev, tz and governor list To: Daniel Lezcano Cc: Zhang Rui , Srinivas Pandruvada , Ram Chandrasekar , Linux Kernel Mailing List 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 Thu, Jun 25, 2020 at 8:15 PM Daniel Lezcano wrote: > > The cdev, tz and governor list, as well as their respective locks are > statically defined in the thermal_core.c file. > > In order to give a sane access to these list, like browsing all the > thermal zones or all the cooling devices, let's define a set of > helpers where we pass a callback as a parameter to be called for each > thermal entity. > > We keep the self-encapsulation and ensure the locks are correctly > taken when looking at the list. > > Signed-off-by: Daniel Lezcano > --- > drivers/thermal/thermal_core.c | 51 ++++++++++++++++++++++++++++++++++ Is the idea to not use thermal_helpers.c from now on? It fits perfectly with a patch I have to merge all its contents to thermal_core.c :-) > drivers/thermal/thermal_core.h | 9 ++++++ > 2 files changed, 60 insertions(+) > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index 2a3f83265d8b..e2f8d2550ecd 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -611,6 +611,57 @@ void thermal_zone_device_rebind_exception(struct thermal_zone_device *tz, > mutex_unlock(&thermal_list_lock); > } > > +int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *), > + void *data) > +{ > + struct thermal_governor *gov; > + int ret = 0; > + > + mutex_lock(&thermal_governor_lock); > + list_for_each_entry(gov, &thermal_governor_list, governor_list) { > + ret = cb(gov, data); > + if (ret) > + break; > + } > + mutex_unlock(&thermal_governor_lock); > + > + return ret; > +} > + > +int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *, > + void *), void *data) > +{ > + struct thermal_cooling_device *cdev; > + int ret = 0; > + > + mutex_lock(&thermal_list_lock); > + list_for_each_entry(cdev, &thermal_cdev_list, node) { > + ret = cb(cdev, data); > + if (ret) > + break; > + } > + mutex_unlock(&thermal_list_lock); > + > + return ret; > +} > + > +int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *), > + void *data) > +{ > + struct thermal_zone_device *tz; > + int ret = 0; > + > + mutex_lock(&thermal_list_lock); > + list_for_each_entry(tz, &thermal_tz_list, node) { > + ret = cb(tz, data); > + if (ret) > + break; > + } > + mutex_unlock(&thermal_list_lock); > + > + return ret; > +} > + > void thermal_zone_device_unbind_exception(struct thermal_zone_device *tz, > const char *cdev_type, size_t size) > { > diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h > index 4e271016b7a9..bb8f8aee79eb 100644 > --- a/drivers/thermal/thermal_core.h > +++ b/drivers/thermal/thermal_core.h > @@ -41,6 +41,15 @@ extern struct thermal_governor *__governor_thermal_table_end[]; > __governor < __governor_thermal_table_end; \ > __governor++) > > +int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *), > + void *); > + > +int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *, > + void *), void *); > + > +int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *), > + void *thermal_governor); > + > struct thermal_attr { > struct device_attribute attr; > char name[THERMAL_NAME_LENGTH]; > -- > 2.17.1 >