qemu-ppc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack a


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH 07/23] hw/block/nvme: Use definition to avoid dynamic stack allocation
Date: Thu, 6 May 2021 00:07:44 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1

+Eric

On 5/5/21 11:22 PM, Keith Busch wrote:
> On Wed, May 05, 2021 at 11:10:31PM +0200, Philippe Mathieu-Daudé wrote:
>> The compiler isn't clever enough to figure 'SEG_CHUNK_SIZE' is
>> a constant! Help it by using a definitions instead.
> 
> I don't understand.

Neither do I TBH...

> It's labeled 'const', so any reasonable compiler
> will place it in the 'text' segment of the executable rather than on the
> stack. While that's compiler specific, is there really a compiler doing
> something bad with this? If not, I do prefer the 'const' here if only
> because it limits the symbol scope ('static const' is also preferred if
> that helps).

Using: gcc version 10.2.1 20201125 (Red Hat 10.2.1-9) (GCC)

Both static+const / const trigger:

hw/block/nvme.c: In function ‘nvme_map_sgl’:
hw/block/nvme.c:818:5: error: ISO C90 forbids variable length array
‘segment’ [-Werror=vla]
  818 |     NvmeSglDescriptor segment[SEG_CHUNK_SIZE], *sgld, *last_sgld;
      |     ^~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

> 
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> ---
>>  hw/block/nvme.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/hw/block/nvme.c b/hw/block/nvme.c
>> index 5fe082ec34c..2f6d4925826 100644
>> --- a/hw/block/nvme.c
>> +++ b/hw/block/nvme.c
>> @@ -812,7 +812,7 @@ static uint16_t nvme_map_sgl(NvmeCtrl *n, NvmeSg *sg, 
>> NvmeSglDescriptor sgl,
>>       * descriptors and segment chain) than the command transfer size, so it 
>> is
>>       * not bounded by MDTS.
>>       */
>> -    const int SEG_CHUNK_SIZE = 256;
>> +#define SEG_CHUNK_SIZE 256
>>  
>>      NvmeSglDescriptor segment[SEG_CHUNK_SIZE], *sgld, *last_sgld;
>>      uint64_t nsgld;
>> -- 
>> 2.26.3
>>
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]