Skip to content

Commit 09cc8b3

Browse files
hongliu68Jiri Kosina
authored andcommitted
HID: intel-ish-hid: remove data[128] usage on stack when sending HBM request
Instead of using an 128-byte on-stack array to store the request, we can instantiate the request on stack directly. This can save the stack usage of these functions, since most of the requests are much smaller than 128 bytes. Signed-off-by: Hong Liu <[email protected]> Tested-by: Hongyan Song <[email protected]> Acked-by: Srinivas Pandruvada <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 7e06e0d commit 09cc8b3

File tree

3 files changed

+38
-63
lines changed

3 files changed

+38
-63
lines changed

drivers/hid/intel-ish-hid/ishtp/bus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ int ishtp_send_msg(struct ishtp_device *dev, struct ishtp_msg_hdr *hdr,
119119
* Return: This returns IPC send message status.
120120
*/
121121
int ishtp_write_message(struct ishtp_device *dev, struct ishtp_msg_hdr *hdr,
122-
unsigned char *buf)
122+
void *buf)
123123
{
124124
return ishtp_send_msg(dev, hdr, buf, NULL, NULL);
125125
}

drivers/hid/intel-ish-hid/ishtp/bus.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int ishtp_send_msg(struct ishtp_device *dev,
8585
/* Write a single-fragment message */
8686
int ishtp_write_message(struct ishtp_device *dev,
8787
struct ishtp_msg_hdr *hdr,
88-
unsigned char *buf);
88+
void *buf);
8989

9090
/* Use DMA to send/receive messages */
9191
int ishtp_use_dma_transfer(void);

drivers/hid/intel-ish-hid/ishtp/hbm.c

