Skip to content

Commit 2920516

Browse files
matt-auldickle
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]
1 parent 64dc802 commit 2920516

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
@@ -430,7 +430,8 @@ eb_validate_vma(struct i915_execbuffer *eb,
430430
if (unlikely(entry->flags & eb->invalid_flags))
431431
return -EINVAL;
432432

433-
if (unlikely(entry->alignment && !is_power_of_2(entry->alignment)))
433+
if (unlikely(entry->alignment &&
434+
!is_power_of_2_u64(entry->alignment)))
434435
return -EINVAL;
435436

436437
/*

drivers/gpu/drm/i915/i915_utils.h

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

239+
static inline bool is_power_of_2_u64(u64 n)
240+
{
241+
return (n != 0 && ((n & (n - 1)) == 0));
242+
}
243+
239244
static inline void __list_del_many(struct list_head *head,
240245
struct list_head *first)
241246
{

0 commit comments

Comments
 (0)