diff mbox series

[1/5] mei: allow map and unmap of client dma buffer only for disconnected client

Message ID 20210322204633.102581-2-emmanuel.grumbach@intel.com (mailing list archive)
State Not Applicable
Delegated to: Johannes Berg
Headers show
Series Add support for AMT over WLAN | expand

Commit Message

Emmanuel Grumbach March 22, 2021, 8:46 p.m. UTC
From: Tomas Winkler <tomas.winkler@intel.com>

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.

Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
---
 drivers/misc/mei/client.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

Comments

Emmanuel Grumbach March 23, 2021, 3:15 p.m. UTC | #1
On Mon, Mar 22, 2021 at 10:49 PM Emmanuel Grumbach
<emmanuel.grumbach@intel.com> wrote:
>
> From: Tomas Winkler <tomas.winkler@intel.com>
>
> 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.
>
> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
> Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>

This one has been taken by Greg through his tree so I'll drop it.
I won't resend the series for this though.

> ---
>  drivers/misc/mei/client.c | 17 +++++++----------
>  1 file changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c
> index 4378a9b25848..2cc370adb238 100644
> --- a/drivers/misc/mei/client.c
> +++ b/drivers/misc/mei/client.c
> @@ -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;
> @@ -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);
>
> @@ -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;
> @@ -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);
>
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c
index 4378a9b25848..2cc370adb238 100644
--- a/drivers/misc/mei/client.c
+++ b/drivers/misc/mei/client.c
@@ -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;
@@ -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);
 
@@ -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;
@@ -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);