[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 5/8] xen/device-tree: Add dt_property_match_string helper


  • To: Rahul Singh <Rahul.Singh@xxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Fri, 11 Dec 2020 13:13:37 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=q8bRTrq8AuDd9McH6n7Uzv/fwPtioBVwO1NcmUkYkFk=; b=IJCp7UhDeebNBTxdrji37lnuXVhy6n/T8AJ25uiV1HdezXEpsujwjWFuExFBX8tFB3fl4acA3bBANuvifg8I+7nUmfzzwUeW+leL8xblQtAik+Q+vTfkd6hmVxks1QDkJQBXUbclQvzpMhByclRMONVAQjSIINNyJARw1Ney6Ac5mDeTbtIBF438JP3ce9W2Sa6xtG/qK/RJf0AxtohF3jk6MBocG1YqV2WrlZexHl96dsL/ztchpcEQBVUidAQ2SuuQIOqN7Bw/RM9J18e7d8d5XchN2gwnht3MysodNtisl5a1C+oesvyYZxNmdiuPwKnc0AURRjMYgQ4cXDiH/Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J/nabH7RjnskT27z5U/0mjFJ85ROMa3Xi9wZrcOwEJsclByOJnDseCnt9KrxNyCwOtpPtwsamZ5kffN2NNY3I2bcIc7Kup8yYqnO8SEn8cYXV7b6WxI/XTsOHGdagWJXwaG/H2FU7e9F0iuSvpRaPLagB2qJXBbKg6F3Q9FUJlcN1B4hKow7dX2a6oD2j3vLv+EAlGT6d6/VeeBXyIWAbqrQcnyymqPXqHA/0pS0ebhAtv8ElXAoVAeo5cE1u6268UGgr1MFUND+5GlyDatdTbzL2DKiIrGnjI85GdTnVHCIUWgezu6PLbDx10nawvww56hXF/La67A3oUvIIsLXow==
  • Authentication-results-original: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=arm.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>
  • Delivery-date: Fri, 11 Dec 2020 13:14:07 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHWzxXuqdpi5XA8kUmigr++gHdisqnx4LEA
  • Thread-topic: [PATCH v3 5/8] xen/device-tree: Add dt_property_match_string helper

Hi,

> On 10 Dec 2020, at 16:57, Rahul Singh <Rahul.Singh@xxxxxxx> wrote:
> 
> Import the Linux helper of_property_match_string. This function searches
> a string list property and returns the index of a specific string value.
> 
> Signed-off-by: Rahul Singh <rahul.singh@xxxxxxx>
Reviewed-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>

Thanks
Bertrand

> ---
> Changes in v3:
> - This patch is introduce in this verison.
> 
> ---
> xen/common/device_tree.c      | 27 +++++++++++++++++++++++++++
> xen/include/xen/device_tree.h | 12 ++++++++++++
> 2 files changed, 39 insertions(+)
> 
> diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
> index e107c6f89f..18825e333e 100644
> --- a/xen/common/device_tree.c
> +++ b/xen/common/device_tree.c
> @@ -208,6 +208,33 @@ int dt_property_read_string(const struct dt_device_node 
> *np,
>     return 0;
> }
> 
> +int dt_property_match_string(const struct dt_device_node *np,
> +                             const char *propname, const char *string)
> +{
> +    const struct dt_property *dtprop = dt_find_property(np, propname, NULL);
> +    size_t l;
> +    int i;
> +    const char *p, *end;
> +
> +    if ( !dtprop )
> +        return -EINVAL;
> +    if ( !dtprop->value )
> +        return -ENODATA;
> +
> +    p = dtprop->value;
> +    end = p + dtprop->length;
> +
> +    for ( i = 0; p < end; i++, p += l )
> +    {
> +        l = strnlen(p, end - p) + 1;
> +        if ( p + l > end )
> +            return -EILSEQ;
> +        if ( strcmp(string, p) == 0 )
> +            return i; /* Found it; return index */
> +    }
> +    return -ENODATA;
> +}
> +
> bool_t dt_device_is_compatible(const struct dt_device_node *device,
>                                const char *compat)
> {
> diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
> index f2ad22b79c..b02696be94 100644
> --- a/xen/include/xen/device_tree.h
> +++ b/xen/include/xen/device_tree.h
> @@ -400,6 +400,18 @@ static inline bool_t dt_property_read_bool(const struct 
> dt_device_node *np,
> int dt_property_read_string(const struct dt_device_node *np,
>                             const char *propname, const char **out_string);
> 
> +/**
> + * dt_property_match_string() - Find string in a list and return index
> + * @np: pointer to node containing string list property
> + * @propname: string list property name
> + * @string: pointer to string to search for in string list
> + *
> + * This function searches a string list property and returns the index
> + * of a specific string value.
> + */
> +int dt_property_match_string(const struct dt_device_node *np,
> +                             const char *propname, const char *string);
> +
> /**
>  * Checks if the given "compat" string matches one of the strings in
>  * the device's "compatible" property
> -- 
> 2.17.1
> 




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.