[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [XEN PATCH 2/4] x86/emulate: move a variable declaration to address MISRA C:2012 Rule 5.3
- To: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
- From: Jan Beulich <jbeulich@xxxxxxxx>
- Date: Thu, 27 Jul 2023 17:31:20 +0200
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=M9dleTywZq3fAzH8saLveL7a84hScw/lpvlbTNpB+ec=; b=TEoobtxTuXPGBVI7GFcJSODP8qtQrefaFxSSM0D6lnG5witRQLgwrlvf8vGPahuTrp9WNrmSD7ZgmG3fKl3FYEL3qD3LkrWS5FCflSZq1Jrxlnd3w19tDtisqyY63aNSt4DQcpTorjD8rx7Gpa02/rrZvaQkrW+O65f9qmR99xF04nWsTiSA8vcdDwZEMRnv75r9gg3NwHWS3RYnQ3GQBKSMRmQ7UzZotQExRg2WWD6KO5gJVqtXKZzuDHp1d8vMNZSYw3ew7i+G+TpnMAAMZG+rwL7UB+6vSOUo+txspp690Cw/E3n9QMy9TRnyzCE28Q5Li5GZeQ6wCdlQXz79Bw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hWR8bnuDmMHwQAXEn6wWTpMxqwRxz1UdqkeVX05EFdBhHHkg1ljvwp8DTscZcOykpuE9Jg19pcq97PQVYEGDWY3XOcXKpZwik+h5OUYU7OOKcSgBMvkj+NEGEE4LThpHNEfphISX7eGO++2EfBSlK3tbihCPfmmEoaFUb09pvi/cHzAcxDlz3jenZ0xgk4aCqRaqzyJ1fGxBbx+GUxOWlqo6t6Dlg0J4jDUdpsNSlRA2GvicaC4wbBZ3BjOPso1PdzHNH6k+n+yRmpOfI5qm4emXfsR77YoWjFfgcQH9Xg2V9usH9/6LblMmG8zX9jCpVD2WZlPwwMB7/81nFL/5PQ==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
- Cc: sstabellini@xxxxxxxxxx, michal.orzel@xxxxxxx, xenia.ragiadakou@xxxxxxx, ayan.kumar.halder@xxxxxxx, consulting@xxxxxxxxxxx, Paul Durrant <paul@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
- Delivery-date: Thu, 27 Jul 2023 15:31:31 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 27.07.2023 17:22, Nicola Vetrini wrote:
>
>
> On 27/07/23 17:06, Jan Beulich wrote:
>> On 27.07.2023 12:48, Nicola Vetrini wrote:
>>> --- a/xen/arch/x86/hvm/emulate.c
>>> +++ b/xen/arch/x86/hvm/emulate.c
>>> @@ -2024,15 +2024,15 @@ static int cf_check hvmemul_rep_stos(
>>>
>>> switch ( p2mt )
>>> {
>>> - unsigned long bytes;
>>> char *buf;
>>>
>>> default:
>>> /* Allocate temporary buffer. */
>>> for ( ; ; )
>>> {
>>> - bytes = *reps * bytes_per_rep;
>>> - buf = xmalloc_bytes(bytes);
>>> + unsigned long bytes_tmp;
>>> + bytes_tmp = *reps * bytes_per_rep;
>>> + buf = xmalloc_bytes(bytes_tmp);
>>> if ( buf || *reps <= 1 )
>>> break;
>>> *reps >>= 1;
>>
>> This wants dealing with differently - the outer scope variable is unused
>> (only written to) afaics. Eliminating it will, aiui, address another
>> violation at the same time. And then the same in hvmemul_rep_movs(), just
>> that there the variable itself needs to survive. I guess I'll make a
>> patch ...
>
> Wouldn't this code at line ~2068 be possibly affected by writing to
> bytes, if the outer variable is used?
Which outer variable? I'm suggesting to drop that (see the patch that
I've sent already).
Jan
> /* Adjust address for reverse store. */
> if ( df )
> gpa -= bytes - bytes_per_rep;
>
> rc = hvm_copy_to_guest_phys(gpa, buf, bytes, curr);
>
> You're right about the other violation (R2.1)
>
|