Re: [PATCH v2] scsi: fnic: Use vzalloc() instead of vmalloc() and memset(0)

From: Thorsten Blum
Date: Tue Oct 08 2024 - 07:02:28 EST


On 8. Oct 2024, at 12:25, Johannes Thumshirn wrote:
> On 08.10.24 11:53, Thorsten Blum wrote:
>> Use vzalloc() instead of vmalloc() followed by memset(0) to simplify the
>> functions fnic_trace_buf_init() and fnic_fc_trace_init().
>>
>> Remove unnecessary unsigned long cast.
>>
>> Compile-tested only.
>>
>> Cc: Johannes Thumshirn <johannes.thumshirn@xxxxxxx>
>> Signed-off-by: Thorsten Blum <thorsten.blum@xxxxxxxxx>
>> ---
>> Changes in v2:
>> - Remove unsigned long cast as suggested by Johannes Thumshirn
>> - Link to v1: https://lore.kernel.org/linux-kernel/20241007115840.2239-6-thorsten.blum@xxxxxxxxx/
>> ---
>> drivers/scsi/fnic/fnic_trace.c | 14 +++-----------
>> 1 file changed, 3 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/scsi/fnic/fnic_trace.c b/drivers/scsi/fnic/fnic_trace.c
>> index aaa4ea02fb7c..c2413e0e4eaa 100644
>> --- a/drivers/scsi/fnic/fnic_trace.c
>> +++ b/drivers/scsi/fnic/fnic_trace.c
>> @@ -485,7 +485,7 @@ int fnic_trace_buf_init(void)
>> }
>>
>> fnic_trace_entries.page_offset =
>> - vmalloc(array_size(fnic_max_trace_entries,
>> + vzalloc(array_size(fnic_max_trace_entries,
>> sizeof(unsigned long)));
>
> Sorry for not having spotted it earlier, but all those
> vzalloc(array_size(foo, bar)); calls can be turned into vcalloc(foo, bar);

No worries, but removing the unsigned long casts actually doesn't work:

drivers/scsi/fnic/fnic_trace.c:559:27: error: incompatible pointer to integer conversion assigning to 'unsigned long' from 'typeof (vzalloc_noprof(size_mul(((1UL) << 12), fnic_fc_trace_max_pages)))' (aka 'void *') [-Wint-conversion]
559 | fnic_fc_ctlr_trace_buf_p =
| ^
560 | vzalloc(array_size(PAGE_SIZE, fnic_fc_trace_max_pages));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

I'll submit a v3.

Thanks,
Thorsten