From patchwork Wed Aug 28 14:47:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 19578 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0B0AC25E58 for ; Wed, 28 Aug 2013 14:48:29 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id c41sf7127516yho.2 for ; Wed, 28 Aug 2013 07:48:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=epcOD8XlpVQ7BgnMhnf53PMwQ5YQU612cUBrWYBjDPM=; b=mMoEzZrce77FptTH5xCFdKIvNL3BM1DOqzM3yRJIlhddwM9oCrRM+bEbnTcXhWcUcJ MzzOyIuvwpaXvsPtHU8pFoEMWs9fI+XNhc0ihjahOLh52nBaQgsqzkwL5OJfbqHvmH53 L/Kkkr+JzQUKFRtNWLwZR+TtJmJy9TDrp21JzkSaoWarv2QgJYAVQkKeD35ciDGdgV72 b2M91X85l2/suNMf1sHMETP6A00I29eORJRFJxkFnx7F0iwfK9sYvWVfJx4ATWVkLIIS QcYdGSRx7m+KcrCIxK3S6Y1qSLXjm3G+xvud0tj3lRyrHZyWTHPiQE8s+ZnkhKqMPuQI Vwcw== X-Received: by 10.236.66.244 with SMTP id h80mr2605393yhd.30.1377701308828; Wed, 28 Aug 2013 07:48:28 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.82.114 with SMTP id h18ls411086qey.12.gmail; Wed, 28 Aug 2013 07:48:28 -0700 (PDT) X-Received: by 10.52.170.111 with SMTP id al15mr280432vdc.43.1377701308724; Wed, 28 Aug 2013 07:48:28 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id gn1si6624275vec.67.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 28 Aug 2013 07:48:28 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id id13so4253469vcb.32 for ; Wed, 28 Aug 2013 07:48:28 -0700 (PDT) X-Gm-Message-State: ALoCoQnFFC5dow416a8XsydsVt4E/L424Ww0WXTw5MQ++1H668/8Su/9qy9TZcGMoe67SwMnxcQG X-Received: by 10.58.171.4 with SMTP id aq4mr1314210vec.26.1377701308652; Wed, 28 Aug 2013 07:48:28 -0700 (PDT) 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 u4csp359956vcz; Wed, 28 Aug 2013 07:48:28 -0700 (PDT) X-Received: by 10.194.134.97 with SMTP id pj1mr3034238wjb.58.1377701305995; Wed, 28 Aug 2013 07:48:25 -0700 (PDT) Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com [209.85.212.182]) by mx.google.com with ESMTPS id cl6si9501347wjc.145.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 28 Aug 2013 07:48:25 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.182 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=209.85.212.182; Received: by mail-wi0-f182.google.com with SMTP id ey11so3298157wid.3 for ; Wed, 28 Aug 2013 07:48:25 -0700 (PDT) X-Received: by 10.195.12.170 with SMTP id er10mr20703766wjd.5.1377701305472; Wed, 28 Aug 2013 07:48:25 -0700 (PDT) Received: from belegaer.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id a8sm5590498wie.6.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 28 Aug 2013 07:48:23 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Cc: stefano.stabellini@eu.citrix.com, ian.campbell@citrix.com, patches@linaro.org, andre.przywara@linaro.org, Julien Grall Subject: [PATCH V1 15/29] xen/arm: Use dt_device_match to avoid multiple if conditions Date: Wed, 28 Aug 2013 15:47:29 +0100 Message-Id: <1377701263-3319-16-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1377701263-3319-1-git-send-email-julien.grall@linaro.org> References: <1377701263-3319-1-git-send-email-julien.grall@linaro.org> 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.220.173 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: , There is some place in Xen ARM code where multiple if conditions is used check the presence of a node or find a node. These pieces of code can be replace by an array and using proper device tree helpers. Signed-off-by: Julien Grall Acked-by: Ian Campbell --- Changes in v2: - Move skip_match and timer_ids within the appropriate functions --- xen/arch/arm/domain_build.c | 13 ++++++++++--- xen/arch/arm/time.c | 10 +++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 345f0f7..eb8b662 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -437,15 +437,22 @@ static int map_device(struct domain *d, const struct dt_device_node *dev) static int handle_node(struct domain *d, const struct dt_device_node *np) { + static const struct dt_device_match skip_matches[] __initconst = + { + DT_MATCH_COMPATIBLE("xen,xen"), + DT_MATCH_TYPE("memory"), + DT_MATCH_PATH("/chosen"), + { /* sentinel */ }, + }; const struct dt_device_node *child; int res; + + DPRINT("handle %s\n", dt_node_full_name(np)); /* Skip theses nodes and the sub-nodes */ - if ( dt_device_is_compatible(np, "xen,xen") || - dt_device_type_is_equal(np, "memory") || - !strcmp("/chosen", dt_node_full_name(np)) ) + if ( dt_match_node(skip_matches, np ) ) return 0; if ( dt_device_used_by(np) != DOMID_XEN ) diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c index 9c176cd..8125b92 100644 --- a/xen/arch/arm/time.c +++ b/xen/arch/arm/time.c @@ -101,14 +101,18 @@ static uint32_t calibrate_timer(void) /* Set up the timer on the boot CPU */ int __init init_xen_time(void) { + static const struct dt_device_match timer_ids[] __initconst = + { + DT_MATCH_COMPATIBLE("arm,armv7-timer"), + DT_MATCH_COMPATIBLE("arm,armv8-timer"), + { /* sentinel */ }, + }; struct dt_device_node *dev; int res; unsigned int i; u32 rate; - dev = dt_find_compatible_node(NULL, NULL, "arm,armv7-timer"); - if ( !dev ) - dev = dt_find_compatible_node(NULL, NULL, "arm,armv8-timer"); + dev = dt_find_matching_node(NULL, timer_ids); if ( !dev ) panic("Unable to find a compatible timer in the device tree\n");