mei: make return values consistent across the driver
authorAlexander Usyskin <alexander.usyskin@intel.com>
Wed, 19 Feb 2014 15:35:49 +0000 (17:35 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 28 Feb 2014 23:15:57 +0000 (15:15 -0800)
1. Propagate ENOTTY  to user space if the client is not present
in the system
2. Use ETIME consistently on timeouts
3. Return EIO on write failures
4. Return ENODEV on recoverable device failures such as resets

Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/mei/amthif.c
drivers/misc/mei/client.c
drivers/misc/mei/hbm.c
drivers/misc/mei/hw-me.c
drivers/misc/mei/interrupt.c
drivers/misc/mei/main.c
drivers/misc/mei/nfc.c
drivers/misc/mei/wd.c

index bff9a07f1af57e3b75992e52b06f13185932492f..f05d54d15e2fa8ca164192d19eff4eed0dd01df8 100644 (file)
@@ -78,10 +78,9 @@ int mei_amthif_host_init(struct mei_device *dev)
 
        i = mei_me_cl_by_uuid(dev, &mei_amthif_guid);
        if (i < 0) {
-               ret = i;
                dev_info(&dev->pdev->dev,
-                       "amthif: failed to find the client %d\n", ret);
-               return ret;
+                       "amthif: failed to find the client %d\n", i);
+               return -ENOTTY;
        }
 
        cl->me_client_id = dev->me_clients[i].client_id;
@@ -174,14 +173,13 @@ int mei_amthif_read(struct mei_device *dev, struct file *file,
        /* Only possible if we are in timeout */
        if (!cl || cl != &dev->iamthif_cl) {
                dev_dbg(&dev->pdev->dev, "bad file ext.\n");
-               return -ETIMEDOUT;
+               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 -ENODEV;
+               return -ENOTTY;
        }
        dev_dbg(&dev->pdev->dev, "checking amthif data\n");
        cb = mei_amthif_find_read_list_entry(dev, file);
@@ -222,7 +220,7 @@ int mei_amthif_read(struct mei_device *dev, struct file *file,
                        dev_dbg(&dev->pdev->dev, "amthif Time out\n");
                        /* 15 sec for the message has expired */
                        list_del(&cb->list);
-                       rets = -ETIMEDOUT;
+                       rets = -ETIME;
                        goto free;
                }
        }
index 2b0f99955ba6a71babc3d6e2c27df09be661d729..753608185b77ba8575340e8ee29e9a1b2af84fbe 100644 (file)
@@ -664,7 +664,7 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length)
        i = mei_me_cl_by_id(dev, cl->me_client_id);
        if (i < 0) {
                cl_err(dev, cl, "no such me client %d\n", cl->me_client_id);
-               return  -ENODEV;
+               return  -ENOTTY;
        }
 
        cb = mei_io_cb_init(cl, NULL);
@@ -852,13 +852,12 @@ int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb, bool blocking)
        cl->writing_state = MEI_WRITING;
        cb->buf_idx = mei_hdr.length;
 
-       rets = buf->size;
 out:
        if (mei_hdr.msg_complete) {
-               if (mei_cl_flow_ctrl_reduce(cl)) {
-                       rets = -ENODEV;
+               rets = mei_cl_flow_ctrl_reduce(cl);
+               if (rets < 0)
                        goto err;
-               }
+
                list_add_tail(&cb->list, &dev->write_waiting_list.list);
        } else {
                list_add_tail(&cb->list, &dev->write_list.list);
@@ -868,15 +867,18 @@ out:
        if (blocking && cl->writing_state != MEI_WRITE_COMPLETE) {
 
                mutex_unlock(&dev->device_lock);
-               if (wait_event_interruptible(cl->tx_wait,
-                       cl->writing_state == MEI_WRITE_COMPLETE)) {
-                               if (signal_pending(current))
-                                       rets = -EINTR;
-                               else
-                                       rets = -ERESTARTSYS;
-               }
+               rets = wait_event_interruptible(cl->tx_wait,
+                               cl->writing_state == MEI_WRITE_COMPLETE);
                mutex_lock(&dev->device_lock);
+               /* wait_event_interruptible returns -ERESTARTSYS */
+               if (rets) {
+                       if (signal_pending(current))
+                               rets = -EINTR;
+                       goto err;
+               }
        }
+
+       rets = buf->size;
 err:
        return rets;
 }
index a28cc928fb02aec1ab28c3dd6de9524defbd2a14..9555791c010b33471c50d9c39c999c309f33e890 100644 (file)
@@ -161,7 +161,7 @@ int mei_hbm_start_wait(struct mei_device *dev)
        if (ret <= 0 && (dev->hbm_state <= MEI_HBM_START)) {
                dev->hbm_state = MEI_HBM_IDLE;
                dev_err(&dev->pdev->dev, "waiting for mei start failed\n");
-               return -ETIMEDOUT;
+               return -ETIME;
        }
        return 0;
 }
index 84165cce57d2ef6cef31530d7e3a409954b14603..7e769c59a4202d0004f4f2e2562b29ab238cd099 100644 (file)
@@ -244,7 +244,7 @@ static int mei_me_hw_ready_wait(struct mei_device *dev)
        mutex_lock(&dev->device_lock);
        if (!err && !dev->recvd_hw_ready) {
                if (!err)
-                       err = -ETIMEDOUT;
+                       err = -ETIME;
                dev_err(&dev->pdev->dev,
                        "wait hw ready failed. status = %d\n", err);
                return err;
@@ -303,7 +303,7 @@ static bool mei_me_hbuf_is_empty(struct mei_device *dev)
  *
  * @dev: the device structure
  *
- * returns -1(ESLOTS_OVERFLOW) if overflow, otherwise empty slots count
+ * returns -EOVERFLOW if overflow, otherwise empty slots count
  */
 static int mei_me_hbuf_empty_slots(struct mei_device *dev)
 {
@@ -326,7 +326,7 @@ static size_t mei_me_hbuf_max_len(const struct mei_device *dev)
 
 
 /**
- * mei_write_message - writes a message to mei device.
+ * mei_me_write_message - writes a message to mei device.
  *
  * @dev: the device structure
  * @header: mei HECI header of message
@@ -381,7 +381,7 @@ static int mei_me_write_message(struct mei_device *dev,
  *
  * @dev: the device structure
  *
- * returns -1(ESLOTS_OVERFLOW) if overflow, otherwise filled slots count
+ * returns -EOVERFLOW if overflow, otherwise filled slots count
  */
 static int mei_me_count_full_read_slots(struct mei_device *dev)
 {
index e6151e2dac480a176d633529efd8db8c681a9f6b..31cb3452b9d748030222c7d63c5ab7b411e646dc 100644 (file)
@@ -350,7 +350,7 @@ int mei_irq_read_handler(struct mei_device *dev,
                dev_err(&dev->pdev->dev, "less data available than length=%08x.\n",
                                *slots);
                /* we can't read the message */
-               ret = -ERANGE;
+               ret = -EBADMSG;
                goto end;
        }
 
@@ -483,7 +483,7 @@ int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list)
                        if (mei_wd_send(dev))
                                dev_dbg(&dev->pdev->dev, "wd send failed.\n");
                        else if (mei_cl_flow_ctrl_reduce(&dev->wd_cl))
-                               return -ENODEV;
+                               return -EIO;
                        dev->wd_pending = false;
                }
        }
index 434242bada899b32f8e5a0988c9d78758c08c535..49e3bb8a724a87808c07bbfbd8ceb8c30854fff4 100644 (file)
@@ -340,7 +340,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
 
        id = mei_me_cl_by_id(dev, cl->me_client_id);
        if (id < 0) {
-               rets = -ENODEV;
+               rets = -ENOTTY;
                goto out;
        }
 
index 7626dde5e1f53cae64b9e4a76d3a9b089a917ff0..3095fc514a65f3a44868587e6adae91b0eef5612 100644 (file)
@@ -364,7 +364,7 @@ static int mei_nfc_send(struct mei_cl_device *cldev, u8 *buf, size_t length)
        if (!wait_event_interruptible_timeout(ndev->send_wq,
                                ndev->recv_req_id == ndev->req_id, HZ)) {
                dev_err(&dev->pdev->dev, "NFC MEI command timeout\n");
-               err = -ETIMEDOUT;
+               err = -ETIME;
        } else {
                ndev->req_id++;
        }
@@ -502,7 +502,7 @@ int mei_nfc_host_init(struct mei_device *dev)
        i = mei_me_cl_by_uuid(dev, &mei_nfc_info_guid);
        if (i < 0) {
                dev_info(&dev->pdev->dev, "nfc: failed to find the client\n");
-               ret = -ENOENT;
+               ret = -ENOTTY;
                goto err;
        }
 
@@ -520,7 +520,7 @@ int mei_nfc_host_init(struct mei_device *dev)
        i = mei_me_cl_by_uuid(dev, &mei_nfc_guid);
        if (i < 0) {
                dev_info(&dev->pdev->dev, "nfc: failed to find the client\n");
-               ret = -ENOENT;
+               ret = -ENOTTY;
                goto err;
        }
 
index afe976a185864af3580b961556ede784c9bd8bf0..4644b62e9055ffe3d23ee67a2b26d8428d01c565 100644 (file)
@@ -53,7 +53,7 @@ static void mei_wd_set_start_timeout(struct mei_device *dev, u16 timeout)
  *
  * @dev: the device structure
  *
- * returns -ENENT if wd client cannot be found
+ * returns -ENOTTY if wd client cannot be found
  *         -EIO if write has failed
  *         0 on success
  */
@@ -73,7 +73,7 @@ int mei_wd_host_init(struct mei_device *dev)
        id = mei_me_cl_by_uuid(dev, &mei_wd_guid);
        if (id < 0) {
                dev_info(&dev->pdev->dev, "wd: failed to find the client\n");
-               return id;
+               return -ENOTTY;
        }
 
        cl->me_client_id = dev->me_clients[id].client_id;
@@ -185,7 +185,7 @@ int mei_wd_stop(struct mei_device *dev)
                ret = 0;
        } else {
                if (!ret)
-                       ret = -ETIMEDOUT;
+                       ret = -ETIME;
                dev_warn(&dev->pdev->dev,
                        "wd: stop failed to complete ret=%d.\n", ret);
        }