diff options
Diffstat (limited to 'drivers/gpu/nvgpu/common/mm/lockless_allocator.c')
-rw-r--r-- | drivers/gpu/nvgpu/common/mm/lockless_allocator.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/drivers/gpu/nvgpu/common/mm/lockless_allocator.c b/drivers/gpu/nvgpu/common/mm/lockless_allocator.c index 4a3d6c9d..7a5f67e9 100644 --- a/drivers/gpu/nvgpu/common/mm/lockless_allocator.c +++ b/drivers/gpu/nvgpu/common/mm/lockless_allocator.c | |||
@@ -63,8 +63,9 @@ static u64 nvgpu_lockless_alloc(struct nvgpu_allocator *a, u64 len) | |||
63 | int head, new_head, ret; | 63 | int head, new_head, ret; |
64 | u64 addr = 0; | 64 | u64 addr = 0; |
65 | 65 | ||
66 | if (len != pa->blk_size) | 66 | if (len != pa->blk_size) { |
67 | return 0; | 67 | return 0; |
68 | } | ||
68 | 69 | ||
69 | head = NV_ACCESS_ONCE(pa->head); | 70 | head = NV_ACCESS_ONCE(pa->head); |
70 | while (head >= 0) { | 71 | while (head >= 0) { |
@@ -80,10 +81,11 @@ static u64 nvgpu_lockless_alloc(struct nvgpu_allocator *a, u64 len) | |||
80 | head = NV_ACCESS_ONCE(pa->head); | 81 | head = NV_ACCESS_ONCE(pa->head); |
81 | } | 82 | } |
82 | 83 | ||
83 | if (addr) | 84 | if (addr) { |
84 | alloc_dbg(a, "Alloc node # %d @ addr 0x%llx", head, addr); | 85 | alloc_dbg(a, "Alloc node # %d @ addr 0x%llx", head, addr); |
85 | else | 86 | } else { |
86 | alloc_dbg(a, "Alloc failed!"); | 87 | alloc_dbg(a, "Alloc failed!"); |
88 | } | ||
87 | 89 | ||
88 | return addr; | 90 | return addr; |
89 | } | 91 | } |
@@ -167,24 +169,28 @@ int nvgpu_lockless_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a, | |||
167 | u64 count; | 169 | u64 count; |
168 | struct nvgpu_lockless_allocator *a; | 170 | struct nvgpu_lockless_allocator *a; |
169 | 171 | ||
170 | if (!blk_size) | 172 | if (!blk_size) { |
171 | return -EINVAL; | 173 | return -EINVAL; |
174 | } | ||
172 | 175 | ||
173 | /* | 176 | /* |
174 | * Ensure we have space for at least one node & there's no overflow. | 177 | * Ensure we have space for at least one node & there's no overflow. |
175 | * In order to control memory footprint, we require count < INT_MAX | 178 | * In order to control memory footprint, we require count < INT_MAX |
176 | */ | 179 | */ |
177 | count = length / blk_size; | 180 | count = length / blk_size; |
178 | if (!base || !count || count > INT_MAX) | 181 | if (!base || !count || count > INT_MAX) { |
179 | return -EINVAL; | 182 | return -EINVAL; |
183 | } | ||
180 | 184 | ||
181 | a = nvgpu_kzalloc(g, sizeof(struct nvgpu_lockless_allocator)); | 185 | a = nvgpu_kzalloc(g, sizeof(struct nvgpu_lockless_allocator)); |
182 | if (!a) | 186 | if (!a) { |
183 | return -ENOMEM; | 187 | return -ENOMEM; |
188 | } | ||
184 | 189 | ||
185 | err = __nvgpu_alloc_common_init(__a, g, name, a, false, &pool_ops); | 190 | err = __nvgpu_alloc_common_init(__a, g, name, a, false, &pool_ops); |
186 | if (err) | 191 | if (err) { |
187 | goto fail; | 192 | goto fail; |
193 | } | ||
188 | 194 | ||
189 | a->next = nvgpu_vzalloc(g, sizeof(*a->next) * count); | 195 | a->next = nvgpu_vzalloc(g, sizeof(*a->next) * count); |
190 | if (!a->next) { | 196 | if (!a->next) { |