Message ID | 20190212120523.27463-4-hong.liu@intel.com (mailing list archive) |
---|---|
State | Mainlined |
Commit | 09cc8b361887787a3577aa0b6510af4b11b51b9e |
Delegated to: | Jiri Kosina |
Headers | show |
Series | [1/4] HID: intel-ish-hid: avoid binding wrong ishtp_cl_device | expand |
On Tue, 2019-02-12 at 20:05 +0800, Hong Liu wrote: > 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 <hong.liu@intel.com> > Tested-by: Hongyan Song <hongyan.song@intel.com> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> > --- > drivers/hid/intel-ish-hid/ishtp/bus.c | 2 +- > drivers/hid/intel-ish-hid/ishtp/bus.h | 2 +- > drivers/hid/intel-ish-hid/ishtp/hbm.c | 97 ++++++++++--------------- > -- > 3 files changed, 38 insertions(+), 63 deletions(-) > > diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.c > b/drivers/hid/intel-ish-hid/ishtp/bus.c > index a271d6d169b1..f358a02325da 100644 > --- a/drivers/hid/intel-ish-hid/ishtp/bus.c > +++ b/drivers/hid/intel-ish-hid/ishtp/bus.c > @@ -119,7 +119,7 @@ int ishtp_send_msg(struct ishtp_device *dev, > struct ishtp_msg_hdr *hdr, > * Return: This returns IPC send message status. > */ > int ishtp_write_message(struct ishtp_device *dev, struct > ishtp_msg_hdr *hdr, > - unsigned char *buf) > + void *buf) > { > return ishtp_send_msg(dev, hdr, buf, NULL, NULL); > } > diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.h > b/drivers/hid/intel-ish-hid/ishtp/bus.h > index b8a5bcc82536..5c4763d73f8b 100644 > --- a/drivers/hid/intel-ish-hid/ishtp/bus.h > +++ b/drivers/hid/intel-ish-hid/ishtp/bus.h > @@ -85,7 +85,7 @@ int ishtp_send_msg(struct ishtp_device *dev, > /* Write a single-fragment message */ > int ishtp_write_message(struct ishtp_device *dev, > struct ishtp_msg_hdr *hdr, > - unsigned char *buf); > + void *buf); > > /* Use DMA to send/receive messages */ > int ishtp_use_dma_transfer(void); > diff --git a/drivers/hid/intel-ish-hid/ishtp/hbm.c > b/drivers/hid/intel-ish-hid/ishtp/hbm.c > index 8b5dd580ceec..d0b847c86935 100644 > --- a/drivers/hid/intel-ish-hid/ishtp/hbm.c > +++ b/drivers/hid/intel-ish-hid/ishtp/hbm.c > @@ -136,19 +136,14 @@ int ishtp_hbm_start_wait(struct ishtp_device > *dev) > int ishtp_hbm_start_req(struct ishtp_device *dev) > { > struct ishtp_msg_hdr hdr; > - unsigned char data[128]; > - struct ishtp_msg_hdr *ishtp_hdr = &hdr; > - struct hbm_host_version_request *start_req; > - const size_t len = sizeof(struct hbm_host_version_request); > + struct hbm_host_version_request start_req = { 0 }; > > - ishtp_hbm_hdr(ishtp_hdr, len); > + ishtp_hbm_hdr(&hdr, sizeof(start_req)); > > /* host start message */ > - start_req = (struct hbm_host_version_request *)data; > - memset(start_req, 0, len); > - start_req->hbm_cmd = HOST_START_REQ_CMD; > - start_req->host_version.major_version = HBM_MAJOR_VERSION; > - start_req->host_version.minor_version = HBM_MINOR_VERSION; > + start_req.hbm_cmd = HOST_START_REQ_CMD; > + start_req.host_version.major_version = HBM_MAJOR_VERSION; > + start_req.host_version.minor_version = HBM_MINOR_VERSION; > > /* > * (!) Response to HBM start may be so quick that this thread > would get > @@ -156,7 +151,7 @@ int ishtp_hbm_start_req(struct ishtp_device *dev) > * So set it at first, change back to ISHTP_HBM_IDLE upon > failure > */ > dev->hbm_state = ISHTP_HBM_START; > - if (ishtp_write_message(dev, ishtp_hdr, data)) { > + if (ishtp_write_message(dev, &hdr, &start_req)) { > dev_err(dev->devc, "version message send failed\n"); > dev->dev_state = ISHTP_DEV_RESETTING; > dev->hbm_state = ISHTP_HBM_IDLE; > @@ -178,19 +173,13 @@ int ishtp_hbm_start_req(struct ishtp_device > *dev) > void ishtp_hbm_enum_clients_req(struct ishtp_device *dev) > { > struct ishtp_msg_hdr hdr; > - unsigned char data[128]; > - struct ishtp_msg_hdr *ishtp_hdr = &hdr; > - struct hbm_host_enum_request *enum_req; > - const size_t len = sizeof(struct hbm_host_enum_request); > + struct hbm_host_enum_request enum_req = { 0 }; > > /* enumerate clients */ > - ishtp_hbm_hdr(ishtp_hdr, len); > + ishtp_hbm_hdr(&hdr, sizeof(enum_req)); > + enum_req.hbm_cmd = HOST_ENUM_REQ_CMD; > > - enum_req = (struct hbm_host_enum_request *)data; > - memset(enum_req, 0, len); > - enum_req->hbm_cmd = HOST_ENUM_REQ_CMD; > - > - if (ishtp_write_message(dev, ishtp_hdr, data)) { > + if (ishtp_write_message(dev, &hdr, &enum_req)) { > dev->dev_state = ISHTP_DEV_RESETTING; > dev_err(dev->devc, "enumeration request send > failed\n"); > ish_hw_reset(dev); > @@ -208,12 +197,8 @@ void ishtp_hbm_enum_clients_req(struct > ishtp_device *dev) > */ > static int ishtp_hbm_prop_req(struct ishtp_device *dev) > { > - > struct ishtp_msg_hdr hdr; > - unsigned char data[128]; > - struct ishtp_msg_hdr *ishtp_hdr = &hdr; > - struct hbm_props_request *prop_req; > - const size_t len = sizeof(struct hbm_props_request); > + struct hbm_props_request prop_req = { 0 }; > unsigned long next_client_index; > uint8_t client_num; > > @@ -237,15 +222,12 @@ static int ishtp_hbm_prop_req(struct > ishtp_device *dev) > > dev->fw_clients[client_num].client_id = next_client_index; > > - ishtp_hbm_hdr(ishtp_hdr, len); > - prop_req = (struct hbm_props_request *)data; > + ishtp_hbm_hdr(&hdr, sizeof(prop_req)); > > - memset(prop_req, 0, sizeof(struct hbm_props_request)); > + prop_req.hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; > + prop_req.address = next_client_index; > > - prop_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; > - prop_req->address = next_client_index; > - > - if (ishtp_write_message(dev, ishtp_hdr, data)) { > + if (ishtp_write_message(dev, &hdr, &prop_req)) { > dev->dev_state = ISHTP_DEV_RESETTING; > dev_err(dev->devc, "properties request send failed\n"); > ish_hw_reset(dev); > @@ -266,19 +248,14 @@ static int ishtp_hbm_prop_req(struct > ishtp_device *dev) > static void ishtp_hbm_stop_req(struct ishtp_device *dev) > { > struct ishtp_msg_hdr hdr; > - unsigned char data[128]; > - struct ishtp_msg_hdr *ishtp_hdr = &hdr; > - struct hbm_host_stop_request *req; > - const size_t len = sizeof(struct hbm_host_stop_request); > + struct hbm_host_stop_request stop_req = { 0 } ; > > - ishtp_hbm_hdr(ishtp_hdr, len); > - req = (struct hbm_host_stop_request *)data; > + ishtp_hbm_hdr(&hdr, sizeof(stop_req)); > > - memset(req, 0, sizeof(struct hbm_host_stop_request)); > - req->hbm_cmd = HOST_STOP_REQ_CMD; > - req->reason = DRIVER_STOP_REQUEST; > + stop_req.hbm_cmd = HOST_STOP_REQ_CMD; > + stop_req.reason = DRIVER_STOP_REQUEST; > > - ishtp_write_message(dev, ishtp_hdr, data); > + ishtp_write_message(dev, &hdr, &stop_req); > } > > /** > @@ -294,15 +271,15 @@ int ishtp_hbm_cl_flow_control_req(struct > ishtp_device *dev, > struct ishtp_cl *cl) > { > struct ishtp_msg_hdr hdr; > - unsigned char data[128]; > - struct ishtp_msg_hdr *ishtp_hdr = &hdr; > - const size_t len = sizeof(struct hbm_flow_control); > + struct hbm_flow_control flow_ctrl; > + const size_t len = sizeof(flow_ctrl); > int rv; > unsigned long flags; > > spin_lock_irqsave(&cl->fc_spinlock, flags); > - ishtp_hbm_hdr(ishtp_hdr, len); > - ishtp_hbm_cl_hdr(cl, ISHTP_FLOW_CONTROL_CMD, data, len); > + > + ishtp_hbm_hdr(&hdr, len); > + ishtp_hbm_cl_hdr(cl, ISHTP_FLOW_CONTROL_CMD, &flow_ctrl, len); > > /* > * 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, > > cl->recv_msg_num_frags = 0; > > - rv = ishtp_write_message(dev, ishtp_hdr, data); > + rv = ishtp_write_message(dev, &hdr, &flow_ctrl); > if (!rv) { > ++cl->out_flow_ctrl_creds; > ++cl->out_flow_ctrl_cnt; > @@ -345,14 +322,13 @@ int ishtp_hbm_cl_flow_control_req(struct > ishtp_device *dev, > int ishtp_hbm_cl_disconnect_req(struct ishtp_device *dev, struct > ishtp_cl *cl) > { > struct ishtp_msg_hdr hdr; > - unsigned char data[128]; > - struct ishtp_msg_hdr *ishtp_hdr = &hdr; > - const size_t len = sizeof(struct hbm_client_connect_request); > + struct hbm_client_connect_request disconn_req; > + const size_t len = sizeof(disconn_req); > > - ishtp_hbm_hdr(ishtp_hdr, len); > - ishtp_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, data, len); > + ishtp_hbm_hdr(&hdr, len); > + ishtp_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, &disconn_req, > len); > > - return ishtp_write_message(dev, ishtp_hdr, data); > + return ishtp_write_message(dev, &hdr, &disconn_req); > } > > /** > @@ -391,14 +367,13 @@ static void ishtp_hbm_cl_disconnect_res(struct > ishtp_device *dev, > int ishtp_hbm_cl_connect_req(struct ishtp_device *dev, struct > ishtp_cl *cl) > { > struct ishtp_msg_hdr hdr; > - unsigned char data[128]; > - struct ishtp_msg_hdr *ishtp_hdr = &hdr; > - const size_t len = sizeof(struct hbm_client_connect_request); > + struct hbm_client_connect_request conn_req; > + const size_t len = sizeof(conn_req); > > - ishtp_hbm_hdr(ishtp_hdr, len); > - ishtp_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, data, len); > + ishtp_hbm_hdr(&hdr, len); > + ishtp_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, &conn_req, len); > > - return ishtp_write_message(dev, ishtp_hdr, data); > + return ishtp_write_message(dev, &hdr, &conn_req); > } > > /**
diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.c b/drivers/hid/intel-ish-hid/ishtp/bus.c index a271d6d169b1..f358a02325da 100644 --- a/drivers/hid/intel-ish-hid/ishtp/bus.c +++ b/drivers/hid/intel-ish-hid/ishtp/bus.c @@ -119,7 +119,7 @@ int ishtp_send_msg(struct ishtp_device *dev, struct ishtp_msg_hdr *hdr, * Return: This returns IPC send message status. */ int ishtp_write_message(struct ishtp_device *dev, struct ishtp_msg_hdr *hdr, - unsigned char *buf) + void *buf) { return ishtp_send_msg(dev, hdr, buf, NULL, NULL); } diff --git a/drivers/hid/intel-ish-hid/ishtp/bus.h b/drivers/hid/intel-ish-hid/ishtp/bus.h index b8a5bcc82536..5c4763d73f8b 100644 --- a/drivers/hid/intel-ish-hid/ishtp/bus.h +++ b/drivers/hid/intel-ish-hid/ishtp/bus.h @@ -85,7 +85,7 @@ int ishtp_send_msg(struct ishtp_device *dev, /* Write a single-fragment message */ int ishtp_write_message(struct ishtp_device *dev, struct ishtp_msg_hdr *hdr, - unsigned char *buf); + void *buf); /* Use DMA to send/receive messages */ int ishtp_use_dma_transfer(void); diff --git a/drivers/hid/intel-ish-hid/ishtp/hbm.c b/drivers/hid/intel-ish-hid/ishtp/hbm.c index 8b5dd580ceec..d0b847c86935 100644 --- a/drivers/hid/intel-ish-hid/ishtp/hbm.c +++ b/drivers/hid/intel-ish-hid/ishtp/hbm.c @@ -136,19 +136,14 @@ int ishtp_hbm_start_wait(struct ishtp_device *dev) int ishtp_hbm_start_req(struct ishtp_device *dev) { struct ishtp_msg_hdr hdr; - unsigned char data[128]; - struct ishtp_msg_hdr *ishtp_hdr = &hdr; - struct hbm_host_version_request *start_req; - const size_t len = sizeof(struct hbm_host_version_request); + struct hbm_host_version_request start_req = { 0 }; - ishtp_hbm_hdr(ishtp_hdr, len); + ishtp_hbm_hdr(&hdr, sizeof(start_req)); /* host start message */ - start_req = (struct hbm_host_version_request *)data; - memset(start_req, 0, len); - start_req->hbm_cmd = HOST_START_REQ_CMD; - start_req->host_version.major_version = HBM_MAJOR_VERSION; - start_req->host_version.minor_version = HBM_MINOR_VERSION; + start_req.hbm_cmd = HOST_START_REQ_CMD; + start_req.host_version.major_version = HBM_MAJOR_VERSION; + start_req.host_version.minor_version = HBM_MINOR_VERSION; /* * (!) Response to HBM start may be so quick that this thread would get @@ -156,7 +151,7 @@ int ishtp_hbm_start_req(struct ishtp_device *dev) * So set it at first, change back to ISHTP_HBM_IDLE upon failure */ dev->hbm_state = ISHTP_HBM_START; - if (ishtp_write_message(dev, ishtp_hdr, data)) { + if (ishtp_write_message(dev, &hdr, &start_req)) { dev_err(dev->devc, "version message send failed\n"); dev->dev_state = ISHTP_DEV_RESETTING; dev->hbm_state = ISHTP_HBM_IDLE; @@ -178,19 +173,13 @@ int ishtp_hbm_start_req(struct ishtp_device *dev) void ishtp_hbm_enum_clients_req(struct ishtp_device *dev) { struct ishtp_msg_hdr hdr; - unsigned char data[128]; - struct ishtp_msg_hdr *ishtp_hdr = &hdr; - struct hbm_host_enum_request *enum_req; - const size_t len = sizeof(struct hbm_host_enum_request); + struct hbm_host_enum_request enum_req = { 0 }; /* enumerate clients */ - ishtp_hbm_hdr(ishtp_hdr, len); + ishtp_hbm_hdr(&hdr, sizeof(enum_req)); + enum_req.hbm_cmd = HOST_ENUM_REQ_CMD; - enum_req = (struct hbm_host_enum_request *)data; - memset(enum_req, 0, len); - enum_req->hbm_cmd = HOST_ENUM_REQ_CMD; - - if (ishtp_write_message(dev, ishtp_hdr, data)) { + if (ishtp_write_message(dev, &hdr, &enum_req)) { dev->dev_state = ISHTP_DEV_RESETTING; dev_err(dev->devc, "enumeration request send failed\n"); ish_hw_reset(dev); @@ -208,12 +197,8 @@ void ishtp_hbm_enum_clients_req(struct ishtp_device *dev) */ static int ishtp_hbm_prop_req(struct ishtp_device *dev) { - struct ishtp_msg_hdr hdr; - unsigned char data[128]; - struct ishtp_msg_hdr *ishtp_hdr = &hdr; - struct hbm_props_request *prop_req; - const size_t len = sizeof(struct hbm_props_request); + struct hbm_props_request prop_req = { 0 }; unsigned long next_client_index; uint8_t client_num; @@ -237,15 +222,12 @@ static int ishtp_hbm_prop_req(struct ishtp_device *dev) dev->fw_clients[client_num].client_id = next_client_index; - ishtp_hbm_hdr(ishtp_hdr, len); - prop_req = (struct hbm_props_request *)data; + ishtp_hbm_hdr(&hdr, sizeof(prop_req)); - memset(prop_req, 0, sizeof(struct hbm_props_request)); + prop_req.hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; + prop_req.address = next_client_index; - prop_req->hbm_cmd = HOST_CLIENT_PROPERTIES_REQ_CMD; - prop_req->address = next_client_index; - - if (ishtp_write_message(dev, ishtp_hdr, data)) { + if (ishtp_write_message(dev, &hdr, &prop_req)) { dev->dev_state = ISHTP_DEV_RESETTING; dev_err(dev->devc, "properties request send failed\n"); ish_hw_reset(dev); @@ -266,19 +248,14 @@ static int ishtp_hbm_prop_req(struct ishtp_device *dev) static void ishtp_hbm_stop_req(struct ishtp_device *dev) { struct ishtp_msg_hdr hdr; - unsigned char data[128]; - struct ishtp_msg_hdr *ishtp_hdr = &hdr; - struct hbm_host_stop_request *req; - const size_t len = sizeof(struct hbm_host_stop_request); + struct hbm_host_stop_request stop_req = { 0 } ; - ishtp_hbm_hdr(ishtp_hdr, len); - req = (struct hbm_host_stop_request *)data; + ishtp_hbm_hdr(&hdr, sizeof(stop_req)); - memset(req, 0, sizeof(struct hbm_host_stop_request)); - req->hbm_cmd = HOST_STOP_REQ_CMD; - req->reason = DRIVER_STOP_REQUEST; + stop_req.hbm_cmd = HOST_STOP_REQ_CMD; + stop_req.reason = DRIVER_STOP_REQUEST; - ishtp_write_message(dev, ishtp_hdr, data); + ishtp_write_message(dev, &hdr, &stop_req); } /** @@ -294,15 +271,15 @@ int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev, struct ishtp_cl *cl) { struct ishtp_msg_hdr hdr; - unsigned char data[128]; - struct ishtp_msg_hdr *ishtp_hdr = &hdr; - const size_t len = sizeof(struct hbm_flow_control); + struct hbm_flow_control flow_ctrl; + const size_t len = sizeof(flow_ctrl); int rv; unsigned long flags; spin_lock_irqsave(&cl->fc_spinlock, flags); - ishtp_hbm_hdr(ishtp_hdr, len); - ishtp_hbm_cl_hdr(cl, ISHTP_FLOW_CONTROL_CMD, data, len); + + ishtp_hbm_hdr(&hdr, len); + ishtp_hbm_cl_hdr(cl, ISHTP_FLOW_CONTROL_CMD, &flow_ctrl, len); /* * 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, cl->recv_msg_num_frags = 0; - rv = ishtp_write_message(dev, ishtp_hdr, data); + rv = ishtp_write_message(dev, &hdr, &flow_ctrl); if (!rv) { ++cl->out_flow_ctrl_creds; ++cl->out_flow_ctrl_cnt; @@ -345,14 +322,13 @@ int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev, int ishtp_hbm_cl_disconnect_req(struct ishtp_device *dev, struct ishtp_cl *cl) { struct ishtp_msg_hdr hdr; - unsigned char data[128]; - struct ishtp_msg_hdr *ishtp_hdr = &hdr; - const size_t len = sizeof(struct hbm_client_connect_request); + struct hbm_client_connect_request disconn_req; + const size_t len = sizeof(disconn_req); - ishtp_hbm_hdr(ishtp_hdr, len); - ishtp_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, data, len); + ishtp_hbm_hdr(&hdr, len); + ishtp_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, &disconn_req, len); - return ishtp_write_message(dev, ishtp_hdr, data); + return ishtp_write_message(dev, &hdr, &disconn_req); } /** @@ -391,14 +367,13 @@ static void ishtp_hbm_cl_disconnect_res(struct ishtp_device *dev, int ishtp_hbm_cl_connect_req(struct ishtp_device *dev, struct ishtp_cl *cl) { struct ishtp_msg_hdr hdr; - unsigned char data[128]; - struct ishtp_msg_hdr *ishtp_hdr = &hdr; - const size_t len = sizeof(struct hbm_client_connect_request); + struct hbm_client_connect_request conn_req; + const size_t len = sizeof(conn_req); - ishtp_hbm_hdr(ishtp_hdr, len); - ishtp_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, data, len); + ishtp_hbm_hdr(&hdr, len); + ishtp_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, &conn_req, len); - return ishtp_write_message(dev, ishtp_hdr, data); + return ishtp_write_message(dev, &hdr, &conn_req); } /**