Skip to content

Commit 9764723

Browse files
cyndisthierryreding
authored andcommitted
gpu: host1x: Add locking in channel allocation
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
1 parent f170bed commit 9764723

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

drivers/gpu/host1x/channel.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ int host1x_channel_list_init(struct host1x_channel_list *chlist,
2727
return -ENOMEM;
2828
}
2929

30+
mutex_init(&chlist->lock);
31+
3032
return 0;
3133
}
3234

@@ -104,8 +106,11 @@ static struct host1x_channel *acquire_unused_channel(struct host1x *host)
104106
unsigned int max_channels = host->info->nb_channels;
105107
unsigned int index;
106108

109+
mutex_lock(&chlist->lock);
110+
107111
index = find_first_zero_bit(chlist->allocated_channels, max_channels);
108112
if (index >= max_channels) {
113+
mutex_unlock(&chlist->lock);
109114
dev_err(host->dev, "failed to find free channel\n");
110115
return NULL;
111116
}
@@ -114,6 +119,8 @@ static struct host1x_channel *acquire_unused_channel(struct host1x *host)
114119

115120
set_bit(index, chlist->allocated_channels);
116121

122+
mutex_unlock(&chlist->lock);
123+
117124
return &chlist->channels[index];
118125
}
119126

drivers/gpu/host1x/channel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <linux/io.h>
1212
#include <linux/kref.h>
13+
#include <linux/mutex.h>
1314

1415
#include "cdma.h"
1516

@@ -18,6 +19,8 @@ struct host1x_channel;
1819

1920
struct host1x_channel_list {
2021
struct host1x_channel *channels;
22+
23+
struct mutex lock;
2124
unsigned long *allocated_channels;
2225
};
2326

0 commit comments

Comments
 (0)