]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
gpu: host1x: Add locking in channel allocation
authorMikko Perttunen <mperttunen@nvidia.com>
Fri, 1 Sep 2023 11:15:07 +0000 (14:15 +0300)
committerThierry Reding <treding@nvidia.com>
Wed, 11 Oct 2023 20:52:43 +0000 (22:52 +0200)
Add locking around channel allocation to avoid race conditions.

Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230901111510.663401-1-cyndis@kapsi.fi
drivers/gpu/host1x/channel.c
drivers/gpu/host1x/channel.h

index 2d0051d6314c2df54553370f52d4986590112887..79501c9575321cdf9bb12ee63a8bec553663bab2 100644 (file)
@@ -27,6 +27,8 @@ int host1x_channel_list_init(struct host1x_channel_list *chlist,
                return -ENOMEM;
        }
 
+       mutex_init(&chlist->lock);
+
        return 0;
 }
 
@@ -104,8 +106,11 @@ static struct host1x_channel *acquire_unused_channel(struct host1x *host)
        unsigned int max_channels = host->info->nb_channels;
        unsigned int index;
 
+       mutex_lock(&chlist->lock);
+
        index = find_first_zero_bit(chlist->allocated_channels, max_channels);
        if (index >= max_channels) {
+               mutex_unlock(&chlist->lock);
                dev_err(host->dev, "failed to find free channel\n");
                return NULL;
        }
@@ -114,6 +119,8 @@ static struct host1x_channel *acquire_unused_channel(struct host1x *host)
 
        set_bit(index, chlist->allocated_channels);
 
+       mutex_unlock(&chlist->lock);
+
        return &chlist->channels[index];
 }
 
index 39044ff6c3aab1eff020dec36b97d0e50fb71cf2..b23a8071fbd02e1eabd965af67afb01b6f60df9e 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <linux/io.h>
 #include <linux/kref.h>
+#include <linux/mutex.h>
 
 #include "cdma.h"
 
@@ -18,6 +19,8 @@ struct host1x_channel;
 
 struct host1x_channel_list {
        struct host1x_channel *channels;
+
+       struct mutex lock;
        unsigned long *allocated_channels;
 };