linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ocxl: Fix endiannes bug in read_afu_name()
@ 2018-12-10 15:10 Greg Kurz
  2018-12-10 15:54 ` Frederic Barrat
  2018-12-11  0:05 ` Andrew Donnellan
  0 siblings, 2 replies; 5+ messages in thread
From: Greg Kurz @ 2018-12-10 15:10 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Christophe Lombard, Vaibhav Jain, stable, Frederic Barrat,
	Andrew Donnellan

The double word returned by read_afu_info(OCXL_DVSEC_TEMPL_NAME) contains
four characters of the AFU name, read from the PCI config space, hence
with a little-endian ordering. When composing the string, a big-endian
system must swap the bytes so that the characters appear in the right
order.

Do this with le32_to_cpu().

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 drivers/misc/ocxl/config.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c
index 57a6bb1fd3c9..b76198ba8630 100644
--- a/drivers/misc/ocxl/config.c
+++ b/drivers/misc/ocxl/config.c
@@ -318,7 +318,7 @@ static int read_afu_name(struct pci_dev *dev, struct ocxl_fn_config *fn,
 		if (rc)
 			return rc;
 		ptr = (u32 *) &afu->name[i];
-		*ptr = val;
+		*ptr = le32_to_cpu(val);
 	}
 	afu->name[OCXL_AFU_NAME_SZ - 1] = '\0'; /* play safe */
 	return 0;


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] ocxl: Fix endiannes bug in read_afu_name()
  2018-12-10 15:10 [PATCH] ocxl: Fix endiannes bug in read_afu_name() Greg Kurz
@ 2018-12-10 15:54 ` Frederic Barrat
  2018-12-11  0:05 ` Andrew Donnellan
  1 sibling, 0 replies; 5+ messages in thread
From: Frederic Barrat @ 2018-12-10 15:54 UTC (permalink / raw)
  To: Greg Kurz, linuxppc-dev
  Cc: Christophe Lombard, Vaibhav Jain, stable, Frederic Barrat,
	Andrew Donnellan



Le 10/12/2018 à 16:10, Greg Kurz a écrit :
> The double word returned by read_afu_info(OCXL_DVSEC_TEMPL_NAME) contains
> four characters of the AFU name, read from the PCI config space, hence
> with a little-endian ordering. When composing the string, a big-endian
> system must swap the bytes so that the characters appear in the right
> order.
> 
> Do this with le32_to_cpu().
> 
> Signed-off-by: Greg Kurz <groug@kaod.org>
> ---

Thanks!

Acked-by: Frederic Barrat <fbarrat@linux.ibm.com>


>   drivers/misc/ocxl/config.c |    2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c
> index 57a6bb1fd3c9..b76198ba8630 100644
> --- a/drivers/misc/ocxl/config.c
> +++ b/drivers/misc/ocxl/config.c
> @@ -318,7 +318,7 @@ static int read_afu_name(struct pci_dev *dev, struct ocxl_fn_config *fn,
>   		if (rc)
>   			return rc;
>   		ptr = (u32 *) &afu->name[i];
> -		*ptr = val;
> +		*ptr = le32_to_cpu(val);
>   	}
>   	afu->name[OCXL_AFU_NAME_SZ - 1] = '\0'; /* play safe */
>   	return 0;
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ocxl: Fix endiannes bug in read_afu_name()
  2018-12-10 15:10 [PATCH] ocxl: Fix endiannes bug in read_afu_name() Greg Kurz
  2018-12-10 15:54 ` Frederic Barrat
@ 2018-12-11  0:05 ` Andrew Donnellan
  2018-12-11  0:24   ` Andrew Donnellan
  1 sibling, 1 reply; 5+ messages in thread
From: Andrew Donnellan @ 2018-12-11  0:05 UTC (permalink / raw)
  To: Greg Kurz, linuxppc-dev
  Cc: stable, Christophe Lombard, Frederic Barrat, Vaibhav Jain

On 11/12/18 2:10 am, Greg Kurz wrote:
> The double word returned by read_afu_info(OCXL_DVSEC_TEMPL_NAME) contains
> four characters of the AFU name, read from the PCI config space, hence
> with a little-endian ordering. When composing the string, a big-endian
> system must swap the bytes so that the characters appear in the right
> order.
> 
> Do this with le32_to_cpu().
> 
> Signed-off-by: Greg Kurz <groug@kaod.org>

snowpatch reports the following sparse warning:

+drivers/misc/ocxl/config.c:321:24: warning: cast to restricted __le32

You probably need to change val from a u32 to a __le32.

> ---
>   drivers/misc/ocxl/config.c |    2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c
> index 57a6bb1fd3c9..b76198ba8630 100644
> --- a/drivers/misc/ocxl/config.c
> +++ b/drivers/misc/ocxl/config.c
> @@ -318,7 +318,7 @@ static int read_afu_name(struct pci_dev *dev, struct ocxl_fn_config *fn,
>   		if (rc)
>   			return rc;
>   		ptr = (u32 *) &afu->name[i];
> -		*ptr = val;
> +		*ptr = le32_to_cpu(val);
>   	}
>   	afu->name[OCXL_AFU_NAME_SZ - 1] = '\0'; /* play safe */
>   	return 0;
> 

-- 
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com  IBM Australia Limited


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ocxl: Fix endiannes bug in read_afu_name()
  2018-12-11  0:05 ` Andrew Donnellan
@ 2018-12-11  0:24   ` Andrew Donnellan
  2018-12-11  8:33     ` Greg Kurz
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Donnellan @ 2018-12-11  0:24 UTC (permalink / raw)
  To: Greg Kurz, linuxppc-dev
  Cc: stable, Christophe Lombard, Frederic Barrat, Vaibhav Jain

On 11/12/18 11:05 am, Andrew Donnellan wrote:
> On 11/12/18 2:10 am, Greg Kurz wrote:
>> The double word returned by read_afu_info(OCXL_DVSEC_TEMPL_NAME) contains
>> four characters of the AFU name, read from the PCI config space, hence
>> with a little-endian ordering. When composing the string, a big-endian
>> system must swap the bytes so that the characters appear in the right
>> order.
>>
>> Do this with le32_to_cpu().
>>
>> Signed-off-by: Greg Kurz <groug@kaod.org>
> 
> snowpatch reports the following sparse warning:
> 
> +drivers/misc/ocxl/config.c:321:24: warning: cast to restricted __le32
> 
> You probably need to change val from a u32 to a __le32.

Also does this need to go to stable?

-- 
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnellan@au1.ibm.com  IBM Australia Limited


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ocxl: Fix endiannes bug in read_afu_name()
  2018-12-11  0:24   ` Andrew Donnellan
@ 2018-12-11  8:33     ` Greg Kurz
  0 siblings, 0 replies; 5+ messages in thread
From: Greg Kurz @ 2018-12-11  8:33 UTC (permalink / raw)
  To: Andrew Donnellan
  Cc: Christophe Lombard, Vaibhav Jain, stable, Frederic Barrat, linuxppc-dev

On Tue, 11 Dec 2018 11:24:08 +1100
Andrew Donnellan <andrew.donnellan@au1.ibm.com> wrote:

> On 11/12/18 11:05 am, Andrew Donnellan wrote:
> > On 11/12/18 2:10 am, Greg Kurz wrote:  
> >> The double word returned by read_afu_info(OCXL_DVSEC_TEMPL_NAME) contains
> >> four characters of the AFU name, read from the PCI config space, hence
> >> with a little-endian ordering. When composing the string, a big-endian
> >> system must swap the bytes so that the characters appear in the right
> >> order.
> >>
> >> Do this with le32_to_cpu().
> >>
> >> Signed-off-by: Greg Kurz <groug@kaod.org>  
> > 
> > snowpatch reports the following sparse warning:
> > 
> > +drivers/misc/ocxl/config.c:321:24: warning: cast to restricted __le32
> > 
> > You probably need to change val from a u32 to a __le32.  
> 

You might be right, I'll look into this.

> Also does this need to go to stable?
> 

Oops... this bug has been there since the beginning, so yes
it does. I simply forgot to add the Cc: stable tag... :-\

Cheers,

--
Greg

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-12-11  8:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-10 15:10 [PATCH] ocxl: Fix endiannes bug in read_afu_name() Greg Kurz
2018-12-10 15:54 ` Frederic Barrat
2018-12-11  0:05 ` Andrew Donnellan
2018-12-11  0:24   ` Andrew Donnellan
2018-12-11  8:33     ` Greg Kurz

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).