On 28/07/2017 19:52, Marc-André Lureau wrote:
> 
>     Stupid question: what's the benefit?  
> 
> scsi_create/scsi_free is a library API. If they have their own
> allocator, we better use it, or it may easily break, no?

Well, that would be an API breakage, but I see the point.  I think I
would prefer something like

static inline struct scsi_task *iscsi_create_task(...)
{
#if ...
    return scsi_create_task(...)
#else
    /* Older versions of libiscsi have a bug, so include our
     * implementation.
     */
    struct scsi_task *task = g_try_malloc0(sizeof(struct scsi_task));
    if (!task) {
        task;
    }

    memcpy(&task->cdb[0], cdb, cdb_size);
    task->cdb_size   = cdb_size;
    task->xfer_dir   = xfer_dir;
    task->expxferlen = expxferlen;
    return task;
#endif
}

> 
>     Change malloc to g_new0 in the
>     existing code, and we even make it shorter...
> 
> 
> replacing malloc with g_new is the subject of another upcoming series :)
> (https://github.com/elmarco/clang-tools-extra/blob/master/clang-tidy/qemu/UseGnewCheck.cpp)
>  


Reply via email to