From patchwork Tue Nov 8 05:08:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9416533 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4FC0460512 for ; Tue, 8 Nov 2016 05:14:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F4A928B99 for ; Tue, 8 Nov 2016 05:14:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32FEC28B9B; Tue, 8 Nov 2016 05:14:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF9D728B99 for ; Tue, 8 Nov 2016 05:14:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753032AbcKHFOe (ORCPT ); Tue, 8 Nov 2016 00:14:34 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34747 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753322AbcKHFKZ (ORCPT ); Tue, 8 Nov 2016 00:10:25 -0500 Received: by mail-pf0-f195.google.com with SMTP id y68so18086617pfb.1; Mon, 07 Nov 2016 21:10:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WdQmx8Lc+jeZx1O97aMpfA57Yo1qXq5N5KR0yvuTEq4=; b=r0J/911PMjXFFWLCh/NC19+hKkr5JPP+sohj1R8i7JugQVUdhdf3X4gnZ5dZQQJvXx Pe6Ft09d5wtAVxdqxNYa/DapCz2v8/izfVEuWfPHb9TEZLtJkM+3vTlT4XRQHyW+SSPv 4QrJGPLGrc0iq8uebhmgdTzXj5TibqqtdKnDADNI+JftEZKGpEzv6JxOHL2zfgZb5l6X tJMDg93h0k6ahEKs9YE1DxeEMH405fb71vf8vhI3ULqzbEl+q22+hChR5nzq2vOrm1kA /3jTfjNOaiAr4jTtkv07LK49GDNBFBck2n3u8ZJ59ncZCrvuESr7rAYYtXEfgHGNOPq/ mvbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WdQmx8Lc+jeZx1O97aMpfA57Yo1qXq5N5KR0yvuTEq4=; b=M2iU/2e/6d5RfbhCEtrmx7kl6JG717dLZopGSwiwZTwP2OR/iqU7aqrJdoBsyg8rrj GRIHzxch1U4YOxGeJPcRF+mRFl8njGt8PcVWbXTGnEvngh176/PuaZ3+IZFgZjS4UQTw 8DOCZeP+IRmCQuTDDhSHeAGUQgWYYOjzuP2FbOOtYob27AAxSLIDQg3Jss2CHpMrWr4M F6/HiAk2VzGLDjHMJRInxjUBOVjELnz4UJxPYzpTS76vio7mg0bnnoG/Yv97AI51RSr/ K45JmgELKZIKw9vyXFbHtYqAcv939B/DmBRnbLLcmZ4Fnsh9sKuDM2uHrWFYmn/60+hU m1gA== X-Gm-Message-State: ABUngvfaFrkY8I7bzOorKepUQVjADfFYs83LsSt78MCF1DaSpnithzRpGaOxLugDpuJ9qg== X-Received: by 10.98.76.8 with SMTP id z8mr19920776pfa.167.1478581825101; Mon, 07 Nov 2016 21:10:25 -0800 (PST) Received: from localhost ([2601:647:4401:a2f0:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id y12sm44688519pal.1.2016.11.07.21.10.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Nov 2016 21:10:24 -0800 (PST) From: Eduardo Valentin To: Rui Zhang Cc: LKML , Linux PM , Eduardo Valentin Subject: [PATCHv2 18/49] thermal: core: split available_policies_show() Date: Mon, 7 Nov 2016 21:08:56 -0800 Message-Id: <1478581767-7009-19-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1478581767-7009-1-git-send-email-edubezval@gmail.com> References: <1478581767-7009-1-git-send-email-edubezval@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch creates a helper to build a list of available governors. Cc: Zhang Rui Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- drivers/thermal/thermal_core.c | 35 ++++++++++++++++++++--------------- drivers/thermal/thermal_core.h | 1 + 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 23f138f..3d51184 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -779,6 +779,25 @@ int thermal_zone_device_set_policy(struct thermal_zone_device *tz, return ret; } +int thermal_build_list_of_policies(char *buf) +{ + struct thermal_governor *pos; + ssize_t count = 0; + ssize_t size = PAGE_SIZE; + + mutex_lock(&thermal_governor_lock); + + list_for_each_entry(pos, &thermal_governor_list, governor_list) { + size = PAGE_SIZE - count; + count += scnprintf(buf + count, size, "%s ", pos->name); + } + count += scnprintf(buf + count, size, "\n"); + + mutex_unlock(&thermal_governor_lock); + + return count; +} + /* sys I/F for thermal zone */ #define to_thermal_zone(_dev) \ @@ -1048,21 +1067,7 @@ static ssize_t available_policies_show(struct device *dev, struct device_attribute *devattr, char *buf) { - struct thermal_governor *pos; - ssize_t count = 0; - ssize_t size = PAGE_SIZE; - - mutex_lock(&thermal_governor_lock); - - list_for_each_entry(pos, &thermal_governor_list, governor_list) { - size = PAGE_SIZE - count; - count += scnprintf(buf + count, size, "%s ", pos->name); - } - count += scnprintf(buf + count, size, "\n"); - - mutex_unlock(&thermal_governor_lock); - - return count; + return thermal_build_list_of_policies(buf); } static ssize_t diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h index db65d3b..8994d2a 100644 --- a/drivers/thermal/thermal_core.h +++ b/drivers/thermal/thermal_core.h @@ -61,6 +61,7 @@ void thermal_zone_device_rebind_exception(struct thermal_zone_device *, void thermal_zone_device_unbind_exception(struct thermal_zone_device *, const char *, size_t); int thermal_zone_device_set_policy(struct thermal_zone_device *, char *); +int thermal_build_list_of_policies(char *buf); #ifdef CONFIG_THERMAL_GOV_STEP_WISE int thermal_gov_step_wise_register(void);