mei: use consistently me_addr in the hbm structures
Subsystems (2)
PATCH 1/14 mei: use consistently me_addr in the hbm structures
Use consistently me_addr name in hbm protocol structures to represent in firmware client address
--- drivers/misc/mei/hbm.c | 6 +++--- drivers/misc/mei/hw.h | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-)
drivers/misc/mei/hbm.c +3 -3
@@ -288,7 +288,7 @@ static int mei_hbm_prop_req(struct mei_device *dev) prop_req->hbm_cmd =HOST_CLIENT_PROPERTIES_REQ_CMD ; - prop_req->address = next_client_index; + prop_req->me_addr = next_client_index; ret =mei_write_message (dev, mei_hdr, dev->wr_msg.data);if (ret) {
@@ -783,9 +783,9 @@ int mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)return -EPROTO ; } -if (me_client->client_id != props_res->address) { +if (me_client->client_id != props_res->me_addr) {dev_err (&dev->pdev->dev,"hbm: properties response: address mismatch %d ?= %d\n" , - me_client->client_id, props_res->address); + me_client->client_id, props_res->me_addr);return -EPROTO ; }
drivers/misc/mei/hw.h +2 -3
@@ -206,14 +206,13 @@ struct mei_client_properties {struct hbm_props_request {u8 hbm_cmd; -u8 address; +u8 me_addr;u8 reserved[2 ]; } __packed; -struct hbm_props_response {u8 hbm_cmd; -u8 address; +u8 me_addr;u8 status;u8 reserved[1 ];struct mei_client_properties client_properties;
Signature · 1 line
1.9.3
PATCH 2/14 mei: use wrapper for simple hbm client message
Reduce few code lines by using wrappers for sending simple hbm client messages
--- drivers/misc/mei/hbm.c | 51 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 26 deletions(-)
drivers/misc/mei/hbm.c +25 -26
@@ -124,7 +124,7 @@ static int mei_hbm_me_cl_allocate(struct mei_device *dev)/** * mei_hbm_cl_hdr - construct client hbm header * -* @cl: - client +* @cl: client * @hbm_cmd: host bus message command * @buf: buffer for cl header * @len: buffer length
@@ -142,6 +142,26 @@ void mei_hbm_cl_hdr(struct mei_cl *cl, u8 hbm_cmd, void *buf, size_t len) }/** +* mei_hbm_cl_write - write simple hbm client message +* +* @dev: the device structure +* @cl: client +* @hbm_cmd: host bus message command +* @len: buffer length +*/ +static inline +int mei_hbm_cl_write (struct mei_device *dev, +struct mei_cl *cl,u8 hbm_cmd,size_t len) +{ +struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr; + +mei_hbm_hdr (mei_hdr, len); +mei_hbm_cl_hdr (cl, hbm_cmd, dev->wr_msg.data, len); + +return mei_write_message (dev, mei_hdr, dev->wr_msg.data); +} + +/** * mei_hbm_cl_addr_equal - tells if they have the same address * * @cl: - client
@@ -365,15 +385,9 @@ static int mei_hbm_stop_req(struct mei_device *dev)*/ int mei_hbm_cl_flow_control_req (struct mei_device *dev,struct mei_cl *cl) { -struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;const size_t len =sizeof (struct hbm_flow_control ); - -mei_hbm_hdr (mei_hdr, len); -mei_hbm_cl_hdr (cl,MEI_FLOW_CONTROL_CMD , dev->wr_msg.data, len); -cl_dbg (dev, cl,"sending flow control\n" ); - -return mei_write_message (dev, mei_hdr, dev->wr_msg.data); +return mei_hbm_cl_write (dev, cl,MEI_FLOW_CONTROL_CMD , len); }/**
@@ -452,13 +466,8 @@ static void mei_hbm_cl_flow_control_res(struct mei_device *dev,*/ int mei_hbm_cl_disconnect_req (struct mei_device *dev,struct mei_cl *cl) { -struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;const size_t len =sizeof (struct hbm_client_connect_request ); - -mei_hbm_hdr (mei_hdr, len); -mei_hbm_cl_hdr (cl,CLIENT_DISCONNECT_REQ_CMD , dev->wr_msg.data, len); - -return mei_write_message (dev, mei_hdr, dev->wr_msg.data); +return mei_hbm_cl_write (dev, cl,CLIENT_DISCONNECT_REQ_CMD , len); }/**
@@ -471,13 +480,8 @@ int mei_hbm_cl_disconnect_req(struct mei_device *dev, struct mei_cl *cl)*/ int mei_hbm_cl_disconnect_rsp (struct mei_device *dev,struct mei_cl *cl) { -struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;const size_t len =sizeof (struct hbm_client_connect_response ); - -mei_hbm_hdr (mei_hdr, len); -mei_hbm_cl_hdr (cl,CLIENT_DISCONNECT_RES_CMD , dev->wr_msg.data, len); - -return mei_write_message (dev, mei_hdr, dev->wr_msg.data); +return mei_hbm_cl_write (dev, cl,CLIENT_DISCONNECT_RES_CMD , len); }/**
@@ -526,13 +530,8 @@ static void mei_hbm_cl_disconnect_res(struct mei_device *dev,*/ int mei_hbm_cl_connect_req (struct mei_device *dev,struct mei_cl *cl) { -struct mei_msg_hdr *mei_hdr = &dev->wr_msg.hdr;const size_t len =sizeof (struct hbm_client_connect_request ); - -mei_hbm_hdr (mei_hdr, len); -mei_hbm_cl_hdr (cl,CLIENT_CONNECT_REQ_CMD , dev->wr_msg.data, len); - -return mei_write_message (dev, mei_hdr, dev->wr_msg.data); +return mei_hbm_cl_write (dev, cl,CLIENT_CONNECT_REQ_CMD , len); }/**
Signature · 1 line
1.9.3
PATCH 3/14 mei: me_client lookup function to return me_client object
In reply to Tomas WinklerIn order to support dynamic addition/removal of me clients we cannot It is incontinent to use static array and we can use list. As the first step we change the lookup function to return me client address instead of the index.
--- drivers/misc/mei/amthif.c | 29 +++++++++++------------------ drivers/misc/mei/bus.c | 10 +++++----- drivers/misc/mei/client.c | 43 ++++++++++++++++++++----------------------- drivers/misc/mei/client.h | 5 +++-- drivers/misc/mei/hbm.c | 23 +++++++++-------------- drivers/misc/mei/main.c | 30 ++++++++++++++---------------- drivers/misc/mei/nfc.c | 15 ++++++++------- drivers/misc/mei/wd.c | 8 ++++---- 8 files changed, 74 insertions(+), 89 deletions(-)
drivers/misc/mei/amthif.c +11 -18
@@ -68,27 +68,26 @@ void mei_amthif_reset_params(struct mei_device *dev)int mei_amthif_host_init (struct mei_device *dev) {struct mei_cl *cl = &dev->iamthif_cl; +struct mei_me_client *me_cl;unsigned char *msg_buf; -int ret, i; +int ret; dev->iamthif_state =MEI_IAMTHIF_IDLE ;mei_cl_init (cl, dev); - i =mei_me_cl_by_uuid (dev, &mei_amthif_guid); -if (i <0 ) { -dev_info (&dev->pdev->dev, -"amthif: failed to find the client %d\n" , i); + me_cl =mei_me_cl_by_uuid (dev, &mei_amthif_guid); +if (!me_cl) { +dev_info (&dev->pdev->dev,"amthif: failed to find the client" );return -ENOTTY ; } - cl->me_client_id = dev->me_clients[i].client_id; + cl->me_client_id = me_cl->client_id;/* Assign iamthif_mtu to the value received from ME */ - dev->iamthif_mtu = dev->me_clients[i].props.max_msg_length; -dev_dbg (&dev->pdev->dev,"IAMTHIF_MTU = %d\n" , - dev->me_clients[i].props.max_msg_length); + dev->iamthif_mtu = me_cl->props.max_msg_length; +dev_dbg (&dev->pdev->dev,"IAMTHIF_MTU = %d\n" , dev->iamthif_mtu);kfree (dev->iamthif_msg_buf); dev->iamthif_msg_buf =NULL ;
@@ -157,12 +156,11 @@ struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev,int mei_amthif_read (struct mei_device *dev,struct file *file,char __user *ubuf,size_t length,loff_t *offset) { -int rets; -int wait_ret; -struct mei_cl_cb *cb =NULL ;struct mei_cl *cl = file->private_data; +struct mei_cl_cb *cb;unsigned long timeout; -int i; +int rets; +int wait_ret;/* Only possible if we are in timeout */ if (!cl) {
@@ -170,11 +168,6 @@ int mei_amthif_read(struct mei_device *dev, struct file *file,return -ETIME ; } - i =mei_me_cl_by_id (dev, dev->iamthif_cl.me_client_id); -if (i <0 ) { -dev_dbg (&dev->pdev->dev,"amthif client not found.\n" ); -return -ENOTTY ; - }dev_dbg (&dev->pdev->dev,"checking amthif data\n" ); cb =mei_amthif_find_read_list_entry (dev, file);
drivers/misc/mei/bus.c +5 -5
@@ -229,8 +229,8 @@ static int ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, bool blocking) {struct mei_device *dev; +struct mei_me_client *me_cl;struct mei_cl_cb *cb; -int id;int rets;if (WARN_ON (!cl || !cl->dev))
@@ -242,11 +242,11 @@ static int ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,return -ENODEV ;/* Check if we have an ME client device */ - id =mei_me_cl_by_id (dev, cl->me_client_id); -if (id <0 ) -return id; + me_cl =mei_me_cl_by_id (dev, cl->me_client_id); +if (!me_cl) +return -ENOTTY ; -if (length > dev->me_clients[id].props.max_msg_length) +if (length > me_cl->props.max_msg_length)return -EFBIG ; cb =mei_io_cb_init (cl,NULL );
drivers/misc/mei/client.c +20 -23
120 lines not on this page · raw message
drivers/misc/mei/client.h +3 -2
@@ -24,8 +24,9 @@#include "mei_dev.h" -int mei_me_cl_by_uuid (const struct mei_device *dev,const uuid_le *cuuid); -int mei_me_cl_by_id (struct mei_device *dev,u8 client_id); +struct mei_me_client *mei_me_cl_by_uuid (const struct mei_device *dev, +const uuid_le *cuuid); +struct mei_me_client *mei_me_cl_by_id (struct mei_device *dev,u8 client_id);/* * MEI IO Functions
drivers/misc/mei/hbm.c +9 -14
@@ -402,25 +402,20 @@ static int mei_hbm_add_single_flow_creds(struct mei_device *dev, struct hbm_flow_control *flow) {struct mei_me_client *me_cl; -int id; - id =mei_me_cl_by_id (dev, flow->me_addr); -if (id <0 ) { + me_cl =mei_me_cl_by_id (dev, flow->me_addr); +if (!me_cl) {dev_err (&dev->pdev->dev,"no such me client %d\n" , flow->me_addr); -return id; +return -ENOENT ; } - me_cl = &dev->me_clients[id]; -if (me_cl->props.single_recv_buf) { - me_cl->mei_flow_ctrl_creds++; -dev_dbg (&dev->pdev->dev,"recv flow ctrl msg ME %d (single).\n" , - flow->me_addr); -dev_dbg (&dev->pdev->dev,"flow control credentials =%d.\n" , - me_cl->mei_flow_ctrl_creds); - }else { -BUG ();/* error in flow control */ - } +if (WARN_ON (me_cl->props.single_recv_buf ==0 )) +return -EINVAL ; + + me_cl->mei_flow_ctrl_creds++; +dev_dbg (&dev->pdev->dev,"recv flow ctrl msg ME %d (single) creds = %d.\n" , + flow->me_addr, me_cl->mei_flow_ctrl_creds);return 0 ; }
drivers/misc/mei/main.c +14 -16
@@ -303,11 +303,11 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, size_t length, loff_t *offset) { struct mei_cl *cl = file->private_data; +struct mei_me_client *me_cl;struct mei_cl_cb *write_cb =NULL ;struct mei_device *dev;unsigned long timeout =0 ;int rets; -int id;if (WARN_ON (!cl || !cl->dev))return -ENODEV ;
@@ -321,8 +321,8 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, goto out; } - id =mei_me_cl_by_id (dev, cl->me_client_id); -if (id <0 ) { + me_cl =mei_me_cl_by_id (dev, cl->me_client_id); +if (!me_cl) { rets = -ENOTTY ; goto out; }
@@ -332,7 +332,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, goto out; } -if (length > dev->me_clients[id].props.max_msg_length) { +if (length > me_cl->props.max_msg_length) { rets = -EFBIG ; goto out; }
@@ -428,8 +428,8 @@ static int mei_ioctl_connect_client(struct file *file, {struct mei_device *dev;struct mei_client *client; +struct mei_me_client *me_cl;struct mei_cl *cl; -int i;int rets; cl = file->private_data;
@@ -450,22 +450,22 @@ static int mei_ioctl_connect_client(struct file *file, }/* find ME client we're trying to connect to */ - i =mei_me_cl_by_uuid (dev, &data->in_client_uuid); -if (i <0 || dev->me_clients[i].props.fixed_address) { + me_cl =mei_me_cl_by_uuid (dev, &data->in_client_uuid); +if (!me_cl || me_cl->props.fixed_address) {dev_dbg (&dev->pdev->dev,"Cannot connect to FW Client UUID = %pUl\n" , &data->in_client_uuid); rets = -ENOTTY ; goto end; } - cl->me_client_id = dev->me_clients[i].client_id; + cl->me_client_id = me_cl->client_id;dev_dbg (&dev->pdev->dev,"Connect to FW Client ID = %d\n" , cl->me_client_id);dev_dbg (&dev->pdev->dev,"FW Client - Protocol Version = %d\n" , - dev->me_clients[i].props.protocol_version); + me_cl->props.protocol_version);dev_dbg (&dev->pdev->dev,"FW Client - Max Msg Len = %d\n" , - dev->me_clients[i].props.max_msg_length); + me_cl->props.max_msg_length);/* if we're connecting to amthif client then we will use the * existing connection
@@ -484,10 +484,8 @@ static int mei_ioctl_connect_client(struct file *file, file->private_data = &dev->iamthif_cl; client = &data->out_client_properties; - client->max_msg_length = - dev->me_clients[i].props.max_msg_length; - client->protocol_version = - dev->me_clients[i].props.protocol_version; + client->max_msg_length = me_cl->props.max_msg_length; + client->protocol_version = me_cl->props.protocol_version; rets = dev->iamthif_cl.status; goto end;
@@ -496,8 +494,8 @@ static int mei_ioctl_connect_client(struct file *file,/* prepare the output buffer */ client = &data->out_client_properties; - client->max_msg_length = dev->me_clients[i].props.max_msg_length; - client->protocol_version = dev->me_clients[i].props.protocol_version; + client->max_msg_length = me_cl->props.max_msg_length; + client->protocol_version = me_cl->props.protocol_version;dev_dbg (&dev->pdev->dev,"Can connect?\n" );
drivers/misc/mei/nfc.c +8 -7
@@ -480,7 +480,8 @@ int mei_nfc_host_init(struct mei_device *dev) {struct mei_nfc_dev *ndev = &nfc_dev;struct mei_cl *cl_info, *cl =NULL ; -int i, ret; +struct mei_me_client *me_cl; +int ret;/* already initialized */ if (ndev->cl_info)
@@ -498,14 +499,14 @@ int mei_nfc_host_init(struct mei_device *dev) }/* check for valid client id */ - i =mei_me_cl_by_uuid (dev, &mei_nfc_info_guid); -if (i <0 ) { + me_cl =mei_me_cl_by_uuid (dev, &mei_nfc_info_guid); +if (!me_cl) {dev_info (&dev->pdev->dev,"nfc: failed to find the client\n" ); ret = -ENOTTY ; goto err; } - cl_info->me_client_id = dev->me_clients[i].client_id; + cl_info->me_client_id = me_cl->client_id; ret =mei_cl_link (cl_info,MEI_HOST_CLIENT_ID_ANY );if (ret)
@@ -516,14 +517,14 @@ int mei_nfc_host_init(struct mei_device *dev)list_add_tail (&cl_info->device_link, &dev->device_list);/* check for valid client id */ - i =mei_me_cl_by_uuid (dev, &mei_nfc_guid); -if (i <0 ) { + me_cl =mei_me_cl_by_uuid (dev, &mei_nfc_guid); +if (!me_cl) {dev_info (&dev->pdev->dev,"nfc: failed to find the client\n" ); ret = -ENOTTY ; goto err; } - cl->me_client_id = dev->me_clients[i].client_id; + cl->me_client_id = me_cl->client_id; ret =mei_cl_link (cl,MEI_HOST_CLIENT_ID_ANY );if (ret)
drivers/misc/mei/wd.c +4 -4
@@ -59,7 +59,7 @@ static void mei_wd_set_start_timeout(struct mei_device *dev, u16 timeout)int mei_wd_host_init (struct mei_device *dev) {struct mei_cl *cl = &dev->wd_cl; -int id; +struct mei_me_client *me_cl;int ret;mei_cl_init (cl, dev);
@@ -69,13 +69,13 @@ int mei_wd_host_init(struct mei_device *dev)/* check for valid client id */ - id =mei_me_cl_by_uuid (dev, &mei_wd_guid); -if (id <0 ) { + me_cl =mei_me_cl_by_uuid (dev, &mei_wd_guid); +if (!me_cl) {dev_info (&dev->pdev->dev,"wd: failed to find the client\n" );return -ENOTTY ; } - cl->me_client_id = dev->me_clients[id].client_id; + cl->me_client_id = me_cl->client_id; ret =mei_cl_link (cl,MEI_WD_HOST_CLIENT_ID );
Signature · 1 line
1.9.3
Re: [char-misc-next 03/14] mei: me_client lookup function to return me_client object
Quoted 1 line · Tomas Winkler
In order to support dynamic addition/removal of me clients we cannot
cannot what?
Quoted 3 lines
It is incontinent to use static array and we can use list. As the first step we change the lookup function to return me client address instead of the index.
This changelog seems to have some missing parts to it.
josh
Quoted 485 lines
Signed-off-by Tomas Winkler <[email protected]>--- drivers/misc/mei/amthif.c | 29 +++++++++++------------------ drivers/misc/mei/bus.c | 10 +++++----- drivers/misc/mei/client.c | 43 ++++++++++++++++++++----------------------- drivers/misc/mei/client.h | 5 +++-- drivers/misc/mei/hbm.c | 23 +++++++++-------------- drivers/misc/mei/main.c | 30 ++++++++++++++---------------- drivers/misc/mei/nfc.c | 15 ++++++++------- drivers/misc/mei/wd.c | 8 ++++---- 8 files changed, 74 insertions(+), 89 deletions(-)drivers/misc/mei/amthif.c +11
-18@@ -68,27 +68,26 @@ void mei_amthif_reset_params(struct mei_device *dev)int mei_amthif_host_init (struct mei_device *dev) {struct mei_cl *cl = &dev->iamthif_cl; +struct mei_me_client *me_cl;unsigned char *msg_buf; -int ret, i; +int ret; dev->iamthif_state =MEI_IAMTHIF_IDLE ;mei_cl_init (cl, dev); - i =mei_me_cl_by_uuid (dev, &mei_amthif_guid); -if (i <0 ) { -dev_info (&dev->pdev->dev, -"amthif: failed to find the client %d\n" , i); + me_cl =mei_me_cl_by_uuid (dev, &mei_amthif_guid); +if (!me_cl) { +dev_info (&dev->pdev->dev,"amthif: failed to find the client" );return -ENOTTY ; } - cl->me_client_id = dev->me_clients[i].client_id; + cl->me_client_id = me_cl->client_id;/* Assign iamthif_mtu to the value received from ME */ - dev->iamthif_mtu = dev->me_clients[i].props.max_msg_length; -dev_dbg (&dev->pdev->dev,"IAMTHIF_MTU = %d\n" , - dev->me_clients[i].props.max_msg_length); + dev->iamthif_mtu = me_cl->props.max_msg_length; +dev_dbg (&dev->pdev->dev,"IAMTHIF_MTU = %d\n" , dev->iamthif_mtu);kfree (dev->iamthif_msg_buf); dev->iamthif_msg_buf =NULL ;@@ -157,12 +156,11 @@ struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev,int mei_amthif_read (struct mei_device *dev,struct file *file,char __user *ubuf,size_t length,loff_t *offset) { -int rets; -int wait_ret; -struct mei_cl_cb *cb =NULL ;struct mei_cl *cl = file->private_data; +struct mei_cl_cb *cb;unsigned long timeout; -int i; +int rets; +int wait_ret;/* Only possible if we are in timeout */ if (!cl) {@@ -170,11 +168,6 @@ int mei_amthif_read(struct mei_device *dev, struct file *file,return -ETIME ; } - i =mei_me_cl_by_id (dev, dev->iamthif_cl.me_client_id); -if (i <0 ) { -dev_dbg (&dev->pdev->dev,"amthif client not found.\n" ); -return -ENOTTY ; - }dev_dbg (&dev->pdev->dev,"checking amthif data\n" ); cb =mei_amthif_find_read_list_entry (dev, file);drivers/misc/mei/bus.c +5
-5@@ -229,8 +229,8 @@ static int ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, bool blocking) {struct mei_device *dev; +struct mei_me_client *me_cl;struct mei_cl_cb *cb; -int id;int rets;if (WARN_ON (!cl || !cl->dev))@@ -242,11 +242,11 @@ static int ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,return -ENODEV ;/* Check if we have an ME client device */ - id =mei_me_cl_by_id (dev, cl->me_client_id); -if (id <0 ) -return id; + me_cl =mei_me_cl_by_id (dev, cl->me_client_id); +if (!me_cl) +return -ENOTTY ; -if (length > dev->me_clients[id].props.max_msg_length) +if (length > me_cl->props.max_msg_length)return -EFBIG ; cb =mei_io_cb_init (cl,NULL );drivers/misc/mei/client.c +20
-23@@ -33,18 +33,19 @@* * Locking: called under "dev->device_lock" lock * -* returns me client index or -ENOENT if not found +* returns me client or NULL if not found */ -int mei_me_cl_by_uuid (const struct mei_device *dev,const uuid_le *uuid) +struct mei_me_client *mei_me_cl_by_uuid (const struct mei_device *dev, +const uuid_le *uuid) {int i;for (i =0 ; i < dev->me_clients_num; ++i)if (uuid_le_cmp (*uuid, dev->me_clients[i].props.protocol_name) ==0 ) -return i; +return &dev->me_clients[i]; -return -ENOENT ; +return NULL ; }@@ -56,18 +57,18 @@ int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *uuid)* * Locking: called under "dev->device_lock" lock * -* returns index on success, -ENOENT on failure. +* returns me client or NULL if not found */ -int mei_me_cl_by_id (struct mei_device *dev,u8 client_id) +struct mei_me_client *mei_me_cl_by_id (struct mei_device *dev,u8 client_id) {int i;for (i =0 ; i < dev->me_clients_num; i++)if (dev->me_clients[i].client_id == client_id) -return i; +return &dev->me_clients[i]; -return -ENOENT ; +return NULL ; }@@ -646,7 +647,6 @@ int mei_cl_flow_ctrl_creds(struct mei_cl *cl) {struct mei_device *dev;struct mei_me_client *me_cl; -int id;if (WARN_ON (!cl || !cl->dev))return -EINVAL ;@@ -659,13 +659,12 @@ int mei_cl_flow_ctrl_creds(struct mei_cl *cl)if (cl->mei_flow_ctrl_creds >0 )return 1 ; - id =mei_me_cl_by_id (dev, cl->me_client_id); -if (id <0 ) { + me_cl =mei_me_cl_by_id (dev, cl->me_client_id); +if (!me_cl) {cl_err (dev, cl,"no such me client %d\n" , cl->me_client_id); -return id; +return -ENOENT ; } - me_cl = &dev->me_clients[id];if (me_cl->mei_flow_ctrl_creds) {if (WARN_ON (me_cl->props.single_recv_buf ==0 ))return -EINVAL ;@@ -688,21 +687,19 @@ int mei_cl_flow_ctrl_reduce(struct mei_cl *cl) {struct mei_device *dev;struct mei_me_client *me_cl; -int id;if (WARN_ON (!cl || !cl->dev))return -EINVAL ; dev = cl->dev; - id =mei_me_cl_by_id (dev, cl->me_client_id); -if (id <0 ) { + me_cl =mei_me_cl_by_id (dev, cl->me_client_id); +if (!me_cl) {cl_err (dev, cl,"no such me client %d\n" , cl->me_client_id); -return id; +return -ENOENT ; } - me_cl = &dev->me_clients[id]; -if (me_cl->props.single_recv_buf !=0 ) { +if (me_cl->props.single_recv_buf) {if (WARN_ON (me_cl->mei_flow_ctrl_creds <=0 ))return -EINVAL ; me_cl->mei_flow_ctrl_creds--;@@ -725,8 +722,8 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length) {struct mei_device *dev;struct mei_cl_cb *cb; +struct mei_me_client *me_cl;int rets; -int i;if (WARN_ON (!cl || !cl->dev))return -ENODEV ;@@ -740,8 +737,8 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length)cl_dbg (dev, cl,"read is pending.\n" );return -EBUSY ; } - i =mei_me_cl_by_id (dev, cl->me_client_id); -if (i <0 ) { + me_cl =mei_me_cl_by_id (dev, cl->me_client_id); +if (!me_cl) {cl_err (dev, cl,"no such me client %d\n" , cl->me_client_id);return -ENOTTY ; }@@ -760,7 +757,7 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length) }/* always allocate at least client max message */ - length =max_t (size_t, length, dev->me_clients[i].props.max_msg_length); + length =max_t (size_t, length, me_cl->props.max_msg_length); rets =mei_io_cb_alloc_resp_buf (cb, length);if (rets) goto out;drivers/misc/mei/client.h +3
-2@@ -24,8 +24,9 @@#include "mei_dev.h" -int mei_me_cl_by_uuid (const struct mei_device *dev,const uuid_le *cuuid); -int mei_me_cl_by_id (struct mei_device *dev,u8 client_id); +struct mei_me_client *mei_me_cl_by_uuid (const struct mei_device *dev, +const uuid_le *cuuid); +struct mei_me_client *mei_me_cl_by_id (struct mei_device *dev,u8 client_id);/* * MEI IO Functions drivers/misc/mei/hbm.c +9
-14@@ -402,25 +402,20 @@ static int mei_hbm_add_single_flow_creds(struct mei_device *dev, struct hbm_flow_control *flow) {struct mei_me_client *me_cl; -int id; - id =mei_me_cl_by_id (dev, flow->me_addr); -if (id <0 ) { + me_cl =mei_me_cl_by_id (dev, flow->me_addr); +if (!me_cl) {dev_err (&dev->pdev->dev,"no such me client %d\n" , flow->me_addr); -return id; +return -ENOENT ; } - me_cl = &dev->me_clients[id]; -if (me_cl->props.single_recv_buf) { - me_cl->mei_flow_ctrl_creds++; -dev_dbg (&dev->pdev->dev,"recv flow ctrl msg ME %d (single).\n" , - flow->me_addr); -dev_dbg (&dev->pdev->dev,"flow control credentials =%d.\n" , - me_cl->mei_flow_ctrl_creds); - }else { -BUG ();/* error in flow control */ - } +if (WARN_ON (me_cl->props.single_recv_buf ==0 )) +return -EINVAL ; + + me_cl->mei_flow_ctrl_creds++; +dev_dbg (&dev->pdev->dev,"recv flow ctrl msg ME %d (single) creds = %d.\n" , + flow->me_addr, me_cl->mei_flow_ctrl_creds);return 0 ; }drivers/misc/mei/main.c +14
-16@@ -303,11 +303,11 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, size_t length, loff_t *offset) { struct mei_cl *cl = file->private_data; +struct mei_me_client *me_cl;struct mei_cl_cb *write_cb =NULL ;struct mei_device *dev;unsigned long timeout =0 ;int rets; -int id;if (WARN_ON (!cl || !cl->dev))return -ENODEV ;@@ -321,8 +321,8 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, goto out; } - id =mei_me_cl_by_id (dev, cl->me_client_id); -if (id <0 ) { + me_cl =mei_me_cl_by_id (dev, cl->me_client_id); +if (!me_cl) { rets = -ENOTTY ; goto out; }@@ -332,7 +332,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, goto out; } -if (length > dev->me_clients[id].props.max_msg_length) { +if (length > me_cl->props.max_msg_length) { rets = -EFBIG ; goto out; }@@ -428,8 +428,8 @@ static int mei_ioctl_connect_client(struct file *file, {struct mei_device *dev;struct mei_client *client; +struct mei_me_client *me_cl;struct mei_cl *cl; -int i;int rets; cl = file->private_data;@@ -450,22 +450,22 @@ static int mei_ioctl_connect_client(struct file *file, }/* find ME client we're trying to connect to */ - i =mei_me_cl_by_uuid (dev, &data->in_client_uuid); -if (i <0 || dev->me_clients[i].props.fixed_address) { + me_cl =mei_me_cl_by_uuid (dev, &data->in_client_uuid); +if (!me_cl || me_cl->props.fixed_address) {dev_dbg (&dev->pdev->dev,"Cannot connect to FW Client UUID = %pUl\n" , &data->in_client_uuid); rets = -ENOTTY ; goto end; } - cl->me_client_id = dev->me_clients[i].client_id; + cl->me_client_id = me_cl->client_id;dev_dbg (&dev->pdev->dev,"Connect to FW Client ID = %d\n" , cl->me_client_id);dev_dbg (&dev->pdev->dev,"FW Client - Protocol Version = %d\n" , - dev->me_clients[i].props.protocol_version); + me_cl->props.protocol_version);dev_dbg (&dev->pdev->dev,"FW Client - Max Msg Len = %d\n" , - dev->me_clients[i].props.max_msg_length); + me_cl->props.max_msg_length);/* if we're connecting to amthif client then we will use the * existing connection @@ -484,10 +484,8 @@ static int mei_ioctl_connect_client(struct file *file, file->private_data = &dev->iamthif_cl; client = &data->out_client_properties; - client->max_msg_length = - dev->me_clients[i].props.max_msg_length; - client->protocol_version = - dev->me_clients[i].props.protocol_version; + client->max_msg_length = me_cl->props.max_msg_length; + client->protocol_version = me_cl->props.protocol_version; rets = dev->iamthif_cl.status; goto end;@@ -496,8 +494,8 @@ static int mei_ioctl_connect_client(struct file *file,/* prepare the output buffer */ client = &data->out_client_properties; - client->max_msg_length = dev->me_clients[i].props.max_msg_length; - client->protocol_version = dev->me_clients[i].props.protocol_version; + client->max_msg_length = me_cl->props.max_msg_length; + client->protocol_version = me_cl->props.protocol_version;dev_dbg (&dev->pdev->dev,"Can connect?\n" );drivers/misc/mei/nfc.c +8
-7@@ -480,7 +480,8 @@ int mei_nfc_host_init(struct mei_device *dev) {struct mei_nfc_dev *ndev = &nfc_dev;struct mei_cl *cl_info, *cl =NULL ; -int i, ret; +struct mei_me_client *me_cl; +int ret;/* already initialized */ if (ndev->cl_info)@@ -498,14 +499,14 @@ int mei_nfc_host_init(struct mei_device *dev) }/* check for valid client id */ - i =mei_me_cl_by_uuid (dev, &mei_nfc_info_guid); -if (i <0 ) { + me_cl =mei_me_cl_by_uuid (dev, &mei_nfc_info_guid); +if (!me_cl) {dev_info (&dev->pdev->dev,"nfc: failed to find the client\n" ); ret = -ENOTTY ; goto err; } - cl_info->me_client_id = dev->me_clients[i].client_id; + cl_info->me_client_id = me_cl->client_id; ret =mei_cl_link (cl_info,MEI_HOST_CLIENT_ID_ANY );if (ret)@@ -516,14 +517,14 @@ int mei_nfc_host_init(struct mei_device *dev)list_add_tail (&cl_info->device_link, &dev->device_list);/* check for valid client id */ - i =mei_me_cl_by_uuid (dev, &mei_nfc_guid); -if (i <0 ) { + me_cl =mei_me_cl_by_uuid (dev, &mei_nfc_guid); +if (!me_cl) {dev_info (&dev->pdev->dev,"nfc: failed to find the client\n" ); ret = -ENOTTY ; goto err; } - cl->me_client_id = dev->me_clients[i].client_id; + cl->me_client_id = me_cl->client_id; ret =mei_cl_link (cl,MEI_HOST_CLIENT_ID_ANY );if (ret)drivers/misc/mei/wd.c +4
-5@@ -59,7 +59,7 @@ static void mei_wd_set_start_timeout(struct mei_device *dev, u16 timeout)int mei_wd_host_init (struct mei_device *dev) {struct mei_cl *cl = &dev->wd_cl; -int id; +struct mei_me_client *me_cl;int ret;mei_cl_init (cl, dev);@@ -69,13 +69,13 @@ int mei_wd_host_init(struct mei_device *dev)/* check for valid client id */ - id =mei_me_cl_by_uuid (dev, &mei_wd_guid); -if (id <0 ) { + me_cl =mei_me_cl_by_uuid (dev, &mei_wd_guid); +if (!me_cl) {dev_info (&dev->pdev->dev,"wd: failed to find the client\n" );return -ENOTTY ; } - cl->me_client_id = dev->me_clients[id].client_id; + cl->me_client_id = me_cl->client_id; ret =mei_cl_link (cl,MEI_WD_HOST_CLIENT_ID ); --1.9.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
RE: [char-misc-next 03/14] mei: me_client lookup function to return me_client object
Quoted 14 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Josh Boyer
Sent: Thursday, August 21, 2014 15:33
To: Winkler, Tomas
Cc: Greg KH; Arnd Bergmann; Linux-Kernel@Vger. Kernel. Org
Subject: Re: [char-misc-next 03/14] mei:me_clientlookup function to returnme_clientobjectQuoted 1 line · Tomas Winkler
In order to support dynamic addition/removal of me clients we cannot
Quoted 7 lines
cannot what?
Quoted 3 lines
It is incontinent to use static array and we can use list. As the first step we change the lookup function to return me client address instead of the index.
This changelog seems to have some missing parts to it.
Oops , let me see what went wrong here....
Thanks
Tomas
PATCH 4/14 mei: use list for me clients book keeping
In reply to Tomas WinklerTo support dynamic addition/remove of clients
it is more convenient to use list instead of
static array
--- drivers/misc/mei/client.c | 34 ++++++------- drivers/misc/mei/debugfs.c | 19 ++++---- drivers/misc/mei/hbm.c | 116 +++++++++++++++++---------------------------- drivers/misc/mei/init.c | 1 + drivers/misc/mei/mei_dev.h | 4 +- 5 files changed, 71 insertions(+), 103 deletions(-)
drivers/misc/mei/client.c +15 -19
@@ -38,12 +38,11 @@struct mei_me_client *mei_me_cl_by_uuid (const struct mei_device *dev,const uuid_le *uuid) { -int i; +struct mei_me_client *me_cl; -for (i =0 ; i < dev->me_clients_num; ++i) -if (uuid_le_cmp (*uuid, - dev->me_clients[i].props.protocol_name) ==0 ) -return &dev->me_clients[i]; +list_for_each_entry (me_cl, &dev->me_clients, list) +if (uuid_le_cmp (*uuid, me_cl->props.protocol_name) ==0 ) +return me_cl;return NULL ; }
@@ -62,12 +61,12 @@ struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev,struct mei_me_client *mei_me_cl_by_id (struct mei_device *dev,u8 client_id) { -int i; -for (i =0 ; i < dev->me_clients_num; i++) -if (dev->me_clients[i].client_id == client_id) -return &dev->me_clients[i]; +struct mei_me_client *me_cl; +list_for_each_entry (me_cl, &dev->me_clients, list) +if (me_cl->client_id == client_id) +return me_cl;return NULL ; }
@@ -396,19 +395,19 @@ void mei_host_client_init(struct work_struct *work) {struct mei_device *dev =container_of (work, struct mei_device, init_work); -struct mei_client_properties *client_props; -int i; +struct mei_me_client *me_cl; +struct mei_client_properties *props;mutex_lock (&dev->device_lock); -for (i =0 ; i < dev->me_clients_num; i++) { - client_props = &dev->me_clients[i].props; +list_for_each_entry (me_cl, &dev->me_clients, list) { + props = &me_cl->props; -if (!uuid_le_cmp (client_props->protocol_name, mei_amthif_guid)) +if (!uuid_le_cmp (props->protocol_name, mei_amthif_guid))mei_amthif_host_init (dev); -else if (!uuid_le_cmp (client_props->protocol_name, mei_wd_guid)) +else if (!uuid_le_cmp (props->protocol_name, mei_wd_guid))mei_wd_host_init (dev); -else if (!uuid_le_cmp (client_props->protocol_name, mei_nfc_guid)) +else if (!uuid_le_cmp (props->protocol_name, mei_nfc_guid))mei_nfc_host_init (dev); }
@@ -653,9 +652,6 @@ int mei_cl_flow_ctrl_creds(struct mei_cl *cl) dev = cl->dev; -if (!dev->me_clients_num) -return 0 ; -if (cl->mei_flow_ctrl_creds >0 )return 1 ;
drivers/misc/mei/debugfs.c +9 -10
@@ -28,10 +28,10 @@ static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf, size_t cnt, loff_t *ppos) { struct mei_device *dev = fp->private_data; -struct mei_me_client *cl; +struct mei_me_client *me_cl;const size_t bufsz =1024 ;char *buf =kzalloc (bufsz,GFP_KERNEL ); -int i; +int i =0 ;int pos =0 ;int ret;
@@ -47,20 +47,19 @@ static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf,if (dev->dev_state !=MEI_DEV_ENABLED ) goto out; -for (i =0 ; i < dev->me_clients_num; i++) { - cl = &dev->me_clients[i]; +list_for_each_entry (me_cl, &dev->me_clients, list) {/* skip me clients that cannot be connected */ -if (cl->props.max_number_of_connections ==0 ) +if (me_cl->props.max_number_of_connections ==0 )continue ; pos +=scnprintf (buf + pos, bufsz - pos,"%2d|%2d|%4d|%pUl|%3d|%7d|\n" , - i, cl->client_id, - cl->props.fixed_address, - &cl->props.protocol_name, - cl->props.max_number_of_connections, - cl->props.max_msg_length); + i++, me_cl->client_id, + me_cl->props.fixed_address, + &me_cl->props.protocol_name, + me_cl->props.max_number_of_connections, + me_cl->props.max_msg_length); } out:mutex_unlock (&dev->device_lock);
drivers/misc/mei/hbm.c +44 -72
202 lines not on this page · raw message
drivers/misc/mei/init.c +1 -0
@@ -356,6 +356,7 @@ void mei_device_init(struct mei_device *dev, const struct mei_cfg *cfg)/* setup our list array */ INIT_LIST_HEAD (&dev->file_list);INIT_LIST_HEAD (&dev->device_list); +INIT_LIST_HEAD (&dev->me_clients);mutex_init (&dev->device_lock);init_waitqueue_head (&dev->wait_hw_ready);init_waitqueue_head (&dev->wait_pg);
drivers/misc/mei/mei_dev.h +2 -2
@@ -175,6 +175,7 @@ struct mei_fw_status {* @mei_flow_ctrl_creds - flow control credits */ struct mei_me_client { +struct list_head list;struct mei_client_properties props;u8 client_id;u8 mei_flow_ctrl_creds;
@@ -478,10 +479,9 @@ struct mei_device {struct hbm_version version; -struct mei_me_client *me_clients;/* Note: memory has to be allocated */ +struct list_head me_clients;DECLARE_BITMAP (me_clients_map,MEI_CLIENTS_MAX );DECLARE_BITMAP (host_clients_map,MEI_CLIENTS_MAX ); -unsigned long me_clients_num;unsigned long me_client_presentation_num;unsigned long me_client_index;
Signature · 1 line
1.9.3
PATCH 5/14 mei: add me client remove functions
In reply to Tomas WinklerTo support dynamic addition/remove we add wrappers for removal of me clients
--- drivers/misc/mei/client.c | 22 +++++++++++++++++++++- drivers/misc/mei/client.h | 2 ++ drivers/misc/mei/hbm.c | 21 +++++++++++++++------ 3 files changed, 38 insertions(+), 7 deletions(-)
drivers/misc/mei/client.c +21 -1
@@ -47,7 +47,6 @@ struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev,return NULL ; } -/** * mei_me_cl_by_id return index to me_clients for client_id *
@@ -70,6 +69,27 @@ struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id)return NULL ; } +/** +* mei_me_cl_remove - remove me client matching uuid and client_id +* +* @dev: the device structure +* @uuid: me client uuid +* @client_id: me client address +*/ +void mei_me_cl_remove (struct mei_device *dev,const uuid_le *uuid,u8 client_id) +{ +struct mei_me_client *me_cl, *next; + +list_for_each_entry_safe (me_cl, next, &dev->me_clients, list) { +if (uuid_le_cmp (*uuid, me_cl->props.protocol_name) ==0 && + me_cl->client_id == client_id) { +list_del (&me_cl->list); +kfree (me_cl); +break ; + } + } +} +/** * mei_cl_cmp_id - tells if the clients are the same
drivers/misc/mei/client.h +2 -0
@@ -27,6 +27,8 @@struct mei_me_client *mei_me_cl_by_uuid (const struct mei_device *dev,const uuid_le *cuuid);struct mei_me_client *mei_me_cl_by_id (struct mei_device *dev,u8 client_id); +void mei_me_cl_remove (struct mei_device *dev, +const uuid_le *uuid,u8 client_id);/* * MEI IO Functions
drivers/misc/mei/hbm.c +15 -6
@@ -71,21 +71,30 @@ void mei_hbm_idle(struct mei_device *dev) }/** -* mei_hbm_reset - reset hbm counters and book keeping data structurs +* mei_me_cl_remove_all - remove all me clients * * @dev: the device structure */ -void mei_hbm_reset (struct mei_device *dev) +static void mei_me_cl_remove_all (struct mei_device *dev) {struct mei_me_client *me_cl, *next; +list_for_each_entry_safe (me_cl, next, &dev->me_clients, list) { +list_del (&me_cl->list); +kfree (me_cl); + } +} +/** +* mei_hbm_reset - reset hbm counters and book keeping data structurs +* +* @dev: the device structure +*/ +void mei_hbm_reset (struct mei_device *dev) +{ dev->me_client_presentation_num =0 ; dev->me_client_index =0 ; -list_for_each_entry_safe (me_cl, next, &dev->me_clients, list) { -list_del (&me_cl->list); -kfree (me_cl); - } +mei_me_cl_remove_all (dev);mei_hbm_idle (dev); }
Signature · 1 line
1.9.3
PATCH 6/14 mei: add mei_me_cl_by_uuid_id function
In reply to Tomas WinklerWhen handling dynamic clients there might be a race scenario in which two me clients with the same me address would be linked in the me clients list, therefore we need to search by both uuid and me address.
--- drivers/misc/mei/amthif.c | 1 + drivers/misc/mei/bus.c | 4 ++-- drivers/misc/mei/client.c | 14 +++++++++++++- drivers/misc/mei/client.h | 4 ++++ drivers/misc/mei/main.c | 3 ++- drivers/misc/mei/mei_dev.h | 2 +- drivers/misc/mei/nfc.c | 6 ++---- drivers/misc/mei/wd.c | 1 + 8 files changed, 26 insertions(+), 9 deletions(-)
drivers/misc/mei/amthif.c +1 -0
@@ -83,6 +83,7 @@ int mei_amthif_host_init(struct mei_device *dev) } cl->me_client_id = me_cl->client_id; + cl->cl_uuid = me_cl->props.protocol_name;/* Assign iamthif_mtu to the value received from ME */
drivers/misc/mei/bus.c +2 -2
@@ -147,7 +147,7 @@ static struct mei_cl *mei_bus_find_mei_cl_by_uuid(struct mei_device *dev,struct mei_cl *cl;list_for_each_entry (cl, &dev->device_list, device_link) { -if (!uuid_le_cmp (uuid, cl->device_uuid)) +if (!uuid_le_cmp (uuid, cl->cl_uuid))return cl; }
@@ -242,7 +242,7 @@ static int ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,return -ENODEV ;/* Check if we have an ME client device */ - me_cl =mei_me_cl_by_id (dev, cl->me_client_id); + me_cl =mei_me_cl_by_uuid_id (dev, &cl->cl_uuid, cl->me_client_id);if (!me_cl)return -ENOTTY ;
drivers/misc/mei/client.c +13 -1
@@ -69,6 +69,18 @@ struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id)return NULL ; } +struct mei_me_client *mei_me_cl_by_uuid_id (struct mei_device *dev, +const uuid_le *uuid,u8 client_id) +{ +struct mei_me_client *me_cl; + +list_for_each_entry (me_cl, &dev->me_clients, list) +if (uuid_le_cmp (*uuid, me_cl->props.protocol_name) ==0 && + me_cl->client_id == client_id) +return me_cl; +return NULL ; +} +/** * mei_me_cl_remove - remove me client matching uuid and client_id *
@@ -753,7 +765,7 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length)cl_dbg (dev, cl,"read is pending.\n" );return -EBUSY ; } - me_cl =mei_me_cl_by_id (dev, cl->me_client_id); + me_cl =mei_me_cl_by_uuid_id (dev, &cl->cl_uuid, cl->me_client_id);if (!me_cl) {cl_err (dev, cl,"no such me client %d\n" , cl->me_client_id);return -ENOTTY ;
drivers/misc/mei/client.h +4 -0
@@ -27,6 +27,10 @@struct mei_me_client *mei_me_cl_by_uuid (const struct mei_device *dev,const uuid_le *cuuid);struct mei_me_client *mei_me_cl_by_id (struct mei_device *dev,u8 client_id); + +struct mei_me_client *mei_me_cl_by_uuid_id (struct mei_device *dev, +const uuid_le *uuid,u8 client_id); +void mei_me_cl_remove (struct mei_device *dev,const uuid_le *uuid,u8 client_id);
drivers/misc/mei/main.c +2 -1
@@ -321,7 +321,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, goto out; } - me_cl =mei_me_cl_by_id (dev, cl->me_client_id); + me_cl =mei_me_cl_by_uuid_id (dev, &cl->cl_uuid, cl->me_client_id);if (!me_cl) { rets = -ENOTTY ; goto out;
@@ -459,6 +459,7 @@ static int mei_ioctl_connect_client(struct file *file, } cl->me_client_id = me_cl->client_id; + cl->cl_uuid = me_cl->props.protocol_name;dev_dbg (&dev->pdev->dev,"Connect to FW Client ID = %d\n" , cl->me_client_id);
drivers/misc/mei/mei_dev.h +1 -1
@@ -212,6 +212,7 @@ struct mei_cl {wait_queue_head_t wait;int status;/* ID of client connected */ +uuid_le cl_uuid;u8 host_client_id;u8 me_client_id;u8 mei_flow_ctrl_creds;
@@ -223,7 +224,6 @@ struct mei_cl {/* MEI CL bus data */ struct mei_cl_device *device;struct list_head device_link; -uuid_le device_uuid; };/** struct mei_hw_ops
drivers/misc/mei/nfc.c +2 -4
@@ -507,12 +507,12 @@ int mei_nfc_host_init(struct mei_device *dev) } cl_info->me_client_id = me_cl->client_id; + cl_info->cl_uuid = me_cl->props.protocol_name; ret =mei_cl_link (cl_info,MEI_HOST_CLIENT_ID_ANY );if (ret) goto err; - cl_info->device_uuid = mei_nfc_info_guid;list_add_tail (&cl_info->device_link, &dev->device_list);
@@ -525,14 +525,12 @@ int mei_nfc_host_init(struct mei_device *dev) } cl->me_client_id = me_cl->client_id; + cl->cl_uuid = me_cl->props.protocol_name; ret =mei_cl_link (cl,MEI_HOST_CLIENT_ID_ANY );if (ret) goto err; - cl->device_uuid = mei_nfc_guid; - -list_add_tail (&cl->device_link, &dev->device_list); ndev->req_id =1 ;
drivers/misc/mei/wd.c +1 -0
@@ -76,6 +76,7 @@ int mei_wd_host_init(struct mei_device *dev) } cl->me_client_id = me_cl->client_id; + cl->cl_uuid = me_cl->props.protocol_name; ret =mei_cl_link (cl,MEI_WD_HOST_CLIENT_ID );
Signature · 1 line
1.9.3
PATCH 7/14 mei: add hbm commands return status values
In reply to Tomas WinklerHBM uses global list of status values
from which the values of particular commands
are derived
--- drivers/misc/mei/hbm.c | 22 ++++++++++++++++++++-- drivers/misc/mei/hw.h | 39 +++++++++++++++++++++++++++++++++------ 2 files changed, 53 insertions(+), 8 deletions(-)
drivers/misc/mei/hbm.c +20 -2
@@ -25,6 +25,23 @@#include "hbm.h" #include "client.h" +static const char *mei_hbm_status_str (enum mei_hbm_status status) +{ +#define MEI_HBM_STATUS (status) case MEI_HBMS_##status: return #status +switch (status) { +MEI_HBM_STATUS (SUCCESS ); +MEI_HBM_STATUS (CLIENT_NOT_FOUND ); +MEI_HBM_STATUS (ALREADY_EXISTS ); +MEI_HBM_STATUS (REJECTED ); +MEI_HBM_STATUS (INVALID_PARAMETER ); +MEI_HBM_STATUS (NOT_ALLOWED ); +MEI_HBM_STATUS (ALREADY_STARTED ); +MEI_HBM_STATUS (NOT_STARTED ); +default :return "unknown" ; + } +#undef MEI_HBM_STATUS +}; +static const char *mei_cl_conn_status_str (enum mei_cl_connect_status status) {#define MEI_CL_CS (status) case MEI_CL_CONN_##status: return #status
@@ -770,8 +787,9 @@ int mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr) props_res = (struct hbm_props_response *)mei_msg;if (props_res->status) { -dev_err (&dev->pdev->dev,"hbm: properties response: wrong status = %d\n" , - props_res->status); +dev_err (&dev->pdev->dev,"hbm: properties response: wrong status = %d %s\n" , + props_res->status, +mei_hbm_status_str (props_res->status));return -EPROTO ; }
drivers/misc/mei/hw.h +33 -6
@@ -97,23 +97,50 @@ enum mei_stop_reason_types { SYSTEM_S5_ENTRY = 0x08 }; + +/** +* mei_hbm_status - mei host bus messages return values +* +* @MEI_HBMS_SUCCESS - status success +* @MEI_HBMS_CLIENT_NOT_FOUND - client not found +* @MEI_HBMS_ALREADY_EXISTS - connection already established +* @MEI_HBMS_REJECTED - connection is rejected +* @MEI_HBMS_INVALID_PARAMETER - invalid parameter +* @MEI_HBMS_NOT_ALLOWED - operation not allowed +* @MEI_HBMS_ALREADY_STARTED - system is already started +* @MEI_HBMS_NOT_STARTED - system not started +*/ +enum mei_hbm_status { +MEI_HBMS_SUCCESS =0 , +MEI_HBMS_CLIENT_NOT_FOUND =1 , +MEI_HBMS_ALREADY_EXISTS =2 , +MEI_HBMS_REJECTED =3 , +MEI_HBMS_INVALID_PARAMETER =4 , +MEI_HBMS_NOT_ALLOWED =5 , +MEI_HBMS_ALREADY_STARTED =6 , +MEI_HBMS_NOT_STARTED =7 , + +MEI_HBMS_MAX +}; + +/* * Client Connect Status * used by hbm_client_connect_response.status */ enum mei_cl_connect_status { -MEI_CL_CONN_SUCCESS =0x00 , -MEI_CL_CONN_NOT_FOUND =0x01 , -MEI_CL_CONN_ALREADY_STARTED =0x02 , -MEI_CL_CONN_OUT_OF_RESOURCES =0x03 , -MEI_CL_CONN_MESSAGE_SMALL =0x04 +MEI_CL_CONN_SUCCESS =MEI_HBMS_SUCCESS , +MEI_CL_CONN_NOT_FOUND =MEI_HBMS_CLIENT_NOT_FOUND , +MEI_CL_CONN_ALREADY_STARTED =MEI_HBMS_ALREADY_EXISTS , +MEI_CL_CONN_OUT_OF_RESOURCES =MEI_HBMS_REJECTED , +MEI_CL_CONN_MESSAGE_SMALL =MEI_HBMS_INVALID_PARAMETER , };/* * Client Disconnect Status */ enum mei_cl_disconnect_status { -MEI_CL_DISCONN_SUCCESS =0x00 +MEI_CL_DISCONN_SUCCESS =MEI_HBMS_SUCCESS };/*
Signature · 1 line
1.9.3
PATCH 8/14 mei: use disconnect name consistently
In reply to Tomas WinklerRename mei_cl_irq_close to mei_cl_irq_disconnect
and MEI_FOP_CLOSE to MEI_FOP_DISCONNECT
Remove unused MEI_FOP_OPEN
--- drivers/misc/mei/client.c | 3 ++- drivers/misc/mei/interrupt.c | 8 ++++---- drivers/misc/mei/mei_dev.h | 6 ++---- 3 files changed, 8 insertions(+), 9 deletions(-)
drivers/misc/mei/client.c +2 -1
@@ -516,7 +516,8 @@ int mei_cl_disconnect(struct mei_cl *cl) goto free; } - cb->fop_type =MEI_FOP_CLOSE ; + cb->fop_type =MEI_FOP_DISCONNECT ; +if (mei_hbuf_acquire (dev)) {if (mei_hbm_cl_disconnect_req (dev, cl)) { rets = -ENODEV ;
drivers/misc/mei/interrupt.c +4 -4
@@ -195,7 +195,7 @@ static int mei_cl_irq_disconnect_rsp(struct mei_cl *cl, struct mei_cl_cb *cb,/** -* mei_cl_irq_close - processes close related operation from +* mei_cl_irq_disconnect - processes close related operation from * interrupt thread context - send disconnect request * * @cl: client
@@ -204,7 +204,7 @@ static int mei_cl_irq_disconnect_rsp(struct mei_cl *cl, struct mei_cl_cb *cb,* * returns 0, OK; otherwise, error. */ -static int mei_cl_irq_close (struct mei_cl *cl,struct mei_cl_cb *cb, +static int mei_cl_irq_disconnect (struct mei_cl *cl,struct mei_cl_cb *cb,struct mei_cl_cb *cmpl_list) {struct mei_device *dev = cl->dev;
@@ -495,9 +495,9 @@ int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list)return -ENODEV ; }switch (cb->fop_type) { -case MEI_FOP_CLOSE : +case MEI_FOP_DISCONNECT :/* send disconnect message */ - ret =mei_cl_irq_close (cl, cb, cmpl_list); + ret =mei_cl_irq_disconnect (cl, cb, cmpl_list);if (ret)return ret;
drivers/misc/mei/mei_dev.h +2 -4
@@ -132,17 +132,15 @@ enum mei_wd_states {* @MEI_FOP_READ - read * @MEI_FOP_WRITE - write * @MEI_FOP_CONNECT - connect +* @MEI_FOP_DISCONNECT - disconnect * @MEI_FOP_DISCONNECT_RSP - disconnect response -* @MEI_FOP_OPEN - open -* @MEI_FOP_CLOSE - close */ enum mei_cb_file_ops {MEI_FOP_READ =0 ,MEI_FOP_WRITE ,MEI_FOP_CONNECT , +MEI_FOP_DISCONNECT ,MEI_FOP_DISCONNECT_RSP , -MEI_FOP_OPEN , -MEI_FOP_CLOSE };/*
Signature · 1 line
1.9.3
PATCH 9/14 mei: revamp connect and disconnect response handling
In reply to Tomas WinklerBoth responses have same flow only the client status update is different. We introduce handler mei_hbm_cl_res() that handles both responses
Also we use per client wait queue (cl->wait) rather then global dev->wait_recvd_msg
--- drivers/misc/mei/client.c | 4 +- drivers/misc/mei/hbm.c | 118 +++++++++++++++++++++++++--------------------- 2 files changed, 65 insertions(+), 57 deletions(-)
drivers/misc/mei/client.c +2 -2
@@ -534,7 +534,7 @@ int mei_cl_disconnect(struct mei_cl *cl) }mutex_unlock (&dev->device_lock); -wait_event_timeout (dev->wait_recvd_msg, +wait_event_timeout (cl->wait,MEI_FILE_DISCONNECTED == cl->state,mei_secs_to_jiffies (MEI_CL_CONNECT_TIMEOUT ));
@@ -639,7 +639,7 @@ int mei_cl_connect(struct mei_cl *cl, struct file *file) }mutex_unlock (&dev->device_lock); -wait_event_timeout (dev->wait_recvd_msg, +wait_event_timeout (cl->wait, (cl->state ==MEI_FILE_CONNECTED || cl->state ==MEI_FILE_DISCONNECTED ),mei_secs_to_jiffies (MEI_CL_CONNECT_TIMEOUT ));
drivers/misc/mei/hbm.c +63 -55
180 lines not on this page · raw message
Signature · 1 line
1.9.3
PATCH 10/14 mei: wait for hbm start non-interruptible
In reply to Tomas WinklerFrom: Alexander Usyskin <[email protected]>
We cannot handle user interrupt in context of hbm start so we only wait for time out which is reasonably short.
1. Add kdoc
2. Rename state to better reflect its function
3. Simplify wait condition and rename
wait_recvd_msg to wait_hbm_start
--- drivers/misc/mei/hbm.c | 26 ++++++++++++++++---------- drivers/misc/mei/hbm.h | 6 ++++-- drivers/misc/mei/init.c | 2 +- drivers/misc/mei/mei_dev.h | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-)
drivers/misc/mei/hbm.c +16 -10
@@ -172,21 +172,27 @@ bool mei_hbm_cl_addr_equal(struct mei_cl *cl, void *buf) cl->me_client_id == cmd->me_addr; } - +/** +* mei_hbm_start_wait - wait for start response message. +* +* @dev: the device structure +* +* returns 0 on success and < 0 on failure +*/ int mei_hbm_start_wait (struct mei_device *dev) {int ret; -if (dev->hbm_state >MEI_HBM_START ) + +if (dev->hbm_state >MEI_HBM_STARTING )return 0 ;mutex_unlock (&dev->device_lock); - ret =wait_event_interruptible_timeout (dev->wait_recvd_msg, - dev->hbm_state ==MEI_HBM_IDLE || - dev->hbm_state >=MEI_HBM_STARTED , + ret =wait_event_timeout (dev->wait_hbm_start, + dev->hbm_state !=MEI_HBM_STARTING ,mei_secs_to_jiffies (MEI_HBM_TIMEOUT ));mutex_lock (&dev->device_lock); -if (ret <=0 && (dev->hbm_state <=MEI_HBM_START )) { +if (ret ==0 && (dev->hbm_state <=MEI_HBM_STARTING )) { dev->hbm_state =MEI_HBM_IDLE ;dev_err (&dev->pdev->dev,"waiting for mei start failed\n" );return -ETIME ;
@@ -227,7 +233,7 @@ int mei_hbm_start_req(struct mei_device *dev)return ret; } - dev->hbm_state =MEI_HBM_START ; + dev->hbm_state =MEI_HBM_STARTING ; dev->init_clients_timer =MEI_CLIENTS_INIT_TIMEOUT ;return 0 ; }
@@ -726,7 +732,7 @@ int mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr) }if (dev->dev_state !=MEI_DEV_INIT_CLIENTS || - dev->hbm_state !=MEI_HBM_START ) { + dev->hbm_state !=MEI_HBM_STARTING ) {dev_err (&dev->pdev->dev,"hbm: start: state mismatch, [%d, %d]\n" , dev->dev_state, dev->hbm_state);return -EPROTO ;
@@ -739,7 +745,7 @@ int mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)return -EIO ; } -wake_up_interruptible (&dev->wait_recvd_msg); +wake_up (&dev->wait_hbm_start);break ;case CLIENT_CONNECT_RES_CMD :
@@ -866,7 +872,7 @@ int mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)dev_dbg (&dev->pdev->dev,"hbm: stop request: message received\n" ); dev->hbm_state =MEI_HBM_STOPPED ;if (mei_hbm_stop_req (dev)) { -dev_err (&dev->pdev->dev,"hbm: start: failed to send stop request\n" ); +dev_err (&dev->pdev->dev,"hbm: stop request: failed to send stop request\n" );return -EIO ; }break ;
drivers/misc/mei/hbm.h +4 -2
@@ -25,13 +25,15 @@ struct mei_cl;* enum mei_hbm_state - host bus message protocol state * * @MEI_HBM_IDLE : protocol not started -* @MEI_HBM_START : start request message was sent +* @MEI_HBM_STARTING : start request message was sent +* @MEI_HBM_STARTED : start reply message was received * @MEI_HBM_ENUM_CLIENTS : enumeration request was sent * @MEI_HBM_CLIENT_PROPERTIES : acquiring clients properties +* @MEI_HBM_STOPPED : stopping exchange */ enum mei_hbm_state {MEI_HBM_IDLE =0 , -MEI_HBM_START , +MEI_HBM_STARTING ,MEI_HBM_STARTED ,MEI_HBM_ENUM_CLIENTS ,MEI_HBM_CLIENT_PROPERTIES ,
drivers/misc/mei/init.c +1 -1
@@ -360,7 +360,7 @@ void mei_device_init(struct mei_device *dev, const struct mei_cfg *cfg)mutex_init (&dev->device_lock);init_waitqueue_head (&dev->wait_hw_ready);init_waitqueue_head (&dev->wait_pg); -init_waitqueue_head (&dev->wait_recvd_msg); +init_waitqueue_head (&dev->wait_hbm_start);init_waitqueue_head (&dev->wait_stop_wd); dev->dev_state =MEI_DEV_INITIALIZING ; dev->reset_count =0 ;
drivers/misc/mei/mei_dev.h +1 -1
@@ -443,7 +443,7 @@ struct mei_device {*/ wait_queue_head_t wait_hw_ready;wait_queue_head_t wait_pg; -wait_queue_head_t wait_recvd_msg; +wait_queue_head_t wait_hbm_start;wait_queue_head_t wait_stop_wd;/*
Signature · 1 line
1.9.3
PATCH 11/14 mei: simplify handling of hbm client events
In reply to Tomas WinklerAdd mei_hbm_cl_find_by_cmd handler to retrieve
the destination client
--- drivers/misc/mei/hbm.c | 74 +++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 31 deletions(-)
drivers/misc/mei/hbm.c +43 -31
@@ -157,22 +157,43 @@ int mei_hbm_cl_write(struct mei_device *dev, }/** -* mei_hbm_cl_addr_equal - tells if they have the same address +* mei_hbm_cl_addr_equal - check if the client's and +* the message address match * -* @cl: - client -* @buf: buffer with cl header +* @cl: client +* @cmd: hbm client message * * returns true if addresses are the same */ static inline -bool mei_hbm_cl_addr_equal (struct mei_cl *cl,void *buf) +bool mei_hbm_cl_addr_equal (struct mei_cl *cl,struct mei_hbm_cl_cmd *cmd) { -struct mei_hbm_cl_cmd *cmd = buf;return cl->host_client_id == cmd->host_addr && cl->me_client_id == cmd->me_addr; }/** +* mei_hbm_cl_find_by_cmd - find recipient client +* +* @dev: the device structure +* @buf: a buffer with hbm cl command +* +* returns the recipient client or NULL if not found +*/ +static inline +struct mei_cl *mei_hbm_cl_find_by_cmd (struct mei_device *dev,void *buf) +{ +struct mei_hbm_cl_cmd *cmd = (struct mei_hbm_cl_cmd *)buf; +struct mei_cl *cl; + +list_for_each_entry (cl, &dev->file_list, link) +if (mei_hbm_cl_addr_equal (cl, cmd)) +return cl; +return NULL ; +} + + +/** * mei_hbm_start_wait - wait for start response message. * * @dev: the device structure
@@ -449,7 +470,7 @@ static int mei_hbm_add_single_flow_creds(struct mei_device *dev,* @flow_control: flow control response bus message */ static void mei_hbm_cl_flow_control_res (struct mei_device *dev, -struct hbm_flow_control *flow_control) +struct hbm_flow_control *flow_control) {struct mei_cl *cl;
@@ -459,15 +480,11 @@ static void mei_hbm_cl_flow_control_res(struct mei_device *dev,return ; } -/* normal connection */ -list_for_each_entry (cl, &dev->file_list, link) { -if (mei_hbm_cl_addr_equal (cl, flow_control)) { - cl->mei_flow_ctrl_creds++; -dev_dbg (&dev->pdev->dev,"flow ctrl msg for host %d ME %d creds %d.\n" , - flow_control->host_addr, flow_control->me_addr, + cl =mei_hbm_cl_find_by_cmd (dev, flow_control); +if (cl) { + cl->mei_flow_ctrl_creds++; +cl_dbg (dev, cl,"flow control creds = %d.\n" , cl->mei_flow_ctrl_creds); -break ; - } } }
@@ -627,23 +644,18 @@ static int mei_hbm_fw_disconnect_req(struct mei_device *dev,struct mei_cl *cl;struct mei_cl_cb *cb; -list_for_each_entry (cl, &dev->file_list, link) { -if (mei_hbm_cl_addr_equal (cl, disconnect_req)) { -dev_dbg (&dev->pdev->dev,"disconnect request host client %d ME client %d.\n" , - disconnect_req->host_addr, - disconnect_req->me_addr); - cl->state =MEI_FILE_DISCONNECTED ; - cl->timer_count =0 ; - - cb =mei_io_cb_init (cl,NULL ); -if (!cb) -return -ENOMEM ; - cb->fop_type =MEI_FOP_DISCONNECT_RSP ; -cl_dbg (dev, cl,"add disconnect response as first\n" ); -list_add (&cb->list, &dev->ctrl_wr_list.list); - -break ; - } + cl =mei_hbm_cl_find_by_cmd (dev, disconnect_req); +if (cl) { +cl_dbg (dev, cl,"disconnect request received\n" ); + cl->state =MEI_FILE_DISCONNECTED ; + cl->timer_count =0 ; + + cb =mei_io_cb_init (cl,NULL ); +if (!cb) +return -ENOMEM ; + cb->fop_type =MEI_FOP_DISCONNECT_RSP ; +cl_dbg (dev, cl,"add disconnect response as first\n" ); +list_add (&cb->list, &dev->ctrl_wr_list.list); }return 0 ; }
Signature · 1 line
1.9.3
PATCH 12/14 mei: extract supported features from the hbm version
In reply to Tomas Winklerextract supported hbm features and commands from the hbm version
--- drivers/misc/mei/hbm.c | 25 ++++++++++++++++++++++++- drivers/misc/mei/hw-me.c | 6 +----- drivers/misc/mei/mei_dev.h | 4 ++++ 3 files changed, 29 insertions(+), 6 deletions(-)
drivers/misc/mei/hbm.c +24 -1
@@ -372,7 +372,8 @@ static int mei_hbm_prop_req(struct mei_device *dev)* @dev: the device structure * @pg_cmd: the pg command code * -* This function returns -EIO on write failure +* returns -EIO on write failure +* -EOPNOTSUPP if the operation is not supported by the protocol */ int mei_hbm_pg (struct mei_device *dev,u8 pg_cmd) {
@@ -381,6 +382,9 @@ int mei_hbm_pg(struct mei_device *dev, u8 pg_cmd)const size_t len =sizeof (struct hbm_power_gate );int ret; +if (!dev->hbm_f_pg_supported) +return -EOPNOTSUPP ; +mei_hbm_hdr (mei_hdr, len); req = (struct hbm_power_gate *)dev->wr_msg.data;
@@ -660,6 +664,23 @@ static int mei_hbm_fw_disconnect_req(struct mei_device *dev,return 0 ; } +/** +* mei_hbm_config_features: check what hbm features and commands +* are supported by the fw +* +* @dev: the device structure +*/ +static void mei_hbm_config_features (struct mei_device *dev) +{ +/* Power Gating Isolation Support */ + dev->hbm_f_pg_supported =0 ; +if (dev->version.major_version >HBM_MAJOR_VERSION_PGI ) + dev->hbm_f_pg_supported =1 ; + +if (dev->version.major_version ==HBM_MAJOR_VERSION_PGI && + dev->version.minor_version >=HBM_MINOR_VERSION_PGI ) + dev->hbm_f_pg_supported =1 ; +}/** * mei_hbm_version_is_supported - checks whether the driver can
@@ -743,6 +764,8 @@ int mei_hbm_dispatch(struct mei_device *dev, struct mei_msg_hdr *hdr)break ; } +mei_hbm_config_features (dev); +if (dev->dev_state !=MEI_DEV_INIT_CLIENTS || dev->hbm_state !=MEI_HBM_STARTING ) { dev_err(&dev->pdev->dev, "hbm: start: state mismatch, [%d, %d]\n",
drivers/misc/mei/hw-me.c +1 -5
@@ -574,11 +574,7 @@ static bool mei_me_pg_is_enabled(struct mei_device *dev)if ((reg &ME_PGIC_HRA ) ==0 ) goto notsupported; -if (dev->version.major_version <HBM_MAJOR_VERSION_PGI ) - goto notsupported; - -if (dev->version.major_version ==HBM_MAJOR_VERSION_PGI && - dev->version.minor_version <HBM_MINOR_VERSION_PGI ) +if (!dev->hbm_f_pg_supported) goto notsupported;return true;
drivers/misc/mei/mei_dev.h +4 -0
@@ -402,6 +402,9 @@ struct mei_cfg {* * @reset_count - limits the number of consecutive resets * @hbm_state - state of host bus message protocol +* +* @hbm_f_pg_supported - hbm feature pgi protocol +* * @pg_event - power gating event * @mem_addr - mem mapped base register address
@@ -476,6 +479,7 @@ struct mei_device { } wr_msg;struct hbm_version version; + unsigned int hbm_f_pg_supported:1;struct list_head me_clients;DECLARE_BITMAP (me_clients_map,MEI_CLIENTS_MAX );
Signature · 1 line
1.9.3
PATCH 13/14 mei: enable adding more IOCTL handlers
In reply to Tomas WinklerHandle ioctls in a switch statement so we can
add more commands easily
--- drivers/misc/mei/main.c | 53 ++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 25 deletions(-)
drivers/misc/mei/main.c +28 -25
@@ -523,8 +523,6 @@ static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data)struct mei_connect_client_data *connect_data =NULL ;int rets; -if (cmd !=IOCTL_MEI_CONNECT_CLIENT ) -return -EINVAL ;if (WARN_ON (!cl || !cl->dev))return -ENODEV ;
@@ -539,34 +537,39 @@ static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data) goto out; } -dev_dbg (&dev->pdev->dev,": IOCTL_MEI_CONNECT_CLIENT.\n" ); - - connect_data =kzalloc (sizeof (struct mei_connect_client_data ), +switch (cmd) { +case IOCTL_MEI_CONNECT_CLIENT : +dev_dbg (&dev->pdev->dev,": IOCTL_MEI_CONNECT_CLIENT.\n" ); + connect_data =kzalloc (sizeof (struct mei_connect_client_data ),GFP_KERNEL ); -if (!connect_data) { - rets = -ENOMEM ; - goto out; - } -dev_dbg (&dev->pdev->dev,"copy connect data from user\n" ); -if (copy_from_user (connect_data, (char __user *)data, -sizeof (struct mei_connect_client_data ))) { -dev_dbg (&dev->pdev->dev,"failed to copy data from userland\n" ); - rets = -EFAULT ; - goto out; - } +if (!connect_data) { + rets = -ENOMEM ; + goto out; + } - rets =mei_ioctl_connect_client (file, connect_data); +if (copy_from_user (connect_data, (char __user *)data, +sizeof (struct mei_connect_client_data ))) { +dev_dbg (&dev->pdev->dev,"failed to copy data from userland\n" ); + rets = -EFAULT ; + goto out; + } -/* if all is ok, copying the data back to user. */ -if (rets) - goto out; + rets =mei_ioctl_connect_client (file, connect_data); +if (rets) + goto out; -dev_dbg (&dev->pdev->dev,"copy connect data to user\n" ); -if (copy_to_user ((char __user *)data, connect_data, +/* if all is ok, copying the data back to user. */ +if (copy_to_user ((char __user *)data, connect_data,sizeof (struct mei_connect_client_data ))) { -dev_dbg (&dev->pdev->dev,"failed to copy data to userland\n" ); - rets = -EFAULT ; - goto out; +dev_dbg (&dev->pdev->dev,"failed to copy data to userland\n" ); + rets = -EFAULT ; + goto out; + } + +break ; +default : +dev_err (&dev->pdev->dev,": unsupported ioctl %d.\n" , cmd); + rets = -ENOIOCTLCMD ; } out:
Signature · 1 line
1.9.3
PATCH 14/14 mei: use connect_data on the stack
In reply to Tomas WinklerThere is no need for dynamic allocation for connect_data. We can use variable on the stack and make code less error prone and simple
--- drivers/misc/mei/main.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)
drivers/misc/mei/main.c +5 -16
@@ -433,9 +433,6 @@ static int mei_ioctl_connect_client(struct file *file,int rets; cl = file->private_data; -if (WARN_ON (!cl || !cl->dev)) -return -ENODEV ; - dev = cl->dev;if (dev->dev_state !=MEI_DEV_ENABLED ) {
@@ -506,7 +503,6 @@ end:return rets; } -/** * mei_ioctl - the IOCTL function *
@@ -520,7 +516,7 @@ static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data) {struct mei_device *dev;struct mei_cl *cl = file->private_data; -struct mei_connect_client_data *connect_data =NULL ; +struct mei_connect_client_data connect_data;int rets;
@@ -540,26 +536,19 @@ static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data)switch (cmd) {case IOCTL_MEI_CONNECT_CLIENT :dev_dbg (&dev->pdev->dev,": IOCTL_MEI_CONNECT_CLIENT.\n" ); - connect_data =kzalloc (sizeof (struct mei_connect_client_data ), -GFP_KERNEL ); -if (!connect_data) { - rets = -ENOMEM ; - goto out; - } - -if (copy_from_user (connect_data, (char __user *)data, +if (copy_from_user (&connect_data, (char __user *)data,sizeof (struct mei_connect_client_data ))) {dev_dbg (&dev->pdev->dev,"failed to copy data from userland\n" ); rets = -EFAULT ; goto out; } - rets =mei_ioctl_connect_client (file, connect_data); + rets =mei_ioctl_connect_client (file, &connect_data);if (rets) goto out;/* if all is ok, copying the data back to user. */ -if (copy_to_user ((char __user *)data, connect_data, +if (copy_to_user ((char __user *)data, &connect_data,sizeof (struct mei_connect_client_data ))) {dev_dbg (&dev->pdev->dev,"failed to copy data to userland\n" ); rets = -EFAULT ;
@@ -567,13 +556,13 @@ static long mei_ioctl(struct file *file, unsigned int cmd, unsigned long data) }break ; +default :dev_err (&dev->pdev->dev,": unsupported ioctl %d.\n" , cmd); rets = -ENOIOCTLCMD ; } out: -kfree (connect_data);mutex_unlock (&dev->device_lock);return rets; }
Signature · 1 line
1.9.3