From: Jani Nikula <jani.nikula@intel.com>
To: "Christian König" <christian.koenig@amd.com>,
"Grigory Vasilyev" <h0tc0d3@gmail.com>,
"Rodrigo Siqueira" <Rodrigo.Siqueira@amd.com>,
"Melissa Wen" <mwen@igalia.com>
Cc: Jiawei Gu <Jiawei.Gu@amd.com>, David Airlie <airlied@linux.ie>,
"Pan, Xinhui" <Xinhui.Pan@amd.com>,
Lucas De Marchi <lucas.demarchi@intel.com>,
linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org,
dri-devel@lists.freedesktop.org, Daniel Vetter <daniel@ffwll.ch>,
Alex Deucher <alexander.deucher@amd.com>
Subject: Re: [PATCH] drm/amdgpu: Senseless code and unnecessary memset
Date: Wed, 06 Apr 2022 17:26:44 +0300 [thread overview]
Message-ID: <874k3670ez.fsf@intel.com> (raw)
In-Reply-To: <614a4844-fa5d-8b8e-0628-894394f31608@amd.com>
On Tue, 05 Apr 2022, Christian König <christian.koenig@amd.com> wrote:
> Am 05.04.22 um 19:36 schrieb Grigory Vasilyev:
>> Using memset on local arrays before exiting the function is pointless.
>> Compilator will remove this code. Also for local arrays is preferable to
>> use {0} instead of memset. Mistakes are often made when working with
>> memset.
>
> Well actually memset is preferred when working with structures which are
> given to the hardware parser because {0} won't initialize paddings.
Not that I'd know anything that's going on here... but it sure seems
strange to me to be passing unpacked structures where the padding might
matter to a "hardware parser".
*shrug*
BR,
Jani.
>
> So please don't use {0} in any of the atom bios code.
>
> Regards,
> Christian.
>
>>
>> Signed-off-by: Grigory Vasilyev <h0tc0d3@gmail.com>
>> ---
>> drivers/gpu/drm/amd/amdgpu/atom.c | 8 +-------
>> 1 file changed, 1 insertion(+), 7 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/atom.c b/drivers/gpu/drm/amd/amdgpu/atom.c
>> index be9d61bcb8ae..537e48fbbe6b 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/atom.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/atom.c
>> @@ -1538,11 +1538,9 @@ struct atom_context *amdgpu_atom_parse(struct card_info *card, void *bios)
>> int amdgpu_atom_asic_init(struct atom_context *ctx)
>> {
>> int hwi = CU16(ctx->data_table + ATOM_DATA_FWI_PTR);
>> - uint32_t ps[16];
>> + uint32_t ps[16] = {0};
>> int ret;
>>
>> - memset(ps, 0, 64);
>> -
>> ps[0] = cpu_to_le32(CU32(hwi + ATOM_FWI_DEFSCLK_PTR));
>> ps[1] = cpu_to_le32(CU32(hwi + ATOM_FWI_DEFMCLK_PTR));
>> if (!ps[0] || !ps[1])
>> @@ -1551,10 +1549,6 @@ int amdgpu_atom_asic_init(struct atom_context *ctx)
>> if (!CU16(ctx->cmd_table + 4 + 2 * ATOM_CMD_INIT))
>> return 1;
>> ret = amdgpu_atom_execute_table(ctx, ATOM_CMD_INIT, ps);
>> - if (ret)
>> - return ret;
>> -
>> - memset(ps, 0, 64);
>>
>> return ret;
>> }
>
--
Jani Nikula, Intel Open Source Graphics Center
WARNING: multiple messages have this Message-ID (diff)
From: Jani Nikula <jani.nikula@intel.com>
To: "Christian König" <christian.koenig@amd.com>,
"Grigory Vasilyev" <h0tc0d3@gmail.com>,
"Rodrigo Siqueira" <Rodrigo.Siqueira@amd.com>,
"Melissa Wen" <mwen@igalia.com>
Cc: Jiawei Gu <Jiawei.Gu@amd.com>, David Airlie <airlied@linux.ie>,
"Pan, Xinhui" <Xinhui.Pan@amd.com>,
Lucas De Marchi <lucas.demarchi@intel.com>,
linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org,
dri-devel@lists.freedesktop.org,
Alex Deucher <alexander.deucher@amd.com>
Subject: Re: [PATCH] drm/amdgpu: Senseless code and unnecessary memset
Date: Wed, 06 Apr 2022 17:26:44 +0300 [thread overview]
Message-ID: <874k3670ez.fsf@intel.com> (raw)
In-Reply-To: <614a4844-fa5d-8b8e-0628-894394f31608@amd.com>
On Tue, 05 Apr 2022, Christian König <christian.koenig@amd.com> wrote:
> Am 05.04.22 um 19:36 schrieb Grigory Vasilyev:
>> Using memset on local arrays before exiting the function is pointless.
>> Compilator will remove this code. Also for local arrays is preferable to
>> use {0} instead of memset. Mistakes are often made when working with
>> memset.
>
> Well actually memset is preferred when working with structures which are
> given to the hardware parser because {0} won't initialize paddings.
Not that I'd know anything that's going on here... but it sure seems
strange to me to be passing unpacked structures where the padding might
matter to a "hardware parser".
*shrug*
BR,
Jani.
>
> So please don't use {0} in any of the atom bios code.
>
> Regards,
> Christian.
>
>>
>> Signed-off-by: Grigory Vasilyev <h0tc0d3@gmail.com>
>> ---
>> drivers/gpu/drm/amd/amdgpu/atom.c | 8 +-------
>> 1 file changed, 1 insertion(+), 7 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/atom.c b/drivers/gpu/drm/amd/amdgpu/atom.c
>> index be9d61bcb8ae..537e48fbbe6b 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/atom.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/atom.c
>> @@ -1538,11 +1538,9 @@ struct atom_context *amdgpu_atom_parse(struct card_info *card, void *bios)
>> int amdgpu_atom_asic_init(struct atom_context *ctx)
>> {
>> int hwi = CU16(ctx->data_table + ATOM_DATA_FWI_PTR);
>> - uint32_t ps[16];
>> + uint32_t ps[16] = {0};
>> int ret;
>>
>> - memset(ps, 0, 64);
>> -
>> ps[0] = cpu_to_le32(CU32(hwi + ATOM_FWI_DEFSCLK_PTR));
>> ps[1] = cpu_to_le32(CU32(hwi + ATOM_FWI_DEFMCLK_PTR));
>> if (!ps[0] || !ps[1])
>> @@ -1551,10 +1549,6 @@ int amdgpu_atom_asic_init(struct atom_context *ctx)
>> if (!CU16(ctx->cmd_table + 4 + 2 * ATOM_CMD_INIT))
>> return 1;
>> ret = amdgpu_atom_execute_table(ctx, ATOM_CMD_INIT, ps);
>> - if (ret)
>> - return ret;
>> -
>> - memset(ps, 0, 64);
>>
>> return ret;
>> }
>
--
Jani Nikula, Intel Open Source Graphics Center
WARNING: multiple messages have this Message-ID (diff)
From: Jani Nikula <jani.nikula@intel.com>
To: "Christian König" <christian.koenig@amd.com>,
"Grigory Vasilyev" <h0tc0d3@gmail.com>,
"Rodrigo Siqueira" <Rodrigo.Siqueira@amd.com>,
"Melissa Wen" <mwen@igalia.com>
Cc: Alex Deucher <alexander.deucher@amd.com>,
"Pan, Xinhui" <Xinhui.Pan@amd.com>,
David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
Jiawei Gu <Jiawei.Gu@amd.com>,
Lucas De Marchi <lucas.demarchi@intel.com>,
amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/amdgpu: Senseless code and unnecessary memset
Date: Wed, 06 Apr 2022 17:26:44 +0300 [thread overview]
Message-ID: <874k3670ez.fsf@intel.com> (raw)
In-Reply-To: <614a4844-fa5d-8b8e-0628-894394f31608@amd.com>
On Tue, 05 Apr 2022, Christian König <christian.koenig@amd.com> wrote:
> Am 05.04.22 um 19:36 schrieb Grigory Vasilyev:
>> Using memset on local arrays before exiting the function is pointless.
>> Compilator will remove this code. Also for local arrays is preferable to
>> use {0} instead of memset. Mistakes are often made when working with
>> memset.
>
> Well actually memset is preferred when working with structures which are
> given to the hardware parser because {0} won't initialize paddings.
Not that I'd know anything that's going on here... but it sure seems
strange to me to be passing unpacked structures where the padding might
matter to a "hardware parser".
*shrug*
BR,
Jani.
>
> So please don't use {0} in any of the atom bios code.
>
> Regards,
> Christian.
>
>>
>> Signed-off-by: Grigory Vasilyev <h0tc0d3@gmail.com>
>> ---
>> drivers/gpu/drm/amd/amdgpu/atom.c | 8 +-------
>> 1 file changed, 1 insertion(+), 7 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/atom.c b/drivers/gpu/drm/amd/amdgpu/atom.c
>> index be9d61bcb8ae..537e48fbbe6b 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/atom.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/atom.c
>> @@ -1538,11 +1538,9 @@ struct atom_context *amdgpu_atom_parse(struct card_info *card, void *bios)
>> int amdgpu_atom_asic_init(struct atom_context *ctx)
>> {
>> int hwi = CU16(ctx->data_table + ATOM_DATA_FWI_PTR);
>> - uint32_t ps[16];
>> + uint32_t ps[16] = {0};
>> int ret;
>>
>> - memset(ps, 0, 64);
>> -
>> ps[0] = cpu_to_le32(CU32(hwi + ATOM_FWI_DEFSCLK_PTR));
>> ps[1] = cpu_to_le32(CU32(hwi + ATOM_FWI_DEFMCLK_PTR));
>> if (!ps[0] || !ps[1])
>> @@ -1551,10 +1549,6 @@ int amdgpu_atom_asic_init(struct atom_context *ctx)
>> if (!CU16(ctx->cmd_table + 4 + 2 * ATOM_CMD_INIT))
>> return 1;
>> ret = amdgpu_atom_execute_table(ctx, ATOM_CMD_INIT, ps);
>> - if (ret)
>> - return ret;
>> -
>> - memset(ps, 0, 64);
>>
>> return ret;
>> }
>
--
Jani Nikula, Intel Open Source Graphics Center
next prev parent reply other threads:[~2022-04-06 15:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-05 17:36 [PATCH] drm/amdgpu: Senseless code and unnecessary memset Grigory Vasilyev
2022-04-05 17:36 ` Grigory Vasilyev
2022-04-05 17:36 ` Grigory Vasilyev
2022-04-05 17:38 ` Christian König
2022-04-05 17:38 ` Christian König
2022-04-05 17:38 ` Christian König
2022-04-06 14:26 ` Jani Nikula [this message]
2022-04-06 14:26 ` Jani Nikula
2022-04-06 14:26 ` Jani Nikula
2022-04-06 14:43 ` Christian König
2022-04-06 14:43 ` Christian König
2022-04-06 14:43 ` Christian König
2022-04-10 0:50 ` Grigory Vasilyev
2022-04-10 0:50 ` Grigory Vasilyev
2022-04-10 0:50 ` Grigory Vasilyev
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=874k3670ez.fsf@intel.com \
--to=jani.nikula@intel.com \
--cc=Jiawei.Gu@amd.com \
--cc=Rodrigo.Siqueira@amd.com \
--cc=Xinhui.Pan@amd.com \
--cc=airlied@linux.ie \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=h0tc0d3@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lucas.demarchi@intel.com \
--cc=mwen@igalia.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.