Skip to content

Commit 1d61c5d

Browse files
matt-auldjnikula
authored andcommitted
drm/i915: be more solid in checking the alignment
The alignment is u64, and yet is_power_of_2() assumes unsigned long, which might give different results between 32b and 64b kernel. Signed-off-by: Matthew Auld <[email protected]> Cc: Chris Wilson <[email protected]> Reviewed-by: Chris Wilson <[email protected]> Signed-off-by: Chris Wilson <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Cc: [email protected] (cherry picked from commit 2920516) Signed-off-by: Jani Nikula <[email protected]>
1 parent 259170c commit 1d61c5d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,8 @@ eb_validate_vma(struct i915_execbuffer *eb,
423423
if (unlikely(entry->flags & eb->invalid_flags))
424424
return -EINVAL;
425425

426-
if (unlikely(entry->alignment && !is_power_of_2(entry->alignment)))
426+
if (unlikely(entry->alignment &&
427+
!is_power_of_2_u64(entry->alignment)))
427428
return -EINVAL;
428429

429430
/*

drivers/gpu/drm/i915/i915_utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ static inline u64 ptr_to_u64(const void *ptr)
234234
__idx; \
235235
})
236236

237+
static inline bool is_power_of_2_u64(u64 n)
238+
{
239+
return (n != 0 && ((n & (n - 1)) == 0));
240+
}
241+
237242
static inline void __list_del_many(struct list_head *head,
238243
struct list_head *first)
239244
{

0 commit comments

Comments
 (0)