Lines changed: 36 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -136,27 +136,22 @@ int ishtp_hbm_start_wait(struct ishtp_device *dev)
136136
int ishtp_hbm_start_req(struct ishtp_device *dev)
137137
{
138138
struct ishtp_msg_hdr hdr;
139-
unsigned char data[128];
140-
struct ishtp_msg_hdr *ishtp_hdr = &hdr;
141-
struct hbm_host_version_request *start_req;
142-
const size_t len = sizeof(struct hbm_host_version_request);
139+
struct hbm_host_version_request start_req = { 0 };
143140

144-
ishtp_hbm_hdr(ishtp_hdr, len);
141+
ishtp_hbm_hdr(&hdr, sizeof(start_req));
145142

146143
/* host start message */
147-
start_req = (struct hbm_host_version_request *)data;
148-
memset(start_req, 0, len);
149-
start_req->hbm_cmd = HOST_START_REQ_CMD;
150-
start_req->host_version.major_version = HBM_MAJOR_VERSION;
151-
start_req->host_version.minor_version = HBM_MINOR_VERSION;
144+
start_req.hbm_cmd = HOST_START_REQ_CMD;
145+
start_req.host_version.major_version = HBM_MAJOR_VERSION;
146+
start_req.host_version.minor_version = HBM_MINOR_VERSION;
152147

153148
/*
154149
* (!) Response to HBM start may be so quick that this thread would get
155150
* preempted BEFORE managing to set hbm_state = ISHTP_HBM_START.
156151
* So set it at first, change back to ISHTP_HBM_IDLE upon failure
157152
*/
158153
dev->hbm_state = ISHTP_HBM_START;
159-
if (ishtp_write_message(dev, ishtp_hdr, data)) {
154+
if (ishtp_write_message(dev, &hdr, &start_req)) {
160155
dev_err(dev->devc, "version message send failed\n");
161156
dev->dev_state = ISHTP_DEV_RESETTING;
162157
dev->hbm_state = ISHTP_HBM_IDLE;
@@ -178,19 +173,13 @@ int ishtp_hbm_start_req(struct ishtp_device *dev)
178173
void ishtp_hbm_enum_clients_req(struct ishtp_device *dev)
179174
{
180175
struct ishtp_msg_hdr hdr;
181-
unsigned char data[128];
182-
struct ishtp_msg_hdr *ishtp_hdr = &hdr;
183-
struct hbm_host_enum_request *enum_req;
184-
const size_t len = sizeof(struct hbm_host_enum_request);
176+
struct hbm_host_enum_request enum_req = { 0 };
185177

186178
/* enumerate clients */
187-
ishtp_hbm_hdr(ishtp_hdr, len);
179+
ishtp_hbm_hdr(&hdr, sizeof(enum_req));
180+
enum_req.hbm_cmd = HOST_ENUM_REQ_CMD;
188181

189-
enum_req = (struct hbm_host_enum_request *)data;
190-
memset(enum_req, 0, len);
191-
enum_req->hbm_cmd = HOST_ENUM_REQ_CMD;
192-
193-
if (ishtp_write_message(dev, ishtp_hdr, data)) {
182+
if (ishtp_write_message(dev, &hdr, &enum_req)) {
194183
dev->dev_state = ISHTP_DEV_RESETTING;
195184
dev_err(dev->devc, "enumeration request send failed\n");
196185
ish_hw_reset(dev);
@@ -208,12 +197,8 @@ void ishtp_hbm_enum_clients_req(struct ishtp_device *dev)
208197
*/
209198
static int ishtp_hbm_prop_req(struct ishtp_device *dev)
210199
{
211-
212200
struct ishtp_msg_hdr hdr;
213-
unsigned char data[128];
214-
struct ishtp_msg_hdr *ishtp_hdr = &hdr;
215-
struct hbm_props_request *prop_req;
216-
const size_t len = sizeof(struct hbm_props_request);
201+
struct hbm_props_request prop_req = { 0 };
217202
unsigned long next_client_index;
218203
uint8_t client_num;
219204

@@ -237,15 +222,12 @@ static int ishtp_hbm_prop_req(struct ishtp_device *dev)
237222

238223
dev->fw_clients[client_num].client_id = next_client_index;
239224

240-
ishtp_hbm_hdr(ishtp_hdr, len);
241-
prop_req = (struct hbm_props_request *)data;
225+
ishtp_hbm_hdr(&hdr, sizeof(prop_req));
242226

243-
memset(prop_req, 0, sizeof(struct hbm_props_request));
227+
prop_req.hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD;
228+
prop_req.address = next_client_index;
244229

245-
prop_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD;
246-
prop_req->address = next_client_index;
247-
248-
if (ishtp_write_message(dev, ishtp_hdr, data)) {
230+
if (ishtp_write_message(dev, &hdr, &prop_req)) {
249231
dev->dev_state = ISHTP_DEV_RESETTING;
250232
dev_err(dev->devc, "properties request send failed\n");
251233
ish_hw_reset(dev);
@@ -266,19 +248,14 @@ static int ishtp_hbm_prop_req(struct ishtp_device *dev)
266248
static void ishtp_hbm_stop_req(struct ishtp_device *dev)
267249
{
268250
struct ishtp_msg_hdr hdr;
269-
unsigned char data[128];
270-
struct ishtp_msg_hdr *ishtp_hdr = &hdr;
271-
struct hbm_host_stop_request *req;
272-
const size_t len = sizeof(struct hbm_host_stop_request);
251+
struct hbm_host_stop_request stop_req = { 0 } ;
273252

274-
ishtp_hbm_hdr(ishtp_hdr, len);
275-
req = (struct hbm_host_stop_request *)data;
253+
ishtp_hbm_hdr(&hdr, sizeof(stop_req));
276254

277-
memset(req, 0, sizeof(struct hbm_host_stop_request));
278-
req->hbm_cmd = HOST_STOP_REQ_CMD;
279-
req->reason = DRIVER_STOP_REQUEST;
255+
stop_req.hbm_cmd = HOST_STOP_REQ_CMD;
256+
stop_req.reason = DRIVER_STOP_REQUEST;
280257

281-
ishtp_write_message(dev, ishtp_hdr, data);
258+
ishtp_write_message(dev, &hdr, &stop_req);
282259
}
283260

284261
/**
@@ -294,15 +271,15 @@ int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev,
294271
struct ishtp_cl *cl)
295272
{
296273
struct ishtp_msg_hdr hdr;
297-
unsigned char data[128];
298-
struct ishtp_msg_hdr *ishtp_hdr = &hdr;
299-
const size_t len = sizeof(struct hbm_flow_control);
274+
struct hbm_flow_control flow_ctrl;
275+
const size_t len = sizeof(flow_ctrl);
300276
int rv;
301277
unsigned long flags;
302278

303279
spin_lock_irqsave(&cl->fc_spinlock, flags);
304-
ishtp_hbm_hdr(ishtp_hdr, len);
305-
ishtp_hbm_cl_hdr(cl, ISHTP_FLOW_CONTROL_CMD, data, len);
280+
281+
ishtp_hbm_hdr(&hdr, len);
282+
ishtp_hbm_cl_hdr(cl, ISHTP_FLOW_CONTROL_CMD, &flow_ctrl, len);
306283

307284
/*
308285
* Sync possible race when RB recycle and packet receive paths
@@ -315,7 +292,7 @@ int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev,
315292

316293
cl->recv_msg_num_frags = 0;
317294

318-
rv = ishtp_write_message(dev, ishtp_hdr, data);
295+
rv = ishtp_write_message(dev, &hdr, &flow_ctrl);
319296
if (!rv) {
320297
++cl->out_flow_ctrl_creds;
321298
++cl->out_flow_ctrl_cnt;
@@ -345,14 +322,13 @@ int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev,
345322
int ishtp_hbm_cl_disconnect_req(struct ishtp_device *dev, struct ishtp_cl *cl)
346323
{
347324
struct ishtp_msg_hdr hdr;
348-
unsigned char data[128];
349-
struct ishtp_msg_hdr *ishtp_hdr = &hdr;
350-
const size_t len = sizeof(struct hbm_client_connect_request);
325+
struct hbm_client_connect_request disconn_req;
326+
const size_t len = sizeof(disconn_req);
351327

352-
ishtp_hbm_hdr(ishtp_hdr, len);
353-
ishtp_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, data, len);
328+
ishtp_hbm_hdr(&hdr, len);
329+
ishtp_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, &disconn_req, len);
354330

355-
return ishtp_write_message(dev, ishtp_hdr, data);
331+
return ishtp_write_message(dev, &hdr, &disconn_req);
356332
}
357333

358334
/**
@@ -391,14 +367,13 @@ static void ishtp_hbm_cl_disconnect_res(struct ishtp_device *dev,
391367
int ishtp_hbm_cl_connect_req(struct ishtp_device *dev, struct ishtp_cl *cl)
392368
{
393369
struct ishtp_msg_hdr hdr;
394-
unsigned char data[128];
395-
struct ishtp_msg_hdr *ishtp_hdr = &hdr;
396-
const size_t len = sizeof(struct hbm_client_connect_request);
370+
struct hbm_client_connect_request conn_req;
371+
const size_t len = sizeof(conn_req);
397372

398-
ishtp_hbm_hdr(ishtp_hdr, len);
399-
ishtp_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, data, len);
373+
ishtp_hbm_hdr(&hdr, len);
374+
ishtp_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, &conn_req, len);
400375

401-
return ishtp_write_message(dev, ishtp_hdr, data);
376+
return ishtp_write_message(dev, &hdr, &conn_req);
402377
}
403378

404379
/**

0 commit comments

Comments
 (0)