From patchwork Fri Dec 13 02:31:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 22316 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f72.google.com (mail-pb0-f72.google.com [209.85.160.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E1D7023FC9 for ; Fri, 13 Dec 2013 02:32:03 +0000 (UTC) Received: by mail-pb0-f72.google.com with SMTP id jt11sf3093498pbb.3 for ; Thu, 12 Dec 2013 18:32:02 -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=/NndzXW79dbiKqcu5oaDTEJCR1JfgoN2WXBoDMQQZ1E=; b=R2ONQn7Q1Z4iULBfq6PJLRM+375rdV3GQZpbc1T7uTtoLBrp+l0gJQA5/SxjAHw8ST ytfm4h/aDGJ2hUhZ6pRDy/hZWmprHH/KAoxfRf0wOSjHfzt4ublmWLpMrBRMgRcWHyw7 KHuT3IQOnx0M1GFOnWbBcd+cahZ1hnK42JCMBYfXb9AEZrvhUar/zf0MYNcaAU92hmN2 fz47d1SWnku0ChA3E2nPzvm5yudQZ3bG82sh6Uv8TXtlzkFpSAdZOIsW9IRWVbs3TaM8 tbIOnHUMzPqfQarGmfUiZHzx7+X3jgZZlM2BGyeHJzp604kmdxAVNs7IL8/3RirCxJlB dX1g== X-Gm-Message-State: ALoCoQls9ytY28n1PW4PY8O1mRdkDpQXjEc/kCn6WBOidUI4aqa+AMYVNU5gtnGC8qtZOtd/xGea X-Received: by 10.66.141.46 with SMTP id rl14mr67443pab.44.1386901922535; Thu, 12 Dec 2013 18:32:02 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.105.193 with SMTP id go1ls769377qeb.97.gmail; Thu, 12 Dec 2013 18:32:02 -0800 (PST) X-Received: by 10.58.100.244 with SMTP id fb20mr59909veb.6.1386901922301; Thu, 12 Dec 2013 18:32:02 -0800 (PST) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by mx.google.com with ESMTPS id l11si128376vcn.57.2013.12.12.18.32.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Dec 2013 18:32:02 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.176 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.176; Received: by mail-ve0-f176.google.com with SMTP id oz11so945704veb.21 for ; Thu, 12 Dec 2013 18:32:02 -0800 (PST) X-Received: by 10.220.199.5 with SMTP id eq5mr59854vcb.16.1386901922096; Thu, 12 Dec 2013 18:32:02 -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.220.174.196 with SMTP id u4csp3047vcz; Thu, 12 Dec 2013 18:32:01 -0800 (PST) X-Received: by 10.15.26.6 with SMTP id m6mr129634eeu.80.1386901920795; Thu, 12 Dec 2013 18:32:00 -0800 (PST) Received: from mail-ea0-f177.google.com (mail-ea0-f177.google.com [209.85.215.177]) by mx.google.com with ESMTPS id s42si346084eew.182.2013.12.12.18.32.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 12 Dec 2013 18:32:00 -0800 (PST) Received-SPF: neutral (google.com: 209.85.215.177 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=209.85.215.177; Received: by mail-ea0-f177.google.com with SMTP id n15so589173ead.36 for ; Thu, 12 Dec 2013 18:32:00 -0800 (PST) X-Received: by 10.15.77.134 with SMTP id p6mr190180eey.0.1386901920242; Thu, 12 Dec 2013 18:32:00 -0800 (PST) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id m1sm1400053eeg.0.2013.12.12.18.31.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Dec 2013 18:31:59 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Cc: patches@linaro.org, ian.campbell@citrix.com, tim@xen.org, stefano.stabellini@citrix.com, tsahee@gmx.com, Julien Grall Subject: [PATCH] xen/dts: Don't translate invalid address Date: Fri, 13 Dec 2013 02:31:50 +0000 Message-Id: <1386901910-1016-1-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 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.176 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 --- 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. --- xen/common/device_tree.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 84e709d..9b9a348 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -93,7 +93,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 *parent); 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); @@ -793,6 +793,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 *parent) +{ + /* Root node doesn't have "ranges" property */ + if ( parent->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(parent, "ranges", NULL) != NULL); +} + static void dt_bus_default_count_cells(const struct dt_device_node *dev, int *addrc, int *sizec) { @@ -819,7 +831,7 @@ static u64 dt_bus_default_map(__be32 *addr, const __be32 *range, * If the number of address cells is larger than 2 we assume the * mapping doesn't specify a physical address. Rather, the address * specifies an identifier that must match exactly. - */ + */ if ( na > 2 && memcmp(range, addr, na * 4) != 0 ) return DT_BAD_ADDR; @@ -856,7 +868,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, @@ -871,7 +883,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; } @@ -890,7 +901,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) ) @@ -994,6 +1008,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); @@ -1026,6 +1042,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) ) { @@ -1164,6 +1185,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) )