Re: [PATCH] arch:x86:coco:sev: Initialize ctxt variable

From: Tom Lendacky
Date: Mon Nov 18 2024 - 09:45:57 EST


On 11/15/24 16:55, Ard Biesheuvel wrote:
> On Fri, 15 Nov 2024 at 20:53, Ragavendra B.N. <ragavendra.bn@xxxxxxxxx> wrote:
>>
>> On Fri, Nov 15, 2024 at 12:02:27PM +0100, Ard Biesheuvel wrote:
>>> On Fri, 15 Nov 2024 at 12:01, Ingo Molnar <mingo@xxxxxxxxxx> wrote:
>>>>
>>>>
>>>> * Ragavendra <ragavendra.bn@xxxxxxxxx> wrote:
>>>>
>>>>> Updating the ctxt value to NULL in the svsm_perform_ghcb_protocol as
>>>>> it was not initialized.
>>>>>
>>>>> Fixes: 2e1b3cc9d7f7 (grafted) Merge tag 'arm-fixes-6.12-2' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
>>>>
>>>> This 'Fixes' tag looks bogus.
>>>>
>>>
>>> So does the patch itself - 'struct es_em_ctxt ctxt' is not a pointer.
>> Thank you very much for your response. I am relatively new to kernel development.
>>
>> I know we can use kmalloc for memory allocation. Please advice.
>>
>> struct es_em_ctxt ctxt = kmalloc(sizeof(struct es_em_ctxt), GFP_KERNEL);
>>
>> I am thinking to update like above, but like you mentioned, ctxt is not a pointer. I can update this to be a pointer if needed.
>>
>
> The code is fine as is. Let's end this thread here, shall we?

I was assuming he got some kind of warning from some compiler options or
a static checker. Is that the case Ragavendra?

When I look at the code, it is possible for ctxt->fi.error_code to be
left uninitialized. The simple fix is to just initialize ctxt as:

struct es_em_ctxt ctxt = {};

Thanks,
Tom