From patchwork Thu Apr 9 15:09:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 46955 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 49FE921416 for ; Thu, 9 Apr 2015 15:14:48 +0000 (UTC) Received: by widjs5 with SMTP id js5sf18071756wid.3 for ; Thu, 09 Apr 2015 08:14:47 -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:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=t/ehjwoVEWlXKD3ZlK4kv8tIzlCkUun2DAAPWNhDeM4=; b=LV6520zySOUJKGh45QAhuso6WTWFXRyl6GXBZxLxeiFopd6M7aIMRtv7O5G3Ir85wZ RXhLp3Z1L27jpWCyf5KWhoTBwm0e409t5LuXMAUDFLlH3NhIqkNjnSi2exnBTBooSSFG Utc3p1oxsIShnketlEY63iqZ3qe9C4lp3HLGX4Aw5GMX2M9P3xvH3Kyb2AFRtpVkzJDf RUYHOvfBdvUIqAuuI1fJf2g78IKm0vXNBS6bayjN9lKoDlbNGfzIOAq8fmwhmxLqpUXt WVpfeojK5yoQ8OffJ1TLO6n8Yt+Woj4+cQB+eSTyiqRVN7P4SzP4HYgNLIx8/yMjefEs QpFg== X-Gm-Message-State: ALoCoQnMhWLr+tF/K3E/C60u7gVoKrJBdx7Or9MuYNCeh0yNHs0LT1inCl8UO6MjmM+EfW5FA0/4 X-Received: by 10.194.236.196 with SMTP id uw4mr6056645wjc.5.1428592487556; Thu, 09 Apr 2015 08:14:47 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.202.133 with SMTP id ki5ls337339lac.90.gmail; Thu, 09 Apr 2015 08:14:47 -0700 (PDT) X-Received: by 10.112.170.132 with SMTP id am4mr28427433lbc.89.1428592487422; Thu, 09 Apr 2015 08:14:47 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id g17si11693730lbh.17.2015.04.09.08.14.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2015 08:14:47 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by laat2 with SMTP id t2so84882257laa.1 for ; Thu, 09 Apr 2015 08:14:47 -0700 (PDT) X-Received: by 10.152.116.11 with SMTP id js11mr4924589lab.106.1428592487187; Thu, 09 Apr 2015 08:14:47 -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.67.65 with SMTP id l1csp533076lbt; Thu, 9 Apr 2015 08:14:45 -0700 (PDT) X-Received: by 10.140.233.140 with SMTP id e134mr16837008qhc.63.1428592484048; Thu, 09 Apr 2015 08:14:44 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id 145si5767618qhx.10.2015.04.09.08.14.43 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 09 Apr 2015 08:14:44 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YgE8m-00008m-JE; Thu, 09 Apr 2015 15:13:12 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YgE8l-00008P-A0 for xen-devel@lists.xenproject.org; Thu, 09 Apr 2015 15:13:11 +0000 Received: from [85.158.139.211] by server-1.bemta-5.messagelabs.com id 88/18-20070-60796255; Thu, 09 Apr 2015 15:13:10 +0000 X-Env-Sender: julien.grall@citrix.com X-Msg-Ref: server-7.tower-206.messagelabs.com!1428592386!14820383!2 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 6.13.6; banners=-,-,- X-VirusChecked: Checked Received: (qmail 31773 invoked from network); 9 Apr 2015 15:13:10 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-7.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 9 Apr 2015 15:13:10 -0000 X-IronPort-AV: E=Sophos;i="5.11,550,1422921600"; d="scan'208";a="251719354" From: Julien Grall To: Date: Thu, 9 Apr 2015 16:09:32 +0100 Message-ID: <1428592185-18581-7-git-send-email-julien.grall@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1428592185-18581-1-git-send-email-julien.grall@citrix.com> References: <1428592185-18581-1-git-send-email-julien.grall@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com Subject: [Xen-devel] [PATCH v5 p2 06/19] xen/dts: Provide an helper to get a DT node from a path provided by a guest X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: patch@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.45 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-Archive: From: Julien Grall The maximum size of the copied string has been chosen based on the value use by XSM in similar case. Furthermore, Linux seems to allow path up to 4096 characters. Though this could vary from one OS to another. Signed-off-by: Julien Grall --- Changes in v4: - Drop DEVICE_TREE_MAX_PATHLEN - Bump the value to PAGE_SIZE (i.e 4096). It's used in XSM and this value seems sensible for Linux - Clarify how the maximum size has been chosen Changes in v3: - Use the new prototype of safe_copy_string_from_guest Changes in v2: - guest_copy_string_from_guest has been renamed into safe_copy_string_from_guest --- xen/common/device_tree.c | 18 ++++++++++++++++++ xen/include/xen/device_tree.h | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 02cae91..31f169b 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,7 @@ #include #include #include +#include const void *device_tree_flattened; dt_irq_xlate_func dt_irq_xlate; @@ -277,6 +279,22 @@ struct dt_device_node *dt_find_node_by_path(const char *path) return np; } +int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen, + struct dt_device_node **node) +{ + char *path; + + path = safe_copy_string_from_guest(u_path, u_plen, PAGE_SIZE); + if ( IS_ERR(path) ) + return PTR_ERR(path); + + *node = dt_find_node_by_path(path); + + xfree(path); + + return (*node == NULL) ? -ESRCH : 0; +} + struct dt_device_node *dt_find_node_by_alias(const char *alias) { const struct dt_alias_prop *app; diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 57eb3ee..e187780 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -456,6 +456,20 @@ struct dt_device_node *dt_find_node_by_alias(const char *alias); */ struct dt_device_node *dt_find_node_by_path(const char *path); + +/** + * dt_find_node_by_gpath - Same as dt_find_node_by_path but retrieve the + * path from the guest + * + * @u_path: Xen Guest handle to the buffer containing the path + * @u_plen: Length of the buffer + * @node: TODO + * + * Return 0 if succeed otherwise -errno + */ +int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen, + struct dt_device_node **node); + /** * dt_get_parent - Get a node's parent if any * @node: Node to get parent