Skip to content

Commit def25b7

Browse files
gfxstranddanvet
authored andcommitted
drm/i915/gem: Make an alignment check more sensible
What we really want to check is that size of the engines array, i.e. args->size - sizeof(*user) is divisible by the element size, i.e. sizeof(*user->engines) because that's what's required for computing the array length right below the check. However, we're currently not doing this and instead doing a compile-time check that sizeof(*user) is divisible by sizeof(*user->engines) and avoiding the subtraction. As far as I can tell, the only reason for the more confusing pair of checks is to avoid a single subtraction of a constant. The other thing the BUILD_BUG_ON might be trying to implicitly check is that offsetof(user->engines) == sizeof(*user) and we don't have any weird padding throwing us off. However, that's not the check it's doing and it's not even a reliable way to do that check. Signed-off-by: Jason Ekstrand <jason@jlekstrand.net> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: https://patchwork.freedesktop.org/patch/msgid/20210708154835.528166-21-jason@jlekstrand.net
1 parent bc2ceb7 commit def25b7

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,9 +1723,8 @@ set_engines(struct i915_gem_context *ctx,
17231723
goto replace;
17241724
}
17251725

1726-
BUILD_BUG_ON(!IS_ALIGNED(sizeof(*user), sizeof(*user->engines)));
17271726
if (args->size < sizeof(*user) ||
1728-
!IS_ALIGNED(args->size, sizeof(*user->engines))) {
1727+
!IS_ALIGNED(args->size - sizeof(*user), sizeof(*user->engines))) {
17291728
drm_dbg(&i915->drm, "Invalid size for engine array: %d\n",
17301729
args->size);
17311730
return -EINVAL;

0 commit comments

Comments
 (0)