* [PATCH 5/5] target/ppc/kvm: Replace alloca() by g_malloc()
[not found] <20210505170055.1415360-1-philmd@redhat.com>
@ 2021-05-05 17:00 ` Philippe Mathieu-Daudé
2021-05-06 2:18 ` David Gibson
2021-05-06 8:41 ` Greg Kurz
0 siblings, 2 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-05-05 17:00 UTC (permalink / raw)
To: qemu-devel
Cc: Philippe Mathieu-Daudé,
David Gibson, Paolo Bonzini, Warner Losh, Kyle Evans, Greg Kurz,
Alex Bennée, open list:PowerPC TCG CPUs,
open list:Overall KVM CPUs
The ALLOCA(3) man-page mentions its "use is discouraged".
Replace it by a g_malloc() call.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
target/ppc/kvm.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 104a308abb5..ae62daddf7d 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -2698,11 +2698,11 @@ int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, int64_t max_ns)
int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
uint16_t n_valid, uint16_t n_invalid, Error **errp)
{
- struct kvm_get_htab_header *buf;
- size_t chunksize = sizeof(*buf) + n_valid * HASH_PTE_SIZE_64;
+ size_t chunksize = sizeof(struct kvm_get_htab_header)
+ + n_valid * HASH_PTE_SIZE_64;
ssize_t rc;
+ g_autofree struct kvm_get_htab_header *buf = g_malloc(chunksize);
- buf = alloca(chunksize);
buf->index = index;
buf->n_valid = n_valid;
buf->n_invalid = n_invalid;
@@ -2741,10 +2741,10 @@ void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, hwaddr ptex, int n)
i = 0;
while (i < n) {
struct kvm_get_htab_header *hdr;
+ char buf[sizeof(*hdr) + HPTES_PER_GROUP * HASH_PTE_SIZE_64];
int m = n < HPTES_PER_GROUP ? n : HPTES_PER_GROUP;
- char buf[sizeof(*hdr) + m * HASH_PTE_SIZE_64];
- rc = read(fd, buf, sizeof(buf));
+ rc = read(fd, buf, sizeof(*hdr) + m * HASH_PTE_SIZE_64);
if (rc < 0) {
hw_error("kvmppc_read_hptes: Unable to read HPTEs");
}
--
2.26.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 5/5] target/ppc/kvm: Replace alloca() by g_malloc()
2021-05-05 17:00 ` [PATCH 5/5] target/ppc/kvm: Replace alloca() by g_malloc() Philippe Mathieu-Daudé
@ 2021-05-06 2:18 ` David Gibson
2021-05-06 8:41 ` Greg Kurz
1 sibling, 0 replies; 4+ messages in thread
From: David Gibson @ 2021-05-06 2:18 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, Paolo Bonzini, Warner Losh, Kyle Evans, Greg Kurz,
Alex Bennée, open list:PowerPC TCG CPUs,
open list:Overall KVM CPUs
[-- Attachment #1: Type: text/plain, Size: 2056 bytes --]
On Wed, May 05, 2021 at 07:00:55PM +0200, Philippe Mathieu-Daudé wrote:
> The ALLOCA(3) man-page mentions its "use is discouraged".
>
> Replace it by a g_malloc() call.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> target/ppc/kvm.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
> index 104a308abb5..ae62daddf7d 100644
> --- a/target/ppc/kvm.c
> +++ b/target/ppc/kvm.c
> @@ -2698,11 +2698,11 @@ int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, int64_t max_ns)
> int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
> uint16_t n_valid, uint16_t n_invalid, Error **errp)
> {
> - struct kvm_get_htab_header *buf;
> - size_t chunksize = sizeof(*buf) + n_valid * HASH_PTE_SIZE_64;
> + size_t chunksize = sizeof(struct kvm_get_htab_header)
> + + n_valid * HASH_PTE_SIZE_64;
> ssize_t rc;
> + g_autofree struct kvm_get_htab_header *buf = g_malloc(chunksize);
>
> - buf = alloca(chunksize);
> buf->index = index;
> buf->n_valid = n_valid;
> buf->n_invalid = n_invalid;
> @@ -2741,10 +2741,10 @@ void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, hwaddr ptex, int n)
> i = 0;
> while (i < n) {
> struct kvm_get_htab_header *hdr;
> + char buf[sizeof(*hdr) + HPTES_PER_GROUP * HASH_PTE_SIZE_64];
> int m = n < HPTES_PER_GROUP ? n : HPTES_PER_GROUP;
> - char buf[sizeof(*hdr) + m * HASH_PTE_SIZE_64];
>
> - rc = read(fd, buf, sizeof(buf));
> + rc = read(fd, buf, sizeof(*hdr) + m * HASH_PTE_SIZE_64);
> if (rc < 0) {
> hw_error("kvmppc_read_hptes: Unable to read HPTEs");
> }
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 5/5] target/ppc/kvm: Replace alloca() by g_malloc()
2021-05-05 17:00 ` [PATCH 5/5] target/ppc/kvm: Replace alloca() by g_malloc() Philippe Mathieu-Daudé
2021-05-06 2:18 ` David Gibson
@ 2021-05-06 8:41 ` Greg Kurz
2021-05-06 13:09 ` Philippe Mathieu-Daudé
1 sibling, 1 reply; 4+ messages in thread
From: Greg Kurz @ 2021-05-06 8:41 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, David Gibson, Paolo Bonzini, Warner Losh, Kyle Evans,
Alex Bennée, open list:PowerPC TCG CPUs,
open list:Overall KVM CPUs
On Wed, 5 May 2021 19:00:55 +0200
Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
> The ALLOCA(3) man-page mentions its "use is discouraged".
>
> Replace it by a g_malloc() call.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> target/ppc/kvm.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
> index 104a308abb5..ae62daddf7d 100644
> --- a/target/ppc/kvm.c
> +++ b/target/ppc/kvm.c
> @@ -2698,11 +2698,11 @@ int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, int64_t max_ns)
> int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
> uint16_t n_valid, uint16_t n_invalid, Error **errp)
> {
> - struct kvm_get_htab_header *buf;
> - size_t chunksize = sizeof(*buf) + n_valid * HASH_PTE_SIZE_64;
> + size_t chunksize = sizeof(struct kvm_get_htab_header)
It is a bit unfortunate to introduce a new dependency on the struct type.
What about the following ?
- struct kvm_get_htab_header *buf;
+ g_autofree struct kvm_get_htab_header *buf = NULL;
size_t chunksize = sizeof(*buf) + n_valid * HASH_PTE_SIZE_64;
ssize_t rc;
- buf = alloca(chunksize);
+ buf = g_malloc(chunksize);
g_autofree struct kvm_get_htab_header *buf = NULL;
size_t chunksize = sizeof(*buf) + n_valid * HASH_PTE_SIZE_64;
> + + n_valid * HASH_PTE_SIZE_64;
> ssize_t rc;
> + g_autofree struct kvm_get_htab_header *buf = g_malloc(chunksize);
>
> - buf = alloca(chunksize);
> buf->index = index;
> buf->n_valid = n_valid;
> buf->n_invalid = n_invalid;
> @@ -2741,10 +2741,10 @@ void kvmppc_read_hptes(ppc_hash_pte64_t *hptes, hwaddr ptex, int n)
> i = 0;
> while (i < n) {
> struct kvm_get_htab_header *hdr;
> + char buf[sizeof(*hdr) + HPTES_PER_GROUP * HASH_PTE_SIZE_64];
> int m = n < HPTES_PER_GROUP ? n : HPTES_PER_GROUP;
> - char buf[sizeof(*hdr) + m * HASH_PTE_SIZE_64];
>
> - rc = read(fd, buf, sizeof(buf));
> + rc = read(fd, buf, sizeof(*hdr) + m * HASH_PTE_SIZE_64);
> if (rc < 0) {
> hw_error("kvmppc_read_hptes: Unable to read HPTEs");
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 5/5] target/ppc/kvm: Replace alloca() by g_malloc()
2021-05-06 8:41 ` Greg Kurz
@ 2021-05-06 13:09 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-05-06 13:09 UTC (permalink / raw)
To: Greg Kurz
Cc: qemu-devel, David Gibson, Paolo Bonzini, Warner Losh, Kyle Evans,
Alex Bennée, open list:PowerPC TCG CPUs,
open list:Overall KVM CPUs
On 5/6/21 10:41 AM, Greg Kurz wrote:
> On Wed, 5 May 2021 19:00:55 +0200
> Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>
>> The ALLOCA(3) man-page mentions its "use is discouraged".
>>
>> Replace it by a g_malloc() call.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> ---
>> target/ppc/kvm.c | 10 +++++-----
>> 1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
>> index 104a308abb5..ae62daddf7d 100644
>> --- a/target/ppc/kvm.c
>> +++ b/target/ppc/kvm.c
>> @@ -2698,11 +2698,11 @@ int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, int64_t max_ns)
>> int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
>> uint16_t n_valid, uint16_t n_invalid, Error **errp)
>> {
>> - struct kvm_get_htab_header *buf;
>> - size_t chunksize = sizeof(*buf) + n_valid * HASH_PTE_SIZE_64;
>> + size_t chunksize = sizeof(struct kvm_get_htab_header)
>
> It is a bit unfortunate to introduce a new dependency on the struct type.
>
> What about the following ?
>
> - struct kvm_get_htab_header *buf;
> + g_autofree struct kvm_get_htab_header *buf = NULL;
> size_t chunksize = sizeof(*buf) + n_valid * HASH_PTE_SIZE_64;
> ssize_t rc;
>
> - buf = alloca(chunksize);
> + buf = g_malloc(chunksize);
OK.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-05-06 13:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20210505170055.1415360-1-philmd@redhat.com>
2021-05-05 17:00 ` [PATCH 5/5] target/ppc/kvm: Replace alloca() by g_malloc() Philippe Mathieu-Daudé
2021-05-06 2:18 ` David Gibson
2021-05-06 8:41 ` Greg Kurz
2021-05-06 13:09 ` Philippe Mathieu-Daudé
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).