* [Xen-devel] [PATCH] xen/arm: optee: fix compilation with GCC 4.8
@ 2019-06-20 15:50 Volodymyr Babchuk
2019-06-21 0:28 ` Stefano Stabellini
0 siblings, 1 reply; 3+ messages in thread
From: Volodymyr Babchuk @ 2019-06-20 15:50 UTC (permalink / raw)
To: Stefano Stabellini, Julien Grall
Cc: xen-devel, Volodymyr Babchuk, Stefano Stabellini
GCC 4.8 is unable to see that variables guest_pg, guest_data and
xen_data will be always initialized before access, so we need to
initialize them earlier.
Suggested-by: Stefano Stabellini <stefanos@xilinx.com>
Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
---
xen/arch/arm/tee/optee.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/xen/arch/arm/tee/optee.c b/xen/arch/arm/tee/optee.c
index 14381d6b2d..5526875e6f 100644
--- a/xen/arch/arm/tee/optee.c
+++ b/xen/arch/arm/tee/optee.c
@@ -717,6 +717,19 @@ static int translate_noncontig(struct optee_domain *ctx,
gfn = gaddr_to_gfn(param->u.tmem.buf_ptr &
~(OPTEE_MSG_NONCONTIG_PAGE_SIZE - 1));
+ /*
+ * We are initializing guest_pg, guest_data and xen_data with NULL
+ * to make GCC 4.8 happy, as it can't infer that those variables
+ * will be initialized with correct values in the loop below.
+ *
+ * This silences old GCC, but can lead to NULL dereference, in
+ * case of programmer's mistake. To minimize chance of this, we
+ * are initializing those variables there, instead of doing this
+ * at beginning of the function.
+ */
+ guest_pg = NULL;
+ xen_data = NULL;
+ guest_data = NULL;
while ( pg_count )
{
struct page_info *page;
--
2.21.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Xen-devel] [PATCH] xen/arm: optee: fix compilation with GCC 4.8
2019-06-20 15:50 [Xen-devel] [PATCH] xen/arm: optee: fix compilation with GCC 4.8 Volodymyr Babchuk
@ 2019-06-21 0:28 ` Stefano Stabellini
2019-06-21 9:33 ` Julien Grall
0 siblings, 1 reply; 3+ messages in thread
From: Stefano Stabellini @ 2019-06-21 0:28 UTC (permalink / raw)
To: Volodymyr Babchuk
Cc: xen-devel, Julien Grall, Stefano Stabellini, Stefano Stabellini
On Thu, 20 Jun 2019, Volodymyr Babchuk wrote:
> GCC 4.8 is unable to see that variables guest_pg, guest_data and
> xen_data will be always initialized before access, so we need to
> initialize them earlier.
>
> Suggested-by: Stefano Stabellini <stefanos@xilinx.com>
> Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
I verified that it works correctly. Thanks for the patch! (Julien, I
didn't commit it yet to give you a chance to give it a look too.)
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> ---
> xen/arch/arm/tee/optee.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/xen/arch/arm/tee/optee.c b/xen/arch/arm/tee/optee.c
> index 14381d6b2d..5526875e6f 100644
> --- a/xen/arch/arm/tee/optee.c
> +++ b/xen/arch/arm/tee/optee.c
> @@ -717,6 +717,19 @@ static int translate_noncontig(struct optee_domain *ctx,
> gfn = gaddr_to_gfn(param->u.tmem.buf_ptr &
> ~(OPTEE_MSG_NONCONTIG_PAGE_SIZE - 1));
>
> + /*
> + * We are initializing guest_pg, guest_data and xen_data with NULL
> + * to make GCC 4.8 happy, as it can't infer that those variables
> + * will be initialized with correct values in the loop below.
> + *
> + * This silences old GCC, but can lead to NULL dereference, in
> + * case of programmer's mistake. To minimize chance of this, we
> + * are initializing those variables there, instead of doing this
> + * at beginning of the function.
> + */
> + guest_pg = NULL;
> + xen_data = NULL;
> + guest_data = NULL;
> while ( pg_count )
> {
> struct page_info *page;
> --
> 2.21.0
>
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Xen-devel] [PATCH] xen/arm: optee: fix compilation with GCC 4.8
2019-06-21 0:28 ` Stefano Stabellini
@ 2019-06-21 9:33 ` Julien Grall
0 siblings, 0 replies; 3+ messages in thread
From: Julien Grall @ 2019-06-21 9:33 UTC (permalink / raw)
To: Stefano Stabellini, Volodymyr Babchuk; +Cc: xen-devel, Stefano Stabellini
On 21/06/2019 01:28, Stefano Stabellini wrote:
> On Thu, 20 Jun 2019, Volodymyr Babchuk wrote:
>> GCC 4.8 is unable to see that variables guest_pg, guest_data and
>> xen_data will be always initialized before access, so we need to
>> initialize them earlier.
>>
>> Suggested-by: Stefano Stabellini <stefanos@xilinx.com>
>> Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
>
> I verified that it works correctly. Thanks for the patch! (Julien, I
> didn't commit it yet to give you a chance to give it a look too.)
>
> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Julien Grall <julien.grall@arm.com>
I have committed it now.
Cheers,
--
Julien Grall
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-06-21 9:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-20 15:50 [Xen-devel] [PATCH] xen/arm: optee: fix compilation with GCC 4.8 Volodymyr Babchuk
2019-06-21 0:28 ` Stefano Stabellini
2019-06-21 9:33 ` Julien Grall
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).