Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp919457ybp; Thu, 17 Oct 2019 05:36:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxEjFH9CZkhfvL7jWPRO66t6kWXS3FvORoeRFLNHGsAwYUqAUYJ+YlNAu6QumYl7c2k1LpO X-Received: by 2002:a17:906:8317:: with SMTP id j23mr3159653ejx.314.1571315774487; Thu, 17 Oct 2019 05:36:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571315774; cv=none; d=google.com; s=arc-20160816; b=hQ73ZdVoWPoxqZljjxs5EdI92QBk7KVoCk6rfYu38izIvs5W2a8dpf1B1LVsTd0WDM Tb5AjEpe6+NWE+le6lA1ifERKe0qs0jTRYqIs7eMHliMTmIzE8BDI1CsNpu6Ap/12E9P /ai3LTTyR/3rUqHKouBLgvcbjkZ5hbYDZOp8CjRjYt0A5qJoHdeV5lzbw+mFqFgRMCiq c+IWdPXrcfvhAfLJKDKZOR43nPZEYZfuTyQaoCbNEnmiTSdUVlS2Us3xZnqy20z0lVYT wQx+3yReXaSjePEG37aph5Jd96AkGbHea+xgMSxOqX/YC800SJJehV+cJ0AgH8r75+jb yoAQ== 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=39+L7uTpKiUnwyMszInidREucesuvpkGs3DnCgLxrOc=; b=aewC7BXL9jCnOOyZnzHK/MMW1V1v8YozIUR8hgNVMysGFyDpw6srqJrbfSc0VFvMS4 5ve+0Gryr0uXk2J9zVypE6OoXMzgdXjkbxaVpOAn0l0N9Ekvr1w1ATC7F5fH3lFzFtDO GUnPkZLfy1lNkBxewQULwS7DNHaCJGzwTH/oSNxGj40/sYSHQ6Tbdz/5i3vvVhAcYO9H 37pajdbcIM1xwNLuzdFqev35p6R42OBO6h4lf3T8OvsM3XwemDWpn8xmSIIScoXeep2c O+FUF4FOGfpUN9+mNrb+3IpU+6E9nCluChvdOM+DdbqplXQay0tihsSkDem40WyiVD2A MxTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@verdurent-com.20150623.gappssmtp.com header.s=20150623 header.b="kxVEGT/o"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l9si1245792ejx.426.2019.10.17.05.35.51; Thu, 17 Oct 2019 05:36:14 -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=@verdurent-com.20150623.gappssmtp.com header.s=20150623 header.b="kxVEGT/o"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406474AbfJPQvD (ORCPT + 99 others); Wed, 16 Oct 2019 12:51:03 -0400 Received: from mail-vs1-f67.google.com ([209.85.217.67]:41704 "EHLO mail-vs1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406468AbfJPQvC (ORCPT ); Wed, 16 Oct 2019 12:51:02 -0400 Received: by mail-vs1-f67.google.com with SMTP id l2so16030462vsr.8 for ; Wed, 16 Oct 2019 09:51:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verdurent-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=39+L7uTpKiUnwyMszInidREucesuvpkGs3DnCgLxrOc=; b=kxVEGT/otZz4heGzzrhb8yZ07E1GnHC0Eu7ysL3Bmnf+5nwTha37D1OFD3PYSgA0oi XUJBSw6OJm7gbKWLiXoaMPMIoiOeufjjAiEv5BCKXWUlE+6v8qkAwYZufLFX4BX1l7/5 w+xDeefkWxcFskLw9zBbJdJzJmVb32G2d5Zc+3CAGZ0fgr459hvF83wirifXNNclh9x1 scQPk4ZKrngge0bgXBU2sx9Lg7UhxHSuN4wc5xi4+UiLmzeHDgyehZSDhKwtdnRR3+zI gtEYYGAHmEJg5VYRwBSD2nfakt6EJPJudUn4iUzzqLXBzrqlFccKv07jWFH1meMwcsrV Al/w== 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=39+L7uTpKiUnwyMszInidREucesuvpkGs3DnCgLxrOc=; b=RaJpQYRc2rDGW+5/3210tBOGv14mV0TwoJRxTr3DAIPI/D1QhaB0pNYdOmLyFzjb/z +D6y8RfO+JD0seinNvH+8hx8bQGivqi21/GlZqM0kd0aklR+qvm0aqQUavNfigRSRS2d 1Sgo9aaS3K6uArrp6ytBB7QkGp4UdwDFkyLeG6WCXzk9Zu4xlEA8hJMg3/Ko9lNKbKx2 rOEt0CDph2BX5K2yOn1QDfoRKsVSCIt4sRTD3frsZXywb9s7g4MAjLtoHDsXYxGzUq2T DAILsn1LqLKF5iYdtMvjOsc5BpekRywIaZDNXwMGPlIGhp4P13mxToRPwWw6vf6uQAUo t0Tw== X-Gm-Message-State: APjAAAWvy04q1ZYCFnH78Zc24ppAAOkpg7oGENbVkNAwP6Tec/R/Eo4/ 5FWDS2h8MpIA9eye5xA8kliBdre7FD384t/jUcTA3A== X-Received: by 2002:a05:6102:2142:: with SMTP id h2mr23725307vsg.27.1571244659605; Wed, 16 Oct 2019 09:50:59 -0700 (PDT) MIME-Version: 1.0 References: <20191015061349.141448-1-wvw@google.com> In-Reply-To: <20191015061349.141448-1-wvw@google.com> From: Amit Kucheria Date: Wed, 16 Oct 2019 22:20:48 +0530 Message-ID: Subject: Re: [PATCH] thermal: create softlink by name for thermal_zone and cooling_device To: Wei Wang Cc: wei.vince.wang@gmail.com, Zhang Rui , Eduardo Valentin , Daniel Lezcano , Linux PM list , LKML 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 Tue, Oct 15, 2019 at 11:43 AM Wei Wang wrote: > > 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. I like this. > 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); This should be a separate fix, if needed. > 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"); Any reason not to use the following form instead? It seems easier to read. if (!cdev_link_kobj) { cdev_link_kobj = kobject_create_and_add("cdev-by-name", cdev->device.kobj.parent); ret = sysfs_create_link(cdev_link_kobj, &cdev->device.kobj, cdev->type)) if (ret) 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"); Same as above. > 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 >