hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/hid/intel-ish-hid/ishtp/hbm.c
....@@ -1,17 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * ISHTP bus layer messages handling
34 *
45 * Copyright (c) 2003-2016, Intel Corporation.
5
- *
6
- * This program is free software; you can redistribute it and/or modify it
7
- * under the terms and conditions of the GNU General Public License,
8
- * version 2, as published by the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope it will be useful, but WITHOUT
11
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13
- * more details.
14
- *
156 */
167
178 #include <linux/export.h>
....@@ -136,19 +127,14 @@
136127 int ishtp_hbm_start_req(struct ishtp_device *dev)
137128 {
138129 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);
130
+ struct hbm_host_version_request start_req = { 0 };
143131
144
- ishtp_hbm_hdr(ishtp_hdr, len);
132
+ ishtp_hbm_hdr(&hdr, sizeof(start_req));
145133
146134 /* 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;
135
+ start_req.hbm_cmd = HOST_START_REQ_CMD;
136
+ start_req.host_version.major_version = HBM_MAJOR_VERSION;
137
+ start_req.host_version.minor_version = HBM_MINOR_VERSION;
152138
153139 /*
154140 * (!) Response to HBM start may be so quick that this thread would get
....@@ -156,7 +142,7 @@
156142 * So set it at first, change back to ISHTP_HBM_IDLE upon failure
157143 */
158144 dev->hbm_state = ISHTP_HBM_START;
159
- if (ishtp_write_message(dev, ishtp_hdr, data)) {
145
+ if (ishtp_write_message(dev, &hdr, &start_req)) {
160146 dev_err(dev->devc, "version message send failed\n");
161147 dev->dev_state = ISHTP_DEV_RESETTING;
162148 dev->hbm_state = ISHTP_HBM_IDLE;
....@@ -178,19 +164,13 @@
178164 void ishtp_hbm_enum_clients_req(struct ishtp_device *dev)
179165 {
180166 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);
167
+ struct hbm_host_enum_request enum_req = { 0 };
185168
186169 /* enumerate clients */
187
- ishtp_hbm_hdr(ishtp_hdr, len);
170
+ ishtp_hbm_hdr(&hdr, sizeof(enum_req));
171
+ enum_req.hbm_cmd = HOST_ENUM_REQ_CMD;
188172
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)) {
173
+ if (ishtp_write_message(dev, &hdr, &enum_req)) {
194174 dev->dev_state = ISHTP_DEV_RESETTING;
195175 dev_err(dev->devc, "enumeration request send failed\n");
196176 ish_hw_reset(dev);
....@@ -208,12 +188,8 @@
208188 */
209189 static int ishtp_hbm_prop_req(struct ishtp_device *dev)
210190 {
211
-
212191 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);
192
+ struct hbm_props_request prop_req = { 0 };
217193 unsigned long next_client_index;
218194 uint8_t client_num;
219195
....@@ -237,15 +213,12 @@
237213
238214 dev->fw_clients[client_num].client_id = next_client_index;
239215
240
- ishtp_hbm_hdr(ishtp_hdr, len);
241
- prop_req = (struct hbm_props_request *)data;
216
+ ishtp_hbm_hdr(&hdr, sizeof(prop_req));
242217
243
- memset(prop_req, 0, sizeof(struct hbm_props_request));
218
+ prop_req.hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD;
219
+ prop_req.address = next_client_index;
244220
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)) {
221
+ if (ishtp_write_message(dev, &hdr, &prop_req)) {
249222 dev->dev_state = ISHTP_DEV_RESETTING;
250223 dev_err(dev->devc, "properties request send failed\n");
251224 ish_hw_reset(dev);
....@@ -266,19 +239,14 @@
266239 static void ishtp_hbm_stop_req(struct ishtp_device *dev)
267240 {
268241 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);
242
+ struct hbm_host_stop_request stop_req = { 0 } ;
273243
274
- ishtp_hbm_hdr(ishtp_hdr, len);
275
- req = (struct hbm_host_stop_request *)data;
244
+ ishtp_hbm_hdr(&hdr, sizeof(stop_req));
276245
277
- memset(req, 0, sizeof(struct hbm_host_stop_request));
278
- req->hbm_cmd = HOST_STOP_REQ_CMD;
279
- req->reason = DRIVER_STOP_REQUEST;
246
+ stop_req.hbm_cmd = HOST_STOP_REQ_CMD;
247
+ stop_req.reason = DRIVER_STOP_REQUEST;
280248
281
- ishtp_write_message(dev, ishtp_hdr, data);
249
+ ishtp_write_message(dev, &hdr, &stop_req);
282250 }
283251
284252 /**
....@@ -294,15 +262,15 @@
294262 struct ishtp_cl *cl)
295263 {
296264 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);
265
+ struct hbm_flow_control flow_ctrl;
266
+ const size_t len = sizeof(flow_ctrl);
300267 int rv;
301268 unsigned long flags;
302269
303270 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);
271
+
272
+ ishtp_hbm_hdr(&hdr, len);
273
+ ishtp_hbm_cl_hdr(cl, ISHTP_FLOW_CONTROL_CMD, &flow_ctrl, len);
306274
307275 /*
308276 * Sync possible race when RB recycle and packet receive paths
....@@ -315,7 +283,7 @@
315283
316284 cl->recv_msg_num_frags = 0;
317285
318
- rv = ishtp_write_message(dev, ishtp_hdr, data);
286
+ rv = ishtp_write_message(dev, &hdr, &flow_ctrl);
319287 if (!rv) {
320288 ++cl->out_flow_ctrl_creds;
321289 ++cl->out_flow_ctrl_cnt;
....@@ -345,14 +313,13 @@
345313 int ishtp_hbm_cl_disconnect_req(struct ishtp_device *dev, struct ishtp_cl *cl)
346314 {
347315 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);
316
+ struct hbm_client_connect_request disconn_req;
317
+ const size_t len = sizeof(disconn_req);
351318
352
- ishtp_hbm_hdr(ishtp_hdr, len);
353
- ishtp_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, data, len);
319
+ ishtp_hbm_hdr(&hdr, len);
320
+ ishtp_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, &disconn_req, len);
354321
355
- return ishtp_write_message(dev, ishtp_hdr, data);
322
+ return ishtp_write_message(dev, &hdr, &disconn_req);
356323 }
357324
358325 /**
....@@ -391,14 +358,13 @@
391358 int ishtp_hbm_cl_connect_req(struct ishtp_device *dev, struct ishtp_cl *cl)
392359 {
393360 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);
361
+ struct hbm_client_connect_request conn_req;
362
+ const size_t len = sizeof(conn_req);
397363
398
- ishtp_hbm_hdr(ishtp_hdr, len);
399
- ishtp_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, data, len);
364
+ ishtp_hbm_hdr(&hdr, len);
365
+ ishtp_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, &conn_req, len);
400366
401
- return ishtp_write_message(dev, ishtp_hdr, data);
367
+ return ishtp_write_message(dev, &hdr, &conn_req);
402368 }
403369
404370 /**
....@@ -436,7 +402,7 @@
436402 * @dev: ISHTP device instance
437403 * @disconnect_req: disconnect request structure
438404 *
439
- * Disconnect request bus message from the fw. Send diconnect response.
405
+ * Disconnect request bus message from the fw. Send disconnect response.
440406 */
441407 static void ishtp_hbm_fw_disconnect_req(struct ishtp_device *dev,
442408 struct hbm_client_connect_request *disconnect_req)