All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleksandr <olekstysh@gmail.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: sstabellini@kernel.org, Wei Liu <wl@xen.org>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	George Dunlap <George.Dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>,
	Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
	julien.grall@arm.com, Paul Durrant <paul.durrant@citrix.com>,
	xen-devel@lists.xenproject.org, volodymyr_babchuk@epam.com
Subject: Re: [Xen-devel] [PATCH V6 3/8] xen/common: Introduce _xrealloc function
Date: Thu, 26 Sep 2019 16:39:40 +0300	[thread overview]
Message-ID: <29f4f366-8c8a-a7ff-ccca-d17847b4fd1b@gmail.com> (raw)
In-Reply-To: <32234ca5-75b2-3908-5f46-484fc53104af@suse.com>


On 26.09.19 15:19, Jan Beulich wrote:

Hi, Jan

> On 26.09.2019 13:20, Oleksandr Tyshchenko wrote:
>> From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
>>
>> This patch introduces type-unsafe function which besides
>> re-allocation handles the following corner cases:
>> 1. if requested size is zero, it will behave like xfree
>> 2. if incoming pointer is not valid (NULL or ZERO_BLOCK_PTR),
>>     it will behave like xmalloc
>>
>> If both pointer and size are valid the function will re-allocate and
>> copy only if requested size and alignment don't fit in already
>> allocated space.
>>
>> Subsequent patch will add type-safe helper macros.
>>
>> Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
> Reviewed-by: Jan Beulich <jbeulich@suse.com>

Thank you!


> preferably with two more cosmetics addressed (can surely be done
> while committing):
>
>> --- a/xen/common/xmalloc_tlsf.c
>> +++ b/xen/common/xmalloc_tlsf.c
>> @@ -549,10 +549,40 @@ static void tlsf_init(void)
>>    * xmalloc()
>>    */
>>   
>> +static void *strip_padding(void *p)
>> +{
>> +    struct bhdr *b = p - BHDR_OVERHEAD;
> Looks like this can (and hence should) be pointer to const.

agree


>
>
>> @@ -593,10 +616,71 @@ void *_xzalloc(unsigned long size, unsigned long align)
>>       return p ? memset(p, 0, size) : p;
>>   }
>>   
>> -void xfree(void *p)
>> +void *_xrealloc(void *ptr, unsigned long size, unsigned long align)
>>   {
>> -    struct bhdr *b;
>> +    unsigned long curr_size;
>> +    void *p;
>> +
>> +    if ( !size )
>> +    {
>> +        xfree(ptr);
>> +        return ZERO_BLOCK_PTR;
>> +    }
>>   
>> +    if ( ptr == NULL || ptr == ZERO_BLOCK_PTR )
>> +        return _xmalloc(size, align);
>> +
>> +    ASSERT(!(align & (align - 1)));
>> +    if ( align < MEM_ALIGN )
>> +        align = MEM_ALIGN;
>> +
>> +    if ( !((unsigned long)ptr & (PAGE_SIZE - 1)) )
>> +    {
>> +        curr_size = (unsigned long)PFN_ORDER(virt_to_page(ptr)) << PAGE_SHIFT;
>> +
>> +        if ( size <= curr_size && !((unsigned long)ptr & (align - 1)) )
>> +            return ptr;
>> +    }
>> +    else
>> +    {
>> +        unsigned long tmp_size;
>> +        struct bhdr *b;
> Same here.

agree


>
>> +        tmp_size = size + align - MEM_ALIGN;
> This could also be the initializer of the variable.

agree

-- 
Regards,

Oleksandr Tyshchenko


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2019-09-26 13:40 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-26 11:20 [Xen-devel] [PATCH V6 0/8] iommu/arm: Add Renesas IPMMU-VMSA support + Linux's iommu_fwspec Oleksandr Tyshchenko
2019-09-26 11:20 ` [Xen-devel] [PATCH V6 1/8] iommu/arm: Add iommu_helpers.c file to keep common for IOMMUs stuff Oleksandr Tyshchenko
2019-09-26 11:20 ` [Xen-devel] [PATCH V6 2/8] iommu/arm: Add ability to handle deferred probing request Oleksandr Tyshchenko
2019-09-26 11:20 ` [Xen-devel] [PATCH V6 3/8] xen/common: Introduce _xrealloc function Oleksandr Tyshchenko
2019-09-26 12:19   ` Jan Beulich
2019-09-26 13:39     ` Oleksandr [this message]
2019-09-26 11:20 ` [Xen-devel] [PATCH V6 4/8] xen/common: Introduce xrealloc_flex_struct() helper macros Oleksandr Tyshchenko
2019-09-26 11:20 ` [Xen-devel] [PATCH V6 5/8] iommu/arm: Add lightweight iommu_fwspec support Oleksandr Tyshchenko
2019-09-26 11:20 ` [Xen-devel] [PATCH V6 6/8] iommu: Order the headers alphabetically in device_tree.c Oleksandr Tyshchenko
2019-09-26 11:20 ` [Xen-devel] [PATCH V6 7/8] iommu/arm: Introduce iommu_add_dt_device API Oleksandr Tyshchenko
2019-09-26 12:52   ` Julien Grall
2019-09-26 13:34     ` Oleksandr
2019-09-26 14:34     ` Jan Beulich
2019-09-26 11:20 ` [Xen-devel] [PATCH V6 8/8] iommu/arm: Add Renesas IPMMU-VMSA support Oleksandr Tyshchenko
2019-09-26 12:22   ` Jan Beulich
2019-09-26 13:32     ` Oleksandr
2019-09-26 14:56 ` [Xen-devel] [PATCH V6 0/8] iommu/arm: Add Renesas IPMMU-VMSA support + Linux's iommu_fwspec Julien Grall
2019-09-26 15:16   ` Oleksandr
2019-09-27 22:50     ` Stefano Stabellini
2019-09-27 23:52       ` Oleksandr Tyshchenko
2019-09-28  9:36         ` Julien Grall
2019-09-30 20:58           ` Stefano Stabellini
2019-10-01  9:23             ` Oleksandr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=29f4f366-8c8a-a7ff-ccca-d17847b4fd1b@gmail.com \
    --to=olekstysh@gmail.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=konrad.wilk@oracle.com \
    --cc=oleksandr_tyshchenko@epam.com \
    --cc=paul.durrant@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=volodymyr_babchuk@epam.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.