Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2158800ybt; Fri, 3 Jul 2020 02:17:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXptvsPrEP1k6iJuGHh8zxB14I9L8qzIMa7EEqbM7Ir64JWtAxJ+Mzga+5HW+0LqiRZVb3 X-Received: by 2002:a17:906:5595:: with SMTP id y21mr32142469ejp.61.1593767841567; Fri, 03 Jul 2020 02:17:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593767841; cv=none; d=google.com; s=arc-20160816; b=LuBN1J1EFobIJ6zx02xCO+dKeE3e2BAlQ+PMBeBcHQ5I4TKJocmq+7ISotMVu4TbDl V84RTf8qM6jLCm8F5TMhmcw+Qs47QLr32EaN4CvEuteVBBLy2q14cpnAORWvo0UGHCnK 2IGrCURSbAT3Pne6lxtrQg9VwFA0YA1MZ7N1SEQDDW6+WGxgqjszpUp9dBBBKj1se75/ ig3TODhjTfDBzGdijePnLri7DFhSyM5at2mqdXJe8HGpHLERU2F5oZEVMEKKc2/eB+5p A6bnquS5C7ENsN48RaaflQz6YdjnwlLzGawzry2SjYUIOehnAi6Vz/LYTsOQzz+SzPmY ceXQ== 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=HjLtRECZ4xF2T8beK0iYF5HUVoGI04zGUc7fJuaUDUM=; b=iqYglpDZZ0TrQ5bG+urBos1WSGxcpH8VNBtbImQwiF1TBn9IpIXBiti4Pu22WG5hmm Yxr4/N78L8sbkLEgO2RM9dPgqvvwE61JvkMwPU16OL72vqiRgxg9pHoU0njbq/9J2B5/ vIfA6iBGHbDBIK5f/hPokyD5evqPQxK9WVHeHCZJ0wavFqr1nux5/G5NEKralu9aOyL6 gjQbGWThbrA9L6/B6EBm6w7BZpz/2HBd5svypX8C6HdqTuEVbB+8sEGcL7B9XFq3NnZq iuO14xQwEbq08k3ZfdBSFaxwJ5R9OVzHWb4ptAzWxPlDj8g67l6Kqbp7Mixvd6kRZOVg Ooag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tr1vg3PW; 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 r6si2736175ejd.213.2020.07.03.02.16.58; Fri, 03 Jul 2020 02:17:21 -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=tr1vg3PW; 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 S1726228AbgGCJOu (ORCPT + 99 others); Fri, 3 Jul 2020 05:14:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725796AbgGCJOu (ORCPT ); Fri, 3 Jul 2020 05:14:50 -0400 Received: from mail-vk1-xa42.google.com (mail-vk1-xa42.google.com [IPv6:2607:f8b0:4864:20::a42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AD5DC08C5C1 for ; Fri, 3 Jul 2020 02:14:50 -0700 (PDT) Received: by mail-vk1-xa42.google.com with SMTP id g22so2774138vke.9 for ; Fri, 03 Jul 2020 02:14:50 -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=HjLtRECZ4xF2T8beK0iYF5HUVoGI04zGUc7fJuaUDUM=; b=tr1vg3PWzgcj46XCTU9K0bi6+NFfnGc+PieFv9e9XcIIxPLoTAJqDTKGVOSOVaYJDO 0MaH93nB9up68BBkr/e/KHSCkFvYwpVIzgTBODl5Kf5BUUxoQgdBjkHwFIdEtHAhPnEZ TLA5quj/bgjLPmyF4a7iJCUXdMpg2qZjQ5p+S6BDb7DtKX1krZw2Ir8LAhRksXHUuZyp 3Kr/N1KnUSqmrSkiLOw626SR1lZ3arU/kr+KsirZaCZiU470zJqDGo2Pg1NGeK6pXspy JS/ND+L85yDzXth/vl3tSea5Ungvw5Fql4rxDRY4MNCbCIC3iA8C2bKZpItviWaQ+XN1 0v7Q== 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=HjLtRECZ4xF2T8beK0iYF5HUVoGI04zGUc7fJuaUDUM=; b=JOUM7yjuPOe/WjJi32aJQRfPlbce6YF7CPk5FRrDVN6FAj5pRfgmRwUkEBD5Z7gd/t LhcYZ0Hgz320sG7SnwX2F3J/GcYQxthbwS+VFj7UasQc0FqFvRprQ9/UooEOkYX6hVau wLVxNJpIv+fQnGCmkKgpsU1H8bvQIJcWTeKoVyO1DVUBt4oA5AgrQLcsskvKTClqGBAD WWw+InfX2d7bdt4lgLGtRDl44esVj/+hZDzx9Wwj9OZnyWq/YWXciZYj9oZZATjkJW8g e8HI+4oiFoJwGJ3UE4kS0k3FkPe0HimSvEej5TzpeRfPHPKSo4dCpZtYALZSM4jAUBdt MBxg== X-Gm-Message-State: AOAM532vve1c5MOcmiA2Fsh0fcCELoeOs8807sRY9KhUAIYPoB5RTiA5 QOxqruOf7ueRzJYIdmHxcB8x5WxfdTHrJuKFj20t8A== X-Received: by 2002:a1f:d783:: with SMTP id o125mr25421584vkg.46.1593767688546; Fri, 03 Jul 2020 02:14:48 -0700 (PDT) MIME-Version: 1.0 References: <20200703085309.32166-1-daniel.lezcano@linaro.org> In-Reply-To: <20200703085309.32166-1-daniel.lezcano@linaro.org> From: Amit Kucheria Date: Fri, 3 Jul 2020 14:44:37 +0530 Message-ID: Subject: Re: [PATCH v3 1/4] thermal: core: Add helpers to browse the cdev, tz and governor list To: Daniel Lezcano Cc: Zhang Rui , Srinivas Pandruvada , Ram Chandrasekar , LKML , Linux PM 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 Fri, Jul 3, 2020 at 2:23 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. > > Acked-by: Zhang Rui > Signed-off-by: Daniel Lezcano Reviewed-by: Amit Kucheria > --- > drivers/thermal/thermal_core.c | 51 ++++++++++++++++++++++++++++++++++ > 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 b71196eaf90e..9caaa0b6d662 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -617,6 +617,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 c95689586e19..71d88dac0791 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 >