All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Greg Kurz <groug@kaod.org>
Cc: qemu-devel@nongnu.org,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Warner Losh" <imp@bsdimp.com>, "Kyle Evans" <kevans@freebsd.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"open list:PowerPC TCG CPUs" <qemu-ppc@nongnu.org>,
	"open list:Overall KVM CPUs" <kvm@vger.kernel.org>
Subject: Re: [PATCH 5/5] target/ppc/kvm: Replace alloca() by g_malloc()
Date: Thu, 6 May 2021 15:09:34 +0200	[thread overview]
Message-ID: <3405dbc2-caf3-0da6-25aa-fe54f8ac8e11@redhat.com> (raw)
In-Reply-To: <20210506104130.5f617359@bahia.lan>

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.


WARNING: multiple messages have this Message-ID (diff)
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Greg Kurz <groug@kaod.org>
Cc: "open list:Overall KVM CPUs" <kvm@vger.kernel.org>,
	"Kyle Evans" <kevans@freebsd.org>,
	qemu-devel@nongnu.org,
	"open list:PowerPC TCG CPUs" <qemu-ppc@nongnu.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Warner Losh" <imp@bsdimp.com>,
	"David Gibson" <david@gibson.dropbear.id.au>
Subject: Re: [PATCH 5/5] target/ppc/kvm: Replace alloca() by g_malloc()
Date: Thu, 6 May 2021 15:09:34 +0200	[thread overview]
Message-ID: <3405dbc2-caf3-0da6-25aa-fe54f8ac8e11@redhat.com> (raw)
In-Reply-To: <20210506104130.5f617359@bahia.lan>

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.



  reply	other threads:[~2021-05-06 13:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 17:00 [PATCH 0/5] misc: Replace alloca() by g_malloc() Philippe Mathieu-Daudé
2021-05-05 17:00 ` [PATCH 1/5] bsd-user/syscall: Replace alloca() by g_new() Philippe Mathieu-Daudé
2021-05-05 17:00 ` [PATCH 2/5] gdbstub: Constify GdbCmdParseEntry Philippe Mathieu-Daudé
2021-05-06 11:50   ` Alex Bennée
2021-05-05 17:00 ` [PATCH 3/5] gdbstub: Use fixed-size array in GdbCmdParseEntry instead of pointer Philippe Mathieu-Daudé
2021-05-06 12:01   ` Alex Bennée
2021-05-06 12:39     ` Philippe Mathieu-Daudé
2021-05-06 15:15       ` Alex Bennée
2021-05-05 17:00 ` [PATCH 4/5] gdbstub: Replace alloca() by g_new() Philippe Mathieu-Daudé
2021-05-06 16:07   ` [ALT PATCH] gdbstub: Replace GdbCmdContext with plain g_array() Alex Bennée
2021-05-05 17:00 ` [PATCH 5/5] target/ppc/kvm: Replace alloca() by g_malloc() Philippe Mathieu-Daudé
2021-05-05 17:00   ` Philippe Mathieu-Daudé
2021-05-06  2:18   ` David Gibson
2021-05-06  2:18     ` David Gibson
2021-05-06  8:41   ` Greg Kurz
2021-05-06  8:41     ` Greg Kurz
2021-05-06 13:09     ` Philippe Mathieu-Daudé [this message]
2021-05-06 13:09       ` Philippe Mathieu-Daudé

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=3405dbc2-caf3-0da6-25aa-fe54f8ac8e11@redhat.com \
    --to=philmd@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=groug@kaod.org \
    --cc=imp@bsdimp.com \
    --cc=kevans@freebsd.org \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.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.