From patchwork Mon Jan 6 16:36:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 22894 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-gg0-f197.google.com (mail-gg0-f197.google.com [209.85.161.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4AFC6218DC for ; Mon, 6 Jan 2014 16:36:30 +0000 (UTC) Received: by mail-gg0-f197.google.com with SMTP id e5sf22054744ggh.8 for ; Mon, 06 Jan 2014 08:36:29 -0800 (PST) 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:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=y3k4NKzAoqL5ReBn5KEJhItRYtTANNEQvlCm5MNqE4U=; b=mnYwZJaMYQHoltm5O+wwsFZfJrz2f1eyD8vy8m45aAs0gokuNj99M3ufhgQYqYiDx5 pVeP9r/bHd8zdm+jLmESmpeazVlA/Hx+7YgolQEH3dvQBljCPAfZqAFE/hdmbJKSn6sg Ezl/2oY1ArTcox9kr+XxSYy1O7AYcWsEMKCkrgdF0UR0OKCCMbwNdfdlKZEULHz17FtE aOqMCLLBVF1+IA4FHsmWlSGPTtMFwrP1GXBASjkl4XyvCtLIeSPDLVYczlVicforK7fN HRO+tHZwLpKKqHBgXNxT02PA3gpGscAGRwVHSrTgITKwko620bDadaHMUgkebX5kxPN0 Vk0A== X-Gm-Message-State: ALoCoQk9aOx5sC5GdVxL2PsckeJ8Zd+6aocFoayrCC8XQh9EcfhsGLjmEyfUqJ6p5bwBWU+1q7Ts X-Received: by 10.58.171.135 with SMTP id au7mr47399819vec.22.1389026189042; Mon, 06 Jan 2014 08:36:29 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.49.10 with SMTP id q10ls5852953qen.0.gmail; Mon, 06 Jan 2014 08:36:28 -0800 (PST) X-Received: by 10.58.7.1 with SMTP id f1mr40913028vea.15.1389026188954; Mon, 06 Jan 2014 08:36:28 -0800 (PST) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id tj7si31447980vdc.7.2014.01.06.08.36.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 06 Jan 2014 08:36:28 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id jw12so9372189veb.31 for ; Mon, 06 Jan 2014 08:36:28 -0800 (PST) X-Received: by 10.58.146.5 with SMTP id sy5mr3136507veb.43.1389026188826; Mon, 06 Jan 2014 08:36:28 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.59.13.131 with SMTP id ey3csp106937ved; Mon, 6 Jan 2014 08:36:28 -0800 (PST) X-Received: by 10.112.219.99 with SMTP id pn3mr42232255lbc.24.1389026187515; Mon, 06 Jan 2014 08:36:27 -0800 (PST) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com [209.85.217.169]) by mx.google.com with ESMTPS id ww4si36583449lbb.42.2014.01.06.08.36.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 06 Jan 2014 08:36:27 -0800 (PST) Received-SPF: neutral (google.com: 209.85.217.169 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=209.85.217.169; Received: by mail-lb0-f169.google.com with SMTP id u14so10165156lbd.0 for ; Mon, 06 Jan 2014 08:36:26 -0800 (PST) X-Received: by 10.112.64.10 with SMTP id k10mr562758lbs.86.1389026186811; Mon, 06 Jan 2014 08:36:26 -0800 (PST) Received: from localhost.localdomain ([195.69.49.131]) by mx.google.com with ESMTPSA id r10sm55382913lag.7.2014.01.06.08.36.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jan 2014 08:36:26 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Cc: ian.campbell@citrix.com, tim@xen.org, patches@linaro.org, stefano.stabellini@eu.citrix.com, Julien Grall Subject: [PATCH v2] xen/dts: Don't translate invalid address Date: Mon, 6 Jan 2014 16:36:18 +0000 Message-Id: <1389026178-8792-1-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.8.3.1 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , ePAR specifies that if the property "ranges" doesn't exist in a bus node: "it is assumed that no mapping exists between children of node and the parent address space". Modify dt_number_of_address to check if the list of ranges are valid. Return 0 (ie there is zero range) if the list is not valid. This patch has been tested on the Arndale where the bug can occur with the '/hdmi' node. Reported-by: Signed-off-by: Julien Grall Acked-by: Ian Campbell --- This patch is a bug fix for Xen 4.4. Without it, Xen can't boot on the Arndale because it's unable to translate a wrong address. Changes in v2: - "parent" name is very confusing, rename it in "node" - remove spurious change --- xen/common/device_tree.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index c35aee1..fa9d06c 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -83,7 +83,7 @@ struct dt_bus { const char *name; const char *addresses; - int (*match)(const struct dt_device_node *parent); + bool_t (*match)(const struct dt_device_node *node); void (*count_cells)(const struct dt_device_node *child, int *addrc, int *sizec); u64 (*map)(__be32 *addr, const __be32 *range, int na, int ns, int pna); @@ -783,6 +783,18 @@ int dt_n_size_cells(const struct dt_device_node *np) /* * Default translator (generic bus) */ +static bool_t dt_bus_default_match(const struct dt_device_node *node) +{ + /* Root node doesn't have "ranges" property */ + if ( node->parent == NULL ) + return 1; + + /* The default bus is only used when the "ranges" property exists. + * Otherwise we can't translate the address + */ + return (dt_get_property(node, "ranges", NULL) != NULL); +} + static void dt_bus_default_count_cells(const struct dt_device_node *dev, int *addrc, int *sizec) { @@ -846,7 +858,7 @@ static const struct dt_bus dt_busses[] = { .name = "default", .addresses = "reg", - .match = NULL, + .match = dt_bus_default_match, .count_cells = dt_bus_default_count_cells, .map = dt_bus_default_map, .translate = dt_bus_default_translate, @@ -861,7 +873,6 @@ static const struct dt_bus *dt_match_bus(const struct dt_device_node *np) for ( i = 0; i < ARRAY_SIZE(dt_busses); i++ ) if ( !dt_busses[i].match || dt_busses[i].match(np) ) return &dt_busses[i]; - BUG(); return NULL; } @@ -880,7 +891,10 @@ static const __be32 *dt_get_address(const struct dt_device_node *dev, parent = dt_get_parent(dev); if ( parent == NULL ) return NULL; + bus = dt_match_bus(parent); + if ( !bus ) + return NULL; bus->count_cells(dev, &na, &ns); if ( !DT_CHECK_ADDR_COUNT(na) ) @@ -984,6 +998,8 @@ static u64 __dt_translate_address(const struct dt_device_node *dev, if ( parent == NULL ) goto bail; bus = dt_match_bus(parent); + if ( !bus ) + goto bail; /* Count address cells & copy address locally */ bus->count_cells(dev, &na, &ns); @@ -1016,6 +1032,11 @@ static u64 __dt_translate_address(const struct dt_device_node *dev, /* Get new parent bus and counts */ pbus = dt_match_bus(parent); + if ( pbus == NULL ) + { + dt_printk("DT: %s is not a valid bus\n", parent->full_name); + break; + } pbus->count_cells(dev, &pna, &pns); if ( !DT_CHECK_COUNTS(pna, pns) ) { @@ -1154,6 +1175,8 @@ unsigned int dt_number_of_address(const struct dt_device_node *dev) return 0; bus = dt_match_bus(parent); + if ( !bus ) + return 0; bus->count_cells(dev, &na, &ns); if ( !DT_CHECK_COUNTS(na, ns) )