Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5501965ybp; Tue, 15 Oct 2019 00:04:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqzCqAqJ2w2tXYztLTOOqOuEWmKjnOqGfJlYYHcs9xjpqmpLzsLEMkUIZ0jj6VqtGi6IxmNE X-Received: by 2002:aa7:de1a:: with SMTP id h26mr32120374edv.289.1571123064000; Tue, 15 Oct 2019 00:04:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571123063; cv=none; d=google.com; s=arc-20160816; b=RorK5QCuQ0e1hGrayP4oTv+SpawyzMpO4gdf2VLqYm9Oy9Wtq2sjE8ZIohsTnDWebk 0fcJV1m9w7zxUZySwUoSY+n644osaGWbhOmBbjPgVRou0rQ3Hhsq5awTRaIyllBjH01Y Vlwzk/wYLJcQc1JEE1+SkABNxBd1zdTbcxbR6gxb7m30aX05lHannujnn5wTz1K5k5yj +g96lol/LVRh/R+lnpWjRM4GATN5C+KKm/NLTbYrTkZqOa+E3hy2VJughrci/yNf1ZCk h2oI2K6TKyQXw8zCsTf66E06iAv1nM44GVlQL+dIB0KfZGOSEelJAtMIMhppRW2nBRKQ trYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:cc:from:subject:mime-version :message-id:date:dkim-signature; bh=DFJlUv3R2tvxSh8wj2z2rPk5wlDmklaGa42vbJhXkJA=; b=vaI8xi4Cn2OXboKNB53340mK9Hu3y6FXEKqsfAN9d+Tx+JQyfvWYgEWEuszF/BcNi6 48fm6c3oPJO98ZWOT11escUFXn+FG9BVIZP4vucdREmkoEl3cbLiKGFj5lse1cg0aQX8 8IEF3yCqHHykE70p8A0ejb4kEhewgbCE5Lh1/KvoRxIHzxCKfg+Evlm9a9Wu38jSRHF/ 2ZqaWnKI/MlNShUG60lqXxJotloEcWu4HvfgL49cRNG8TAPzocY58rcHnw+91Ndke3V1 r0M1L4/l33Rhlo7ER941yIifWH3s3oSnpRCWJF/hCRNyC/83xTlPof28gQpDKvelIMF+ b1xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ofZhNagG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e18si12219927eds.68.2019.10.15.00.04.00; Tue, 15 Oct 2019 00:04:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ofZhNagG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727116AbfJOGNy (ORCPT + 99 others); Tue, 15 Oct 2019 02:13:54 -0400 Received: from mail-pg1-f201.google.com ([209.85.215.201]:49660 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726382AbfJOGNy (ORCPT ); Tue, 15 Oct 2019 02:13:54 -0400 Received: by mail-pg1-f201.google.com with SMTP id l6so14355010pgq.16 for ; Mon, 14 Oct 2019 23:13:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:cc; bh=DFJlUv3R2tvxSh8wj2z2rPk5wlDmklaGa42vbJhXkJA=; b=ofZhNagGO/RutpOWP60t/B7g/QAUMiKkkistW5ofAZdYiEZRlBEruprFDM6I6PxLZy 8KTprRzP9E4b8XM3NWG4eUc6A0T18xd40aGxpktcC8PMv7IX1puYOtclbr9YnAIKijke YyEfNr6s+ibNpfJBNLEbptgb5d0Z8Y67rS7J4YwgG5V1C5lVsD/z2MQpR7mQcld3XHEy XKqFMzbwFNQhMKlULVjexe8PC/eyFB1ke3rf3Aq7aarPxCdwkp3mSbUQ1jI1wr7wqert eaF6sAroReMPMLc+tOANlAHFAKZKqA6whVoZN9CEh9a0n2zF5Yd+hO5HldJqER92ZVxK w87A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:cc; bh=DFJlUv3R2tvxSh8wj2z2rPk5wlDmklaGa42vbJhXkJA=; b=CXPWIN0hW8Uvy2kQMMrebeD3rZhi7Iy0hZuLLeZSj7i9vILxASGeheDGQk+3IWXDci RfRMnelRhDILUjjpV4yDTF+nKpE3/Ey7JZfCeDW+H47DBhZ5+MYAqz0ATG+a6gMMSJYJ 5K9zAwGDuQ6w9ndTEDo2BcgacmRjUbTpva8m4oZ5eKsPGf4bnQeUKNKdl6su9SbsabhB dLr1q7PXSZGWL5v/mwU6M0dNehcJMNIkzuJ5Mpt9NIFH/fiV8LChrkC6xBCKpW/uBibD FHH81IwmrvAtXBDeihDpBKkVmxwcUeXKTwCZBz8e6QSzcnit8YmeN3M2Zt37zaTILIWq g15g== X-Gm-Message-State: APjAAAWBqswhdvgokFy8r02Hmy0kLLgeJZpptAHVy5irHUCdn96lnw6F wJqq3mANEz4TkghbudqzP+AYw9s= X-Received: by 2002:a63:3003:: with SMTP id w3mr34876350pgw.364.1571120033122; Mon, 14 Oct 2019 23:13:53 -0700 (PDT) Date: Mon, 14 Oct 2019 23:13:49 -0700 Message-Id: <20191015061349.141448-1-wvw@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog Subject: [PATCH] thermal: create softlink by name for thermal_zone and cooling_device From: Wei Wang Cc: wei.vince.wang@gmail.com, Wei Wang , Zhang Rui , Eduardo Valentin , Daniel Lezcano , Amit Kucheria , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The paths thermal_zone%d and cooling_device%d are not intuitive and the numbers are subject to change due to device tree change. This usually leads to tree traversal in userspace code. The patch creates `tz-by-name' and `cdev-by-name' for thermal zone and cooling_device respectively. Signed-off-by: Wei Wang --- drivers/thermal/thermal_core.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index d4481cc8958f..0ff8fb1d7b0a 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -22,6 +22,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -46,6 +47,8 @@ static DEFINE_MUTEX(poweroff_lock); static atomic_t in_suspend; static bool power_off_triggered; +static struct kobject *cdev_link_kobj; +static struct kobject *tz_link_kobj; static struct thermal_governor *def_governor; @@ -954,7 +957,7 @@ __thermal_cooling_device_register(struct device_node *np, struct thermal_zone_device *pos = NULL; int result; - if (type && strlen(type) >= THERMAL_NAME_LENGTH) + if (!type || !type[0] || strlen(type) >= THERMAL_NAME_LENGTH) return ERR_PTR(-EINVAL); if (!ops || !ops->get_max_state || !ops->get_cur_state || @@ -989,9 +992,15 @@ __thermal_cooling_device_register(struct device_node *np, return ERR_PTR(result); } - /* Add 'this' new cdev to the global cdev list */ + /* Add 'this' new cdev to the global cdev list and create link*/ mutex_lock(&thermal_list_lock); list_add(&cdev->node, &thermal_cdev_list); + if (!cdev_link_kobj) + cdev_link_kobj = kobject_create_and_add("cdev-by-name", + cdev->device.kobj.parent); + if (!cdev_link_kobj || sysfs_create_link(cdev_link_kobj, + &cdev->device.kobj, cdev->type)) + dev_err(&cdev->device, "Failed to create cdev-by-name link\n"); mutex_unlock(&thermal_list_lock); /* Update binding information for 'this' new cdev */ @@ -1157,6 +1166,8 @@ void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev) } } } + if (cdev_link_kobj) + sysfs_remove_link(cdev_link_kobj, cdev->type); mutex_unlock(&thermal_list_lock); @@ -1340,6 +1351,12 @@ thermal_zone_device_register(const char *type, int trips, int mask, mutex_lock(&thermal_list_lock); list_add_tail(&tz->node, &thermal_tz_list); + if (!tz_link_kobj) + tz_link_kobj = kobject_create_and_add("tz-by-name", + tz->device.kobj.parent); + if (!tz_link_kobj || sysfs_create_link(tz_link_kobj, + &tz->device.kobj, tz->type)) + dev_err(&tz->device, "Failed to create tz-by-name link\n"); mutex_unlock(&thermal_list_lock); /* Bind cooling devices for this zone */ @@ -1411,6 +1428,8 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz) } } } + if (tz_link_kobj) + sysfs_remove_link(tz_link_kobj, tz->type); mutex_unlock(&thermal_list_lock); -- 2.23.0.700.g56cf767bdb-goog