Skip to contentSkip to conversation

block/iscsi: Document why we use raw malloc()

PATCH Applied Peter Maydell 2 participants 4 messages Jul 27, 2023 – Aug 18, 2023 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/iscsi: Document why we use raw malloc()

In block/iscsi.c we use a raw malloc() call, which is unusual given the project standard is to use the glib memory allocation functions. Document why we do so, to avoid it being converted to g_malloc() by mistake.

---
There aren't many uses of raw malloc() in the codebase other than third-party library sourcecode. Mostly we have a comment noting when we're doing it deliberately.

---
 block/iscsi.c | 1 +
 1 file changed, 1 insertion(+)
block/iscsi.c +1 -0
index 34f97ab6460..5640c8b5657 100644
@@ -1058,6 +1058,7 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
         return NULL;
     }
 
+    /* Must use malloc(): this is freed via scsi_free_scsi_task() */
     acb->task = malloc(sizeof(struct scsi_task));
     if (acb->task == NULL) {
         error_report("iSCSI: Failed to allocate task for scsi command. %s",
Signature · 1 line
2.34.1
#1 lore raw
Quoted 20 lines · Peter Maydell

In block/iscsi.c we use a raw malloc() call, which is unusual given the project standard is to use the glib memory allocation functions. Document why we do so, to avoid it being converted to g_malloc() by mistake.

---
There aren't many uses of raw malloc() in the codebase other than third-party library sourcecode. Mostly we have a comment noting when we're doing it deliberately.

---
 block/iscsi.c | 1 +
 1 file changed, 1 insertion(+)
block/iscsi.c +0 -0
index 34f97ab6460..5640c8b5657 100644

block/iscsi.c static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, · line 1064

Quoted 7 lines
block/iscsi.c +1 -0
@@ -1058,6 +1058,7 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
         return NULL;
     }
 
+    /* Must use malloc(): this is freed via scsi_free_scsi_task() */
     acb->task = malloc(sizeof(struct scsi_task));
     if (acb->task == NULL) {
         error_report("iSCSI: Failed to allocate task for scsi command. %s",

The other option here would be to use scsi_create_task(), if we're OK with requiring libiscsi 1.13 or better (that's 9 years old at this point, so should be OK...)

thanks
-- PMM

Applied
#2 lore raw

Am 27.07.2023 um 17:15 hat Peter Maydell geschrieben:

Quoted 7 lines · Peter Maydell
Quoted 6 lines

In block/iscsi.c we use a raw malloc() call, which is unusual given the project standard is to use the glib memory allocation functions. Document why we do so, to avoid it being converted to g_malloc() by mistake.

Quoted 5 lines
Quoted 5 lines

---
There aren't many uses of raw malloc() in the codebase other than third-party library sourcecode. Mostly we have a comment noting when we're doing it deliberately.

Thanks, applied to the block branch.

Quoted 3 lines

The other option here would be to use scsi_create_task(), if we're OK with requiring libiscsi 1.13 or better (that's 9 years old at this point, so should be OK...)

I wouldn't mind either way, but since this patch exists and the other doesn't, I'm applying this one for now.

Kevin

#3 lore raw
Quoted 15 lines · Kevin Wolf

Am 27.07.2023 um 17:15 hat Peter Maydell geschrieben:

Quoted 7 lines · Peter Maydell
Quoted 6 lines

In block/iscsi.c we use a raw malloc() call, which is unusual given the project standard is to use the glib memory allocation functions. Document why we do so, to avoid it being converted to g_malloc() by mistake.

Quoted 5 lines
Quoted 5 lines

---
There aren't many uses of raw malloc() in the codebase other than third-party library sourcecode. Mostly we have a comment noting when we're doing it deliberately.

Quoted 8 lines

Thanks, applied to the block branch.

Quoted 3 lines

The other option here would be to use scsi_create_task(), if we're OK with requiring libiscsi 1.13 or better (that's 9 years old at this point, so should be OK...)

I wouldn't mind either way, but since this patch exists and the other doesn't, I'm applying this one for now.

Thanks. I think scsi_create_task() would be cleaner, but it's just over the amount of change that I'd want to do without a test setup to exercise this code, which is why I stuck to the comment for now.

-- PMM