From: Tomas Winkler <tomas.winkler@intel.com>
To: gregkh@linuxfoundation.org
Cc: arnd@arndb.de, alan@linux.intel.com,
linux-kernel@vger.kernel.org,
Tomas Winkler <tomas.winkler@intel.com>
Subject: [char-misc-next 3/6] mei: mei_write: revamp error path handling
Date: Tue, 9 Oct 2012 16:50:18 +0200 [thread overview]
Message-ID: <1349794221-8667-3-git-send-email-tomas.winkler@intel.com> (raw)
In-Reply-To: <1349794221-8667-1-git-send-email-tomas.winkler@intel.com>
1. unify common amt and regular error path and use it early in the
function
2. fix indentation
3. propagate error code directly from copy_from_user
4. print out errors using dev_err instead of dev_dbg
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
---
drivers/misc/mei/main.c | 75 +++++++++++++++++------------------------------
1 files changed, 27 insertions(+), 48 deletions(-)
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index 15de4b1..8dcf59d 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -621,10 +621,26 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
mutex_lock(&dev->device_lock);
if (dev->dev_state != MEI_DEV_ENABLED) {
- mutex_unlock(&dev->device_lock);
- return -ENODEV;
+ rets = -ENODEV;
+ goto unlock_dev;
}
+ i = mei_me_cl_by_id(dev, cl->me_client_id);
+ if (i < 0) {
+ rets = -ENODEV;
+ goto unlock_dev;
+ }
+ if (length > dev->me_clients[i].props.max_msg_length || length <= 0) {
+ rets = -EMSGSIZE;
+ goto unlock_dev;
+ }
+
+ if (cl->state != MEI_FILE_CONNECTED) {
+ rets = -ENODEV;
+ dev_err(&dev->pdev->dev, "host client = %d, is not connected to ME client = %d",
+ cl->host_client_id, cl->me_client_id);
+ goto unlock_dev;
+ }
if (cl == &dev->iamthif_cl) {
write_cb = find_amthi_read_list_entry(dev, file);
@@ -633,11 +649,11 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
msecs_to_jiffies(IAMTHIF_READ_TIMER);
if (time_after(jiffies, timeout) ||
- cl->reading_state == MEI_READ_COMPLETE) {
- *offset = 0;
- list_del(&write_cb->cb_list);
- mei_free_cb_private(write_cb);
- write_cb = NULL;
+ cl->reading_state == MEI_READ_COMPLETE) {
+ *offset = 0;
+ list_del(&write_cb->cb_list);
+ mei_free_cb_private(write_cb);
+ write_cb = NULL;
}
}
}
@@ -670,8 +686,8 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
dev_dbg(&dev->pdev->dev, "cb request size = %zd\n", length);
- rets = -EFAULT;
- if (copy_from_user(write_cb->request_buffer.data, ubuf, length))
+ rets = copy_from_user(write_cb->request_buffer.data, ubuf, length);
+ if (rets)
goto unlock_dev;
cl->sm_state = 0;
@@ -685,29 +701,11 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
cl->sm_state |= MEI_WD_STATE_INDEPENDENCE_MSG_SENT;
if (cl == &dev->iamthif_cl) {
- if (dev->dev_state != MEI_DEV_ENABLED) {
- rets = -ENODEV;
- goto unlock_dev;
- }
- i = mei_me_cl_by_id(dev, dev->iamthif_cl.me_client_id);
- if (i < 0) {
- rets = -ENODEV;
- goto unlock_dev;
- }
- if (length > dev->me_clients[i].props.max_msg_length ||
- length <= 0) {
- rets = -EMSGSIZE;
- goto unlock_dev;
- }
rets = mei_io_cb_alloc_resp_buf(write_cb, dev->iamthif_mtu);
if (rets)
goto unlock_dev;
write_cb->major_file_operations = MEI_IOCTL;
- if (dev->iamthif_cl.state != MEI_FILE_CONNECTED) {
- rets = -ENODEV;
- goto unlock_dev;
- }
if (!list_empty(&dev->amthi_cmd_list.mei_cb.cb_list) ||
dev->iamthif_state != MEI_IAMTHIF_IDLE) {
@@ -716,43 +714,24 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
dev_dbg(&dev->pdev->dev, "add amthi cb to amthi cmd waiting list\n");
list_add_tail(&write_cb->cb_list,
&dev->amthi_cmd_list.mei_cb.cb_list);
- rets = length;
} else {
dev_dbg(&dev->pdev->dev, "call amthi write\n");
rets = amthi_write(dev, write_cb);
if (rets) {
- dev_dbg(&dev->pdev->dev, "amthi write failed with status = %d\n",
+ dev_err(&dev->pdev->dev, "amthi write failed with status = %d\n",
rets);
goto unlock_dev;
}
- rets = length;
}
mutex_unlock(&dev->device_lock);
- return rets;
+ return length;
}
write_cb->major_file_operations = MEI_WRITE;
dev_dbg(&dev->pdev->dev, "host client = %d, ME client = %d\n",
cl->host_client_id, cl->me_client_id);
- if (cl->state != MEI_FILE_CONNECTED) {
- rets = -ENODEV;
- dev_dbg(&dev->pdev->dev, "host client = %d, is not connected to ME client = %d",
- cl->host_client_id,
- cl->me_client_id);
- goto unlock_dev;
- }
- i = mei_me_cl_by_id(dev, cl->me_client_id);
- if (i < 0) {
- rets = -ENODEV;
- goto unlock_dev;
- }
- if (length > dev->me_clients[i].props.max_msg_length || length <= 0) {
- rets = -EINVAL;
- goto unlock_dev;
- }
-
rets = mei_flow_ctrl_creds(dev, cl);
if (rets < 0)
goto unlock_dev;
--
1.7.4.4
next prev parent reply other threads:[~2012-10-09 14:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-09 14:50 [char-misc-next 1/6] mei: rename mei_cl_cb.information to mei_cl_cb.buf_idx Tomas Winkler
2012-10-09 14:50 ` [char-misc-next 2/6] mei: add allocation and initialization wrappers for io callback Tomas Winkler
2012-10-09 14:50 ` Tomas Winkler [this message]
2012-10-09 14:50 ` [char-misc-next 4/6] mei: kill usless struct mei_io_list Tomas Winkler
2012-10-09 14:50 ` [char-misc-next 5/6] mei: rename mei_free_cb_private to mei_io_cb_free Tomas Winkler
2012-10-09 14:50 ` [char-misc-next 6/6] mei: use mei_io_cb_ warppers also for control flows Tomas Winkler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1349794221-8667-3-git-send-email-tomas.winkler@intel.com \
--to=tomas.winkler@intel.com \
--cc=alan@linux.intel.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®