From: Janosch Frank <frankja@linux.ibm.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Andrew Jones <drjones@redhat.com>,
David Hildenbrand <david@redhat.com>
Cc: kvm@vger.kernel.org, thuth@redhat.com
Subject: Re: [kvm-unit-tests PATCH v2] alloc: Add memalign error checks
Date: Mon, 11 Nov 2019 11:12:41 +0100 [thread overview]
Message-ID: <4c26975a-84af-e21b-fe40-33197b51fffd@linux.ibm.com> (raw)
In-Reply-To: <a91a1828-017a-b0c6-442f-5b31263f3568@redhat.com>
[-- Attachment #1.1: Type: text/plain, Size: 1231 bytes --]
On 11/4/19 12:29 PM, Paolo Bonzini wrote:
> On 04/11/19 11:54, Andrew Jones wrote:
>>
>> diff --git a/lib/alloc.c b/lib/alloc.c
>> index ecdbbc44dbf9..ed8f5f94c9b0 100644
>> --- a/lib/alloc.c
>> +++ b/lib/alloc.c
>> @@ -46,15 +46,17 @@ void *memalign(size_t alignment, size_t size)
>> uintptr_t blkalign;
>> uintptr_t mem;
>>
>> + if (!size)
>> + return NULL;
>> +
>> + assert(alignment >= sizeof(void *) && is_power_of_2(alignment));
>> assert(alloc_ops && alloc_ops->memalign);
>> - if (alignment <= sizeof(uintptr_t))
>> - alignment = sizeof(uintptr_t);
>> - else
>> - size += alignment - 1;
>>
>> + size += alignment - 1;
>> blkalign = MAX(alignment, alloc_ops->align_min);
>> size = ALIGN(size + METADATA_EXTRA, alloc_ops->align_min);
>> p = alloc_ops->memalign(blkalign, size);
>> + assert(p);
I had some more time to think about and test this and I think returning
NULL here is more useful. My usecase is a limit test where I allocate
until I get a NULL and then free everything afterwards.
>>
>> /* Leave room for metadata before aligning the result. */
>> mem = (uintptr_t)p + METADATA_EXTRA;
>
> Looks good, this is what I am queuing.
>
> Paolo
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2019-11-11 10:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-04 10:29 [kvm-unit-tests PATCH v2] alloc: Add memalign error checks Janosch Frank
2019-11-04 10:33 ` David Hildenbrand
2019-11-04 10:54 ` Andrew Jones
2019-11-04 11:29 ` Paolo Bonzini
2019-11-04 11:31 ` David Hildenbrand
2019-11-11 10:12 ` Janosch Frank [this message]
2019-11-11 12:31 ` Andrew Jones
2019-11-11 13:04 ` Paolo Bonzini
2019-11-11 13:13 ` Janosch Frank
2019-11-11 13:17 ` Paolo Bonzini
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=4c26975a-84af-e21b-fe40-33197b51fffd@linux.ibm.com \
--to=frankja@linux.ibm.com \
--cc=david@redhat.com \
--cc=drjones@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=thuth@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox