From: Jani Nikula <jani.nikula@linux.intel.com>
To: Sam James <sam@gentoo.org>,
intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@intel.com>,
Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
Cc: Sam James <sam@gentoo.org>
Subject: Re: [Intel-gfx] [PATCH] drm: i915: Adapt to -Walloc-size
Date: Thu, 09 Nov 2023 13:12:33 +0200 [thread overview]
Message-ID: <87zfznw57i.fsf@intel.com> (raw)
In-Reply-To: <87jzqsy3sp.fsf@intel.com>
On Wed, 08 Nov 2023, Jani Nikula <jani.nikula@linux.intel.com> wrote:
> On Tue, 07 Nov 2023, Sam James <sam@gentoo.org> wrote:
>> GCC 14 introduces a new -Walloc-size included in -Wextra which errors out
>> like:
>> ```
>> drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c: In function ‘eb_copy_relocations’:
>> drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c:1681:24: error: allocation of insufficient size ‘1’ for type ‘struct drm_i915_gem_relocation_entry’ with size ‘32’ [-Werror=alloc-size]
>> 1681 | relocs = kvmalloc_array(size, 1, GFP_KERNEL);
>> | ^
>>
>> ```
>>
>> So, just swap the number of members and size arguments to match the prototype, as
>> we're initialising 1 element of size `size`. GCC then sees we're not
>> doing anything wrong.
>>
>> Signed-off-by: Sam James <sam@gentoo.org>
>
> The short answer,
>
> Reviewed-by: Jani Nikula <jani.nikula@intel.com>
And pushed to drm-intel-gt-next, thanks for the patch.
BR,
Jani.
>
> but please read on.
>
>> ---
>> drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
>> index 683fd8d3151c..45b9d9e34b8b 100644
>> --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
>> +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
>> @@ -1678,7 +1678,7 @@ static int eb_copy_relocations(const struct i915_execbuffer *eb)
>> urelocs = u64_to_user_ptr(eb->exec[i].relocs_ptr);
>> size = nreloc * sizeof(*relocs);
>>
>> - relocs = kvmalloc_array(size, 1, GFP_KERNEL);
>> + relocs = kvmalloc_array(1, size, GFP_KERNEL);
>
> Based on the patch context, we should really be calling:
>
> kvmalloc_array(nreloc, sizeof(*relocs), GFP_KERNEL);
>
> and we'd get mul overflow checks too.
>
> However, the code below also needs size, unless it's refactored to
> operate on multiples of sizeof(*relocs) and it all gets a bit annoying.
>
> Maybe there's a better way, but for the short term the patch at hand is
> no worse than what we currently have, and it'll silence the warning, so
> let's go with this.
>
>
>> if (!relocs) {
>> err = -ENOMEM;
>> goto err;
--
Jani Nikula, Intel
WARNING: multiple messages have this Message-ID (diff)
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Sam James <sam@gentoo.org>,
intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@intel.com>,
Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
Cc: Sam James <sam@gentoo.org>
Subject: Re: [PATCH] drm: i915: Adapt to -Walloc-size
Date: Thu, 09 Nov 2023 13:12:33 +0200 [thread overview]
Message-ID: <87zfznw57i.fsf@intel.com> (raw)
In-Reply-To: <87jzqsy3sp.fsf@intel.com>
On Wed, 08 Nov 2023, Jani Nikula <jani.nikula@linux.intel.com> wrote:
> On Tue, 07 Nov 2023, Sam James <sam@gentoo.org> wrote:
>> GCC 14 introduces a new -Walloc-size included in -Wextra which errors out
>> like:
>> ```
>> drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c: In function ‘eb_copy_relocations’:
>> drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c:1681:24: error: allocation of insufficient size ‘1’ for type ‘struct drm_i915_gem_relocation_entry’ with size ‘32’ [-Werror=alloc-size]
>> 1681 | relocs = kvmalloc_array(size, 1, GFP_KERNEL);
>> | ^
>>
>> ```
>>
>> So, just swap the number of members and size arguments to match the prototype, as
>> we're initialising 1 element of size `size`. GCC then sees we're not
>> doing anything wrong.
>>
>> Signed-off-by: Sam James <sam@gentoo.org>
>
> The short answer,
>
> Reviewed-by: Jani Nikula <jani.nikula@intel.com>
And pushed to drm-intel-gt-next, thanks for the patch.
BR,
Jani.
>
> but please read on.
>
>> ---
>> drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
>> index 683fd8d3151c..45b9d9e34b8b 100644
>> --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
>> +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
>> @@ -1678,7 +1678,7 @@ static int eb_copy_relocations(const struct i915_execbuffer *eb)
>> urelocs = u64_to_user_ptr(eb->exec[i].relocs_ptr);
>> size = nreloc * sizeof(*relocs);
>>
>> - relocs = kvmalloc_array(size, 1, GFP_KERNEL);
>> + relocs = kvmalloc_array(1, size, GFP_KERNEL);
>
> Based on the patch context, we should really be calling:
>
> kvmalloc_array(nreloc, sizeof(*relocs), GFP_KERNEL);
>
> and we'd get mul overflow checks too.
>
> However, the code below also needs size, unless it's refactored to
> operate on multiples of sizeof(*relocs) and it all gets a bit annoying.
>
> Maybe there's a better way, but for the short term the patch at hand is
> no worse than what we currently have, and it'll silence the warning, so
> let's go with this.
>
>
>> if (!relocs) {
>> err = -ENOMEM;
>> goto err;
--
Jani Nikula, Intel
next prev parent reply other threads:[~2023-11-09 11:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-07 21:55 [Intel-gfx] [PATCH] drm: i915: Adapt to -Walloc-size Sam James
2023-11-07 21:55 ` Sam James
2023-11-08 9:47 ` [Intel-gfx] " Jani Nikula
2023-11-08 9:47 ` Jani Nikula
2023-11-09 11:12 ` Jani Nikula [this message]
2023-11-09 11:12 ` Jani Nikula
2023-11-11 7:54 ` [Intel-gfx] " Sam James
2023-11-11 7:54 ` Sam James
2023-11-08 11:14 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for " Patchwork
2023-11-08 11:27 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2023-11-08 17:50 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87zfznw57i.fsf@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=airlied@gmail.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=joonas.lahtinen@linux.intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=sam@gentoo.org \
--cc=tvrtko.ursulin@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.