[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Xen-devel] [PATCH V6 3/8] xen/common: Introduce _xrealloc function
- To: Jan Beulich <jbeulich@xxxxxxxx>
- From: Oleksandr <olekstysh@xxxxxxxxx>
- Date: Thu, 26 Sep 2019 16:39:40 +0300
- Cc: sstabellini@xxxxxxxxxx, Wei Liu <wl@xxxxxxx>, Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>, George Dunlap <George.Dunlap@xxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Ian Jackson <ian.jackson@xxxxxxxxxxxxx>, Tim Deegan <tim@xxxxxxx>, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>, julien.grall@xxxxxxx, Paul Durrant <paul.durrant@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, volodymyr_babchuk@xxxxxxxx
- Delivery-date: Thu, 26 Sep 2019 13:39:50 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
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@xxxxxxxx>
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@xxxxxxxx>
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
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@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
|