From: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
To: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>,
paulus@samba.org, jniethe5@gmail.com, naveen.n.rao@linux.ibm.com,
linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH] powerpc/sstep: Fix array out of bound warning
Date: Fri, 29 Jan 2021 12:48:21 +0530 [thread overview]
Message-ID: <5e77ece2-0baa-9f3e-f4b4-e159fd5044ff@linux.ibm.com> (raw)
In-Reply-To: <20210128172043.GB117@DESKTOP-TDPLP67.localdomain>
On 1/28/21 10:50 PM, Naveen N. Rao wrote:
> On 2021/01/15 11:46AM, Ravi Bangoria wrote:
>> Compiling kernel with -Warray-bounds throws below warning:
>>
>> In function 'emulate_vsx_store':
>> warning: array subscript is above array bounds [-Warray-bounds]
>> buf.d[2] = byterev_8(reg->d[1]);
>> ~~~~~^~~
>> buf.d[3] = byterev_8(reg->d[0]);
>> ~~~~~^~~
>>
>> Fix it by converting local variable 'union vsx_reg buf' into an array.
>> Also consider function argument 'union vsx_reg *reg' as array instead
>> of pointer because callers are actually passing an array to it.
>
> I think you should change the function prototype to reflect this.
>
> However, while I agree with this change in principle, it looks to be a
> lot of code churn for a fairly narrow use. Perhaps we should just
> address the specific bug. Something like the below (not tested)?
Yes, this would serve the same purpose and it's more compact as well. Sent v2.
>
> @@ -818,13 +818,15 @@ void emulate_vsx_store(struct instruction_op *op, const union vsx_reg *reg,
> break;
> if (rev) {
> /* reverse 32 bytes */
> - buf.d[0] = byterev_8(reg->d[3]);
> - buf.d[1] = byterev_8(reg->d[2]);
> - buf.d[2] = byterev_8(reg->d[1]);
> - buf.d[3] = byterev_8(reg->d[0]);
> - reg = &buf;
> + union vsx_reg buf32[2];
> + buf32[0].d[0] = byterev_8(reg[1].d[1]);
> + buf32[0].d[1] = byterev_8(reg[1].d[0]);
> + buf32[1].d[0] = byterev_8(reg[0].d[1]);
> + buf32[1].d[1] = byterev_8(reg[0].d[0]);
> + memcpy(mem, buf32, size);
> + } else {
> + memcpy(mem, reg, size);
> }
> - memcpy(mem, reg, size);
> break;
> case 16:
> /* stxv, stxvx, stxvl, stxvll */
>
>
> - Naveen
>
prev parent reply other threads:[~2021-01-29 7:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-15 6:16 [PATCH] powerpc/sstep: Fix array out of bound warning Ravi Bangoria
2021-01-28 17:20 ` Naveen N. Rao
2021-01-29 7:18 ` Ravi Bangoria [this message]
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=5e77ece2-0baa-9f3e-f4b4-e159fd5044ff@linux.ibm.com \
--to=ravi.bangoria@linux.ibm.com \
--cc=jniethe5@gmail.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=naveen.n.rao@linux.ibm.com \
--cc=naveen.n.rao@linux.vnet.ibm.com \
--cc=paulus@samba.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).