Re: [PATCH v2] scsi: libsas: Fix disk not being scanned in after being removed

From: Jason Yan
Date: Wed Mar 06 2024 - 21:13:48 EST


On 2024/3/7 2:43, John Garry wrote:
As an aside, could libsas - and your changes here - be simpler if we changed smp_execute_task() like this:

static int smp_execute_task(struct domain_device *dev, void *req /* can be on the stack */, int req_size,
                void *resp /* can be on the stack */, int resp_size)
{
    struct scatterlist req_sg;
    struct scatterlist resp_sg;
    int ret;
    void *_req = kmemdup(req, req_size, GFP_KERNEL);
    void *_resp = alloc_smp_resp(resp_size);
    if (!_req || !resp)
        return -ENOMEM;

    sg_init_one(&req_sg, _req, req_size);
    sg_init_one(&resp_sg, _resp, resp_size);
    ret = smp_execute_task_sg(dev, &req_sg, &resp_sg);
    memcpy(resp, _resp, resp_size);
    kfree(_req);
    kfree(_resp);
    return ret;
}

We need to use alloc_smp_resp() and alloc_smp_req() as we can't allocate these memories on the stack for calling sg_init_one(). But if we changed smp_execute_task() to memcpy from/to data on the stack, it might make callers simpler. I'm not sure.

Maybe simpler. I have not check all the length of these buffers, but there is still a risk of stack overflow if the buffer on stack is too large.

Thanks,
Jason