Re: [PATCH v2 1/1] scsi: qla2xxx: replace non-standard flexible array purex_item.iocb

Gustavo A. R. Silva
2025-07-28T19:55:03Z

>> --- a/drivers/scsi/qla2xxx/qla_isr.c
>> +++ b/drivers/scsi/qla2xxx/qla_isr.c
>> @@ -1077,17 +1077,17 @@ static struct purex_item *
>>   qla24xx_alloc_purex_item(scsi_qla_host_t *vha, uint16_t size)
>>   {
>>       struct purex_item *item = NULL;
>> -    uint8_t item_hdr_size = sizeof(*item);
>>       if (size > QLA_DEFAULT_PAYLOAD_SIZE) {
>> -        item = kzalloc(item_hdr_size +
>> -            (size - QLA_DEFAULT_PAYLOAD_SIZE), GFP_ATOMIC);
>> +        item = kzalloc(struct_size(item, iocb, size), GFP_ATOMIC);
>
> With the inclusion of `counted_by`, I think `item->size` should be updated
> here:
>         item->size = size;
>
>>       } else {
>>           if (atomic_inc_return(&vha->default_item.in_use) == 1) {
>> -            item = &vha->default_item;
>> +            item = (struct purex_item *)&vha->default_item;
>>               goto initialize_purex_header;
>>           } else {
>> -            item = kzalloc(item_hdr_size, GFP_ATOMIC);
>> +            item = kzalloc(
>> +                struct_size(item, iocb, QLA_DEFAULT_PAYLOAD_SIZE),
>> +                GFP_ATOMIC);
>
> ...and here:
>             item->size = QLA_DEFAULT_PAYLOAD_SIZE;
>
> Then remove `item->size = size;` just before `return item;`

... or probably set to zero `item->size = 0;` ?

Thanks
-Gustavo