[PATCH] xen/serial: scif: Rework how the parameters are found

Julien Grall posted 1 patch 3 years, 4 months ago
Test gitlab-ci passed
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20201224165021.449-1-julien@xen.org
xen/drivers/char/scif-uart.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] xen/serial: scif: Rework how the parameters are found
Posted by Julien Grall 3 years, 4 months ago
From: Julien Grall <jgrall@amazon.com>

clang 11 will throw the following error while build Xen:

scif-uart.c:333:33: error: cast to smaller integer type 'enum port_types' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]
    uart->params = &port_params[(enum port_types)match->data];
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

The error can be prevented by directly storing a pointer to the port
parameters rather than the a cast of the port type.

Signed-off-by: Julien Grall <jgrall@amazon.com>

---

Only build tested as I don't have the HW.
---
 xen/drivers/char/scif-uart.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/xen/drivers/char/scif-uart.c b/xen/drivers/char/scif-uart.c
index 9d3f66b55b67..ee204a11a471 100644
--- a/xen/drivers/char/scif-uart.c
+++ b/xen/drivers/char/scif-uart.c
@@ -286,8 +286,8 @@ static struct uart_driver __read_mostly scif_uart_driver = {
 
 static const struct dt_device_match scif_uart_dt_match[] __initconst =
 {
-    { .compatible = "renesas,scif",  .data = (void *)SCIF_PORT },
-    { .compatible = "renesas,scifa", .data = (void *)SCIFA_PORT },
+    { .compatible = "renesas,scif",  .data = &port_params[SCIF_PORT] },
+    { .compatible = "renesas,scifa", .data = &port_params[SCIFA_PORT] },
     { /* sentinel */ },
 };
 
@@ -330,7 +330,7 @@ static int __init scif_uart_init(struct dt_device_node *dev,
 
     match = dt_match_node(scif_uart_dt_match, dev);
     ASSERT( match );
-    uart->params = &port_params[(enum port_types)match->data];
+    uart->params = match->data;
 
     uart->vuart.base_addr  = addr;
     uart->vuart.size       = size;
-- 
2.17.1


Re: [PATCH] xen/serial: scif: Rework how the parameters are found
Posted by Oleksandr 3 years, 4 months ago
On 24.12.20 18:50, Julien Grall wrote:

Hi Julien

> From: Julien Grall <jgrall@amazon.com>
>
> clang 11 will throw the following error while build Xen:
>
> scif-uart.c:333:33: error: cast to smaller integer type 'enum port_types' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]
>      uart->params = &port_params[(enum port_types)match->data];
>                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> The error can be prevented by directly storing a pointer to the port
> parameters rather than the a cast of the port type.
>
> Signed-off-by: Julien Grall <jgrall@amazon.com>
>
> ---
>
> Only build tested as I don't have the HW.

I don't have an access to the SCIFA based HW at the moment, but on Gen3 
H3 SoC (SCIF) it works.


> ---
>   xen/drivers/char/scif-uart.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/xen/drivers/char/scif-uart.c b/xen/drivers/char/scif-uart.c
> index 9d3f66b55b67..ee204a11a471 100644
> --- a/xen/drivers/char/scif-uart.c
> +++ b/xen/drivers/char/scif-uart.c
> @@ -286,8 +286,8 @@ static struct uart_driver __read_mostly scif_uart_driver = {
>   
>   static const struct dt_device_match scif_uart_dt_match[] __initconst =
>   {
> -    { .compatible = "renesas,scif",  .data = (void *)SCIF_PORT },
> -    { .compatible = "renesas,scifa", .data = (void *)SCIFA_PORT },
> +    { .compatible = "renesas,scif",  .data = &port_params[SCIF_PORT] },
> +    { .compatible = "renesas,scifa", .data = &port_params[SCIFA_PORT] },
>       { /* sentinel */ },
>   };
>   
> @@ -330,7 +330,7 @@ static int __init scif_uart_init(struct dt_device_node *dev,
>   
>       match = dt_match_node(scif_uart_dt_match, dev);
>       ASSERT( match );
> -    uart->params = &port_params[(enum port_types)match->data];
> +    uart->params = match->data;
>   
>       uart->vuart.base_addr  = addr;
>       uart->vuart.size       = size;

-- 
Regards,

Oleksandr Tyshchenko


Re: [PATCH] xen/serial: scif: Rework how the parameters are found
Posted by Stefano Stabellini 3 years, 3 months ago
On Thu, 24 Dec 2020, Julien Grall wrote:
> From: Julien Grall <jgrall@amazon.com>
> 
> clang 11 will throw the following error while build Xen:
> 
> scif-uart.c:333:33: error: cast to smaller integer type 'enum port_types' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]
>     uart->params = &port_params[(enum port_types)match->data];
>                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> The error can be prevented by directly storing a pointer to the port
> parameters rather than the a cast of the port type.
> 
> Signed-off-by: Julien Grall <jgrall@amazon.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
> 
> Only build tested as I don't have the HW.
> ---
>  xen/drivers/char/scif-uart.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/xen/drivers/char/scif-uart.c b/xen/drivers/char/scif-uart.c
> index 9d3f66b55b67..ee204a11a471 100644
> --- a/xen/drivers/char/scif-uart.c
> +++ b/xen/drivers/char/scif-uart.c
> @@ -286,8 +286,8 @@ static struct uart_driver __read_mostly scif_uart_driver = {
>  
>  static const struct dt_device_match scif_uart_dt_match[] __initconst =
>  {
> -    { .compatible = "renesas,scif",  .data = (void *)SCIF_PORT },
> -    { .compatible = "renesas,scifa", .data = (void *)SCIFA_PORT },
> +    { .compatible = "renesas,scif",  .data = &port_params[SCIF_PORT] },
> +    { .compatible = "renesas,scifa", .data = &port_params[SCIFA_PORT] },
>      { /* sentinel */ },
>  };
>  
> @@ -330,7 +330,7 @@ static int __init scif_uart_init(struct dt_device_node *dev,
>  
>      match = dt_match_node(scif_uart_dt_match, dev);
>      ASSERT( match );
> -    uart->params = &port_params[(enum port_types)match->data];
> +    uart->params = match->data;
>  
>      uart->vuart.base_addr  = addr;
>      uart->vuart.size       = size;
> -- 
> 2.17.1
>