Skip to content

Commit

Permalink
drm/nouveau/flcn/msgq: simplify msg_queue_pop() error handling
Browse files Browse the repository at this point in the history
We always want at least requested size, make anything less a more direct
error condition.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
  • Loading branch information
Ben Skeggs committed Jan 15, 2020
1 parent f09a3ee commit e9602a1
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions drivers/gpu/drm/nouveau/nvkm/falcon/msgq.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,40 +67,30 @@ msg_queue_pop(struct nvkm_msgqueue *priv, struct nvkm_msgqueue_queue *queue,
tail = queue->position;

available = head - tail;

if (available == 0) {
nvkm_warn(subdev, "no message data available\n");
return 0;
}

if (size > available) {
nvkm_warn(subdev, "message data smaller than read request\n");
size = available;
return -EINVAL;
}

nvkm_falcon_read_dmem(priv->falcon, tail, size, 0, data);
queue->position += ALIGN(size, QUEUE_ALIGNMENT);
return size;
return 0;
}

static int
msg_queue_read(struct nvkm_msgqueue *priv, struct nvkm_msgqueue_queue *queue,
struct nv_falcon_msg *hdr)
{
const struct nvkm_subdev *subdev = priv->falcon->owner;
int ret;
int ret = 0;

msg_queue_open(priv, queue);

if (msg_queue_empty(priv, queue)) {
ret = 0;
if (msg_queue_empty(priv, queue))
goto close;
}

ret = msg_queue_pop(priv, queue, hdr, HDR_SIZE);
if (ret >= 0 && ret != HDR_SIZE)
ret = -EINVAL;
if (ret < 0) {
if (ret) {
nvkm_error(subdev, "failed to read message header: %d\n", ret);
goto close;
}
Expand All @@ -115,14 +105,13 @@ msg_queue_read(struct nvkm_msgqueue *priv, struct nvkm_msgqueue_queue *queue,
u32 read_size = hdr->size - HDR_SIZE;

ret = msg_queue_pop(priv, queue, (hdr + 1), read_size);
if (ret >= 0 && ret != read_size)
ret = -EINVAL;
if (ret < 0) {
if (ret) {
nvkm_error(subdev, "failed to read message: %d\n", ret);
goto close;
}
}

ret = 1;
close:
msg_queue_close(priv, queue, (ret >= 0));
return ret;
Expand Down

0 comments on commit e9602a1

Please sign in to comment.