Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7ca96aa2 authored by Alexander Usyskin's avatar Alexander Usyskin Committed by Greg Kroah-Hartman
Browse files

mei: make return values consistent across the driver



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: default avatarAlexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9d098192
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -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;
		}
	}
+14 −12
Original line number Diff line number Diff line
@@ -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 @@ int mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb, bool blocking)
	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)) {
		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;
				else
					rets = -ERESTARTSYS;
			goto err;
		}
		mutex_lock(&dev->device_lock);
	}

	rets = buf->size;
err:
	return rets;
}
+1 −1
Original line number Diff line number Diff line
@@ -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;
}
+4 −4
Original line number Diff line number Diff line
@@ -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)
{
+2 −2
Original line number Diff line number Diff line
@@ -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;
		}
	}
Loading