Skip to content

Commit

Permalink
mei: allow map and unmap of client dma buffer only for disconnected c…
Browse files Browse the repository at this point in the history
…lient

Allow map and unmap of the client dma buffer only when the client is not
connected. The functions return -EPROTO if the client is already connected.
This is to fix the race when traffic may start or stop when buffer
is not available.

Cc: <stable@vger.kernel.org> #v5.11+
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Link: https://lore.kernel.org/r/20210318055959.305627-1-tomas.winkler@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Tomas Winkler authored and Greg Kroah-Hartman committed Mar 23, 2021
1 parent 903079a commit ce068bc
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions drivers/misc/mei/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -2286,8 +2286,8 @@ int mei_cl_dma_alloc_and_map(struct mei_cl *cl, const struct file *fp,
if (buffer_id == 0)
return -EINVAL;

if (!mei_cl_is_connected(cl))
return -ENODEV;
if (mei_cl_is_connected(cl))
return -EPROTO;

if (cl->dma_mapped)
return -EPROTO;
Expand Down Expand Up @@ -2327,9 +2327,7 @@ int mei_cl_dma_alloc_and_map(struct mei_cl *cl, const struct file *fp,

mutex_unlock(&dev->device_lock);
wait_event_timeout(cl->wait,
cl->dma_mapped ||
cl->status ||
!mei_cl_is_connected(cl),
cl->dma_mapped || cl->status,
mei_secs_to_jiffies(MEI_CL_CONNECT_TIMEOUT));
mutex_lock(&dev->device_lock);

Expand Down Expand Up @@ -2376,8 +2374,9 @@ int mei_cl_dma_unmap(struct mei_cl *cl, const struct file *fp)
return -EOPNOTSUPP;
}

if (!mei_cl_is_connected(cl))
return -ENODEV;
/* do not allow unmap for connected client */
if (mei_cl_is_connected(cl))
return -EPROTO;

if (!cl->dma_mapped)
return -EPROTO;
Expand Down Expand Up @@ -2405,9 +2404,7 @@ int mei_cl_dma_unmap(struct mei_cl *cl, const struct file *fp)

mutex_unlock(&dev->device_lock);
wait_event_timeout(cl->wait,
!cl->dma_mapped ||
cl->status ||
!mei_cl_is_connected(cl),
!cl->dma_mapped || cl->status,
mei_secs_to_jiffies(MEI_CL_CONNECT_TIMEOUT));
mutex_lock(&dev->device_lock);

Expand Down

0 comments on commit ce068bc

Please sign in to comment.