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

Re: [XEN][RFC PATCH v3 11/14] xen/arm: Implement device tree node addition functionalities


  • To: Vikram Garhwal <fnu.vikram@xxxxxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Tue, 15 Mar 2022 10:40:57 +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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=szTfdxs5M/Msha/s8hkQD54iMpyHA5nPfE70MdCR6yQ=; b=mIqTtt6sHCHS9r/fgCzt1oZr1D4msHGi5hKVmbPv4tnawtas4XZl2jJ/PjxmEce9IJvOD7IZBL+4GKrTW5SkES1MIs4eUGuiLJZyqQOdz8I7kOqcr6+VKp+leX13shqo6qSbLIuLn6KF9UovEO5iU6RDlebdpP8I4YeNwWFUisIzbYTDUR0woShd48Lrfd1kBv5vvcLBWL92Za2okfLmgk49u0yfWqSbVuFmkqpV0HLq+EJznYGWgMViXT0RoKRe+XsqSZjSh2kwdhIE+4cmYrWMHU3uAQCDUV4TZmpR2us+oHoqHkfgKZwn1ifefE0iKLDFQimtLTqYHcIjubkWmg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OU7/qBCfuLoKud40tZs1UZWaaxsc3O1clDAELOFv4VrkUDduTxsjjUhtkAb+bUJbb+FjctuIMq1QSUdY9K8RyuusnakPK8f4ORmW8MEDoK/QgmAgn4oSGo2A7f07SQWQ7Qpc9zjhNu7fGqISJnpXLSLyIAPEYckzqnR3NmQwwGB55Gf/oTqRQhy+UIkGKxnPAKfYodI2bLggMNh6YtHuYp9zy//XETMQ9avbqBGMrf+F/RnAOI0pWezSdzyo67zNpc680fPYzpHxomaxa13wzxpP8pQLcOJ2ODh4bNZBvnTaIu5AwftKYf0D8co6fRwUCY4wFSc2Uqo41ugAcqN/Ow==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, "julien@xxxxxxx" <julien@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, "volodymyr_babchuk@xxxxxxxx" <volodymyr_babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Tue, 15 Mar 2022 10:41:21 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHYMyVzdRh4vWYAmEuwX+X13mbNP6zATAOA
  • Thread-topic: [XEN][RFC PATCH v3 11/14] xen/arm: Implement device tree node addition functionalities

> 
> +static int dt_overlay_add_node(struct dt_device_node *device_node,
> +                  const char *parent_node_path)

Const should be indented at the same level of struct

> +/*
> + * Adds device tree nodes under target node.
> + * We use dt_host_new to unflatten the updated device_tree_flattened. This is
> + * done to avoid the removal of device_tree generation, iomem regions 
> mapping to
> + * hardware domain done by handle_node().
> + */
> +static long handle_add_overlay_nodes(void *overlay_fdt,
> +                                     uint32_t overlay_fdt_size)
> +{
> +    int rc = 0;
> +    struct dt_device_node *overlay_node;
> +    char **nodes_full_path = NULL;
> +    int **nodes_irq = NULL;
> +    int *node_num_irq = NULL;
> +    void *fdt = NULL;
> +    struct dt_device_node *dt_host_new = NULL;
> +    struct domain *d = hardware_domain;
> +    struct overlay_track *tr = NULL;
> +    unsigned int naddr;
> +    unsigned int num_irq;
> +    unsigned int i, j, k;
> +    unsigned int num_overlay_nodes;

All unsigned int can stay in the same line

> +    u64 addr, size;
> +
> +    fdt = xmalloc_bytes(fdt_totalsize(device_tree_flattened));
> +    if ( fdt == NULL )
> +        return -ENOMEM;
> +
> +    num_overlay_nodes = overlay_node_count(overlay_fdt);
> +    if ( num_overlay_nodes == 0 )
> +    {
> +        xfree(fdt);
> +        return -ENOMEM;
> +    }
> +
> +    spin_lock(&overlay_lock);
> +
> +    memcpy(fdt, device_tree_flattened, fdt_totalsize(device_tree_flattened));
> +
> +    rc = check_overlay_fdt(overlay_fdt, overlay_fdt_size);
> +    if ( rc )
> +    {
> +        xfree(fdt);
> +        return rc;
> +    }
> +
> +    /*
> +     * overlay_get_nodes_info is called to get the node information from 
> dtbo.
> +     * This is done before fdt_overlay_apply() because the overlay apply will
> +     * erase the magic of overlay_fdt.
> +     */
> +    rc = overlay_get_nodes_info(overlay_fdt, &nodes_full_path,
> +                                num_overlay_nodes);
> +    if ( rc )
> +    {
> +        printk(XENLOG_ERR "Getting nodes information failed with error %d\n",
> +               rc);
> +        goto err;
> +    }
> +
> +    nodes_irq = xmalloc_bytes(num_overlay_nodes * sizeof(int *));

You can use xzalloc_bytes and remove the memset below here and...

> +
> +    if ( nodes_irq == NULL )
> +    {
> +        rc = -ENOMEM;
> +        goto err;
> +    }
> +    memset(nodes_irq, 0x0, num_overlay_nodes * sizeof(int *));
> +
> +    node_num_irq = xmalloc_bytes(num_overlay_nodes * sizeof(int));

Here

> +    if ( node_num_irq == NULL )
> +    {
> +        rc = -ENOMEM;
> +        goto err;
> +    }
> +    memset(node_num_irq, 0x0, num_overlay_nodes * sizeof(int));
> +
> +    rc = fdt_overlay_apply(fdt, overlay_fdt);
> +    if ( rc )
> +    {
> +        printk(XENLOG_ERR "Adding overlay node failed with error %d\n", rc);
> +        goto err;
> +    }
> +
> +   […]
> +err:
> +    spin_unlock(&overlay_lock);
> +
> +    xfree(dt_host_new);
> +    xfree(fdt);
> +
> +    if ( nodes_full_path != NULL )
> +    {
> +        for ( i = 0; i < num_overlay_nodes && nodes_full_path[i] != NULL; 
> i++ )
> +        {
> +            xfree(nodes_full_path[i]);
> +        }
> +        xfree(nodes_full_path);
> +    }
> +
> +    if ( nodes_irq != NULL )
> +    {
> +        for ( i = 0; i < num_overlay_nodes && nodes_irq[i] != NULL; i++ )
> +        {
> +            xfree(nodes_irq[i]);
> +        }
> +        xfree(nodes_irq);
> +    }

I see you use this operation quite a bit in this module, perhaps you can create 
a function to
do that


 


Rackspace

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