[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240307093733.41222-2-yangxingui@huawei.com>
Date: Thu, 7 Mar 2024 09:37:31 +0000
From: Xingui Yang <yangxingui@...wei.com>
To: <john.g.garry@...cle.com>, <yanaijie@...wei.com>, <jejb@...ux.ibm.com>,
<martin.petersen@...cle.com>, <damien.lemoal@...nsource.wdc.com>
CC: <linux-scsi@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linuxarm@...wei.com>, <prime.zeng@...ilicon.com>,
<chenxiang66@...ilicon.com>, <kangfenglong@...wei.com>
Subject: [PATCH v3 1/3] scsi: libsas: Allow smp_execute_task() arguments to be on the stack
We need to use alloc_smp_resp() and alloc_smp_req() before call
smp_execute_task() 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.
Suggested-by: John Garry <john.g.garry@...cle.com>
Signed-off-by: Xingui Yang <yangxingui@...wei.com>
---
drivers/scsi/libsas/sas_expander.c | 32 ++++++++++++++++++++----------
1 file changed, 21 insertions(+), 11 deletions(-)
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index a2204674b680..1eeb69cba8da 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -120,17 +120,6 @@ static int smp_execute_task_sg(struct domain_device *dev,
return res;
}
-static int smp_execute_task(struct domain_device *dev, void *req, int req_size,
- void *resp, int resp_size)
-{
- struct scatterlist req_sg;
- struct scatterlist resp_sg;
-
- sg_init_one(&req_sg, req, req_size);
- sg_init_one(&resp_sg, resp, resp_size);
- return smp_execute_task_sg(dev, &req_sg, &resp_sg);
-}
-
/* ---------- Allocations ---------- */
static inline void *alloc_smp_req(int size)
@@ -146,6 +135,27 @@ static inline void *alloc_smp_resp(int size)
return kzalloc(size, GFP_KERNEL);
}
+static int smp_execute_task(struct domain_device *dev, void *req, int req_size,
+ void *resp, int resp_size)
+{
+ struct scatterlist req_sg;
+ struct scatterlist resp_sg;
+ void *_req = kmemdup(req, req_size, GFP_KERNEL);
+ void *_resp = alloc_smp_resp(resp_size);
+ int ret;
+
+ 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;
+}
+
static char sas_route_char(struct domain_device *dev, struct ex_phy *phy)
{
switch (phy->routing_attr) {
--
2.17.1
Powered by blists - more mailing lists