From patchwork Tue Aug 11 06:35:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 52280 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by patches.linaro.org (Postfix) with ESMTPS id ADD8D2152A for ; Tue, 11 Aug 2015 06:36:03 +0000 (UTC) Received: by wijp15 with SMTP id p15sf45835842wij.3 for ; Mon, 10 Aug 2015 23:36:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:cc:subject:message-id :references:mime-version:content-type:content-disposition :in-reply-to:user-agent:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=OGCI/lztWRiRPtAERdHitin65XIzoMRNgmLclW8g44o=; b=F3NfkADyiZv1j/mfjMjFd486qckDSxGKcFfmreXaEGId2MLcedbSoLjCl04imP/kVH d6F17ZLq9r43PsvZ3qJ5PAxALaBbUZUQuhg9voKw8l0KpbXWpjiudSpl62Hpfu/FafZL 2AWDmpVACqgCk+hm/Mj98ZJ58ltpvZMtM5r9F+nAwiDCGvLWl/AF/llK0KsNs4QtfAqa TDb8dLLC/KSVPJU4cOn0zfvpxUmi2VqNog/5HLtd3n7F2S+e1bR3xExhoWCBQxWq4z0f Lf0Gm6j/nklh7FvKhK7ht7PKUkWxOqQ4IxYJstbwFwX0nBPKWXdEFbwodcVxdtIPuDp5 GHRw== X-Gm-Message-State: ALoCoQnCKuFYvmge0l7/agSPOe+a88f0g/VAaY07kayWouMy83Vol7tEQEmHKXC3n2UsbgWzdPRq X-Received: by 10.152.28.100 with SMTP id a4mr7480585lah.4.1439274963004; Mon, 10 Aug 2015 23:36:03 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.20.69 with SMTP id l5ls835390lae.73.gmail; Mon, 10 Aug 2015 23:36:02 -0700 (PDT) X-Received: by 10.152.8.233 with SMTP id u9mr2974088laa.8.1439274962823; Mon, 10 Aug 2015 23:36:02 -0700 (PDT) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id us13si611226lbb.12.2015.08.10.23.36.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Aug 2015 23:36:02 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by labd1 with SMTP id d1so51933628lab.1 for ; Mon, 10 Aug 2015 23:36:02 -0700 (PDT) X-Received: by 10.152.120.135 with SMTP id lc7mr24231534lab.41.1439274962666; Mon, 10 Aug 2015 23:36:02 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.7.198 with SMTP id l6csp2322084lba; Mon, 10 Aug 2015 23:36:01 -0700 (PDT) X-Received: by 10.70.54.196 with SMTP id l4mr53174005pdp.42.1439274961477; Mon, 10 Aug 2015 23:36:01 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ag8si1641296pbd.210.2015.08.10.23.36.00; Mon, 10 Aug 2015 23:36:01 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755294AbbHKGf7 (ORCPT + 28 others); Tue, 11 Aug 2015 02:35:59 -0400 Received: from mail-pa0-f51.google.com ([209.85.220.51]:35211 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754977AbbHKGf5 (ORCPT ); Tue, 11 Aug 2015 02:35:57 -0400 Received: by pacgr6 with SMTP id gr6so43870741pac.2 for ; Mon, 10 Aug 2015 23:35:57 -0700 (PDT) X-Received: by 10.66.196.15 with SMTP id ii15mr52631019pac.108.1439274956908; Mon, 10 Aug 2015 23:35:56 -0700 (PDT) Received: from localhost ([223.227.191.36]) by smtp.gmail.com with ESMTPSA id ud2sm1164186pbc.57.2015.08.10.23.35.53 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 10 Aug 2015 23:35:56 -0700 (PDT) Date: Tue, 11 Aug 2015 12:05:49 +0530 From: Viresh Kumar To: Stephen Boyd Cc: Rafael Wysocki , nm@ti.com, linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, khilman@linaro.org, Bartlomiej Zolnierkiewicz , Dmitry Torokhov , Greg Kroah-Hartman , Len Brown , open list , Pavel Machek Subject: Re: [PATCH 6/6] PM / OPP: Add debugfs support Message-ID: <20150811063549.GB5147@linux> References: <8a238dcc3bdef28aa9fc3f68787a84449c6ff17a.1439187821.git.viresh.kumar@linaro.org> <20150810195009.GE9678@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150810195009.GE9678@codeaurora.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On 10-08-15, 12:50, Stephen Boyd wrote: > > + /* Create device specific directory link */ > > + d = debugfs_create_symlink(dev_name(dev), rootdir, > > The dev_name thing is going to fail. Eventually we'll get into a > situation where two devices with the same name on different > busses have OPPs. When we add them to debugfs their names are > going to conflict. The regulator core suffered this problem, see > commit a9eaa8130707 (regulator: Ensure unique regulator debugfs > directory names, 2014-10-17) for one solution. The regulator core had a slightly different problem probably as it was assigning similar names to devices of same type. And we may not hit it. But still, I have prefixed it with parent name to make it look slightly stronger :) Diff with earlier patch (only compile tested for now, don't have access to setup currently): --- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index b3af1825266a..871502dec381 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -679,7 +679,7 @@ static int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, new_opp->dev_opp = dev_opp; list_add_rcu(&new_opp->node, head); - ret = opp_debug_create_one(new_opp, dev_opp->dentry); + ret = opp_debug_create_one(new_opp, dev_opp); if (ret) dev_err(dev, "%s: Failed to register opp to debugfs (%d)\n", __func__, ret); diff --git a/drivers/base/power/opp/debugfs.c b/drivers/base/power/opp/debugfs.c index d4e18eac8278..6c048bfbf954 100644 --- a/drivers/base/power/opp/debugfs.c +++ b/drivers/base/power/opp/debugfs.c @@ -17,13 +17,24 @@ static struct dentry *rootdir; +static void opp_set_dev_name(const struct device *dev, char *name) +{ + + if (dev->parent) + snprintf(name, NAME_MAX, "%s-%s", dev_name(dev->parent), + dev_name(dev)); + else + snprintf(name, NAME_MAX, "%s", dev_name(dev)); +} + void opp_debug_remove_one(struct dev_pm_opp *opp) { debugfs_remove_recursive(opp->dentry); } -int opp_debug_create_one(struct dev_pm_opp *opp, struct dentry *pdentry) +int opp_debug_create_one(struct dev_pm_opp *opp, struct device_opp *dev_opp) { + struct dentry *pdentry = dev_opp->dentry; struct dentry *d; char name[15]; @@ -75,10 +86,12 @@ static int device_opp_debug_create_dir(struct device_list_opp *list_dev, struct device_opp *dev_opp) { const struct device *dev = list_dev->dev; - struct dentry *d = NULL; + struct dentry *d; + + opp_set_dev_name(dev, dev_opp->dentry_name); /* Create device specific directory */ - d = debugfs_create_dir(dev_name(dev), rootdir); + d = debugfs_create_dir(dev_opp->dentry_name, rootdir); if (!d) { dev_err(dev, "%s: Failed to create debugfs dir\n", __func__); return -ENOMEM; @@ -86,7 +99,6 @@ static int device_opp_debug_create_dir(struct device_list_opp *list_dev, list_dev->dentry = d; dev_opp->dentry = d; - dev_opp->debugfs_dev = dev; return 0; } @@ -95,11 +107,13 @@ static int device_opp_debug_create_link(struct device_list_opp *list_dev, struct device_opp *dev_opp) { const struct device *dev = list_dev->dev; - struct dentry *d = NULL; + char name[NAME_MAX]; + struct dentry *d; + + opp_set_dev_name(list_dev->dev, name); /* Create device specific directory link */ - d = debugfs_create_symlink(dev_name(dev), rootdir, - dev_name(dev_opp->debugfs_dev)); + d = debugfs_create_symlink(name, rootdir, dev_opp->dentry_name); if (!d) { dev_err(dev, "%s: Failed to create link\n", __func__); return -ENOMEM; @@ -135,6 +149,36 @@ int opp_debug_register(struct device_list_opp *list_dev, return device_opp_debug_create_dir(list_dev, dev_opp); } +static void opp_migrate_dentry(struct device_list_opp *list_dev, + struct device_opp *dev_opp) +{ + struct device_list_opp *new_dev; + const struct device *dev; + struct dentry *dentry; + + /* Look for next list-dev */ + list_for_each_entry(new_dev, &dev_opp->dev_list, node) + if (new_dev != list_dev) + break; + + /* new_dev is guaranteed to be valid here */ + dev = new_dev->dev; + debugfs_remove_recursive(new_dev->dentry); + + opp_set_dev_name(dev, dev_opp->dentry_name); + + dentry = debugfs_rename(rootdir, list_dev->dentry, rootdir, + dev_opp->dentry_name); + if (!dentry) { + dev_err(dev, "%s: Failed to rename link from: %s to %s\n", + __func__, dev_name(list_dev->dev), dev_name(dev)); + return; + } + + new_dev->dentry = dentry; + dev_opp->dentry = dentry; +} + /** * opp_debug_unregister - remove a device opp node from debugfs opp directory * @list_dev: list-dev pointer for device @@ -145,9 +189,18 @@ int opp_debug_register(struct device_list_opp *list_dev, void opp_debug_unregister(struct device_list_opp *list_dev, struct device_opp *dev_opp) { - debugfs_remove_recursive(list_dev->dentry); - if (list_dev->dentry == dev_opp->dentry) + if (list_dev->dentry == dev_opp->dentry) { + /* Move the real dentry object under another device */ + if (!list_is_singular(&dev_opp->dev_list)) { + opp_migrate_dentry(list_dev, dev_opp); + goto out; + } dev_opp->dentry = NULL; + } + + debugfs_remove_recursive(list_dev->dentry); + +out: list_dev->dentry = NULL; } diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h index 8eb6a9a098a1..0e4c27fb0c4a 100644 --- a/drivers/base/power/opp/opp.h +++ b/drivers/base/power/opp/opp.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -83,8 +84,10 @@ struct dev_pm_opp { struct device_node *np; +#ifdef CONFIG_DEBUG_FS /* debugfs */ struct dentry *dentry; +#endif }; /** @@ -102,8 +105,10 @@ struct device_list_opp { const struct device *dev; struct rcu_head rcu_head; +#ifdef CONFIG_DEBUG_FS /* debugfs */ struct dentry *dentry; +#endif }; /** @@ -120,7 +125,7 @@ struct device_list_opp { * @np: struct device_node pointer for opp's DT node. * @shared_opp: OPP is shared between multiple devices. * @dentry: debugfs dentry pointer of the real device directory (not links). - * @debugfs_dev: Pointer to device for which the real directory was created. + * @dentry_name: Name of the real dentry. * * This is an internal data structure maintaining the link to opps attached to * a device. This structure is not meant to be shared to users as it is @@ -143,9 +148,11 @@ struct device_opp { bool shared_opp; struct dev_pm_opp *suspend_opp; +#ifdef CONFIG_DEBUG_FS /* debugfs */ struct dentry *dentry; - const struct device *debugfs_dev; + char dentry_name[NAME_MAX]; +#endif }; /* Routines internal to opp core */ @@ -156,7 +163,7 @@ struct device_node *_of_get_opp_desc_node(struct device *dev); #ifdef CONFIG_DEBUG_FS void opp_debug_remove_one(struct dev_pm_opp *opp); -int opp_debug_create_one(struct dev_pm_opp *opp, struct dentry *pdentry); +int opp_debug_create_one(struct dev_pm_opp *opp, struct device_opp *dev_opp); int opp_debug_register(struct device_list_opp *list_dev, struct device_opp *dev_opp); void opp_debug_unregister(struct device_list_opp *list_dev, @@ -165,7 +172,7 @@ void opp_debug_unregister(struct device_list_opp *list_dev, static inline void opp_debug_remove_one(struct dev_pm_opp *opp) {} static inline int opp_debug_create_one(struct dev_pm_opp *opp, - struct dentry *pdentry) + struct device_opp *dev_opp) { return 0; } static inline int opp_debug_register(struct device_list_opp *list_dev, struct device_opp *dev_opp)