From patchwork Thu May 22 23:36:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 30763 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f70.google.com (mail-oa0-f70.google.com [209.85.219.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2BF252066E for ; Fri, 23 May 2014 12:51:15 +0000 (UTC) Received: by mail-oa0-f70.google.com with SMTP id i4sf23019551oah.1 for ; Fri, 23 May 2014 05:51:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=z1Y2Y/zWScobN3ASnv2Vjz0wY17fRawi/V4gX4iNIEw=; b=EKPHak4V4Wn4JlCcVZiq1L9xVKTC5n1wL3H9xYSd6Gj+YMyvIncf3S/hDsollL3vh8 pUu4pYlhf3QJDY+2n0DQsIoCHNE6G/2nhs939ZE5PPzRAEaOT82bAvn7esbFXpfc2Yd4 +SXGM9B6d1xnK2lZI2MFJO8fB3ozuc5u7UNMuUrSHI0wT2hmT57bDLu2+EX8SaIbaqIo n6R4nYP+n9PPh4xBIXMPvqJhR1lh58jAFdssvB/MaMMw8M3CkVraqwLaz/YLEDoYCd54 oEHdM8Ma0l3Ktmg0U94OHbDJczvXkabhK4i1mTqIcw1/KXmkDhgdQNW0HYEFoH3yBr7J erbg== X-Gm-Message-State: ALoCoQmarv0FdHJqoGQ3g753JFi+MsJNjk8J1I3gktlnHXJkqFOdQyzWhEm3nwZ+OaSI+xYH70OP X-Received: by 10.182.103.199 with SMTP id fy7mr2135079obb.18.1400849474415; Fri, 23 May 2014 05:51:14 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.104.49 with SMTP id z46ls1818177qge.50.gmail; Fri, 23 May 2014 05:51:14 -0700 (PDT) X-Received: by 10.220.95.204 with SMTP id e12mr997243vcn.37.1400849474295; Fri, 23 May 2014 05:51:14 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id za4si1539133vdb.43.2014.05.23.05.51.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 23 May 2014 05:51:14 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.177 as permitted sender) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id db11so6153527veb.36 for ; Fri, 23 May 2014 05:51:14 -0700 (PDT) X-Received: by 10.52.35.69 with SMTP id f5mr154270vdj.83.1400849474210; Fri, 23 May 2014 05:51:14 -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.220.221.72 with SMTP id ib8csp28932vcb; Fri, 23 May 2014 05:51:13 -0700 (PDT) X-Received: by 10.68.250.3 with SMTP id yy3mr5821879pbc.56.1400849473423; Fri, 23 May 2014 05:51:13 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ew3si3736020pac.229.2014.05.23.05.51.12; Fri, 23 May 2014 05:51:12 -0700 (PDT) Received-SPF: none (google.com: devicetree-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752499AbaEWMvL (ORCPT + 8 others); Fri, 23 May 2014 08:51:11 -0400 Received: from mail-wg0-f50.google.com ([74.125.82.50]:49149 "EHLO mail-wg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751790AbaEWMvK (ORCPT ); Fri, 23 May 2014 08:51:10 -0400 Received: by mail-wg0-f50.google.com with SMTP id x12so4900654wgg.9 for ; Fri, 23 May 2014 05:51:09 -0700 (PDT) X-Received: by 10.194.87.200 with SMTP id ba8mr4169325wjb.28.1400849469476; Fri, 23 May 2014 05:51:09 -0700 (PDT) Received: from trevor.secretlab.ca ([37.205.61.203]) by mx.google.com with ESMTPSA id vp5sm3797397wjc.31.2014.05.23.05.51.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 May 2014 05:51:05 -0700 (PDT) Received: by trevor.secretlab.ca (Postfix, from userid 1000) id D4EA9C40BF1; Fri, 23 May 2014 08:36:18 +0900 (JST) From: Grant Likely To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Grant Likely , Ezequiel Garcia , Rob Herring Subject: [PATCH v2 1/2] of: Ensure unique names without sacrificing determinism Date: Fri, 23 May 2014 08:36:08 +0900 Message-Id: <1400801769-4506-2-git-send-email-grant.likely@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1400801769-4506-1-git-send-email-grant.likely@linaro.org> References: <1400801769-4506-1-git-send-email-grant.likely@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: grant.likely@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.128.177 as permitted sender) smtp.mail=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: , The way the driver core is implemented, every device using the same bus type is required to have a unique name because a symlink to each device is created in the appropriate /sys/bus/*/devices directory, and two identical names causes a collision. The current code handles the requirement by using an globally incremented counter that is appended to the device name. It works, but it means any change to device registration will change the assigned numbers. Instead, if we build up the name by using information from the parent nodes, then it can be guaranteed to be unique without adding a random number to the end of it. Signed-off-by: Grant Likely Cc: Ezequiel Garcia Cc: Rob Herring Acked-by: Rob Herring Tested-by: Ezequiel Garcia --- drivers/of/platform.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index d0009b3614af..95c133a0554b 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -68,17 +68,15 @@ EXPORT_SYMBOL(of_find_device_by_node); * of_device_make_bus_id - Use the device node data to assign a unique name * @dev: pointer to device structure that is linked to a device tree node * - * This routine will first try using either the dcr-reg or the reg property - * value to derive a unique name. As a last resort it will use the node - * name followed by a unique number. + * This routine will first try using the translated bus address to + * derive a unique name. If it cannot, then it will prepend names from + * parent nodes until a unique name can be derived. */ void of_device_make_bus_id(struct device *dev) { - static atomic_t bus_no_reg_magic; struct device_node *node = dev->of_node; const __be32 *reg; u64 addr; - int magic; #ifdef CONFIG_PPC_DCR /* @@ -100,25 +98,25 @@ void of_device_make_bus_id(struct device *dev) } #endif /* CONFIG_PPC_DCR */ - /* - * For MMIO, get the physical address - */ - reg = of_get_property(node, "reg", NULL); - if (reg) { - addr = of_translate_address(node, reg); - if (addr != OF_BAD_ADDR) { - dev_set_name(dev, "%llx.%s", - (unsigned long long)addr, node->name); + /* Construct the name, using parent nodes if necessary to ensure uniqueness */ + while (node->parent) { + /* + * If the address can be translated, then that is as much + * uniqueness as we need. Make it the first component and return + */ + reg = of_get_property(node, "reg", NULL); + if (reg && (addr = of_translate_address(node, reg)) != OF_BAD_ADDR) { + dev_set_name(dev, dev_name(dev) ? "%llx.%s:%s" : "%llx.%s", + (unsigned long long)addr, node->name, + dev_name(dev)); return; } - } - /* - * No BusID, use the node name and add a globally incremented - * counter (and pray...) - */ - magic = atomic_add_return(1, &bus_no_reg_magic); - dev_set_name(dev, "%s.%d", node->name, magic - 1); + /* format arguments only used if dev_name() resolves to NULL */ + dev_set_name(dev, dev_name(dev) ? "%s:%s" : "%s", + strrchr(node->full_name, '/') + 1, dev_name(dev)); + node = node->parent; + } } /**