Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] PCI: Add cast when assigning PCI_ROM_ADDRESS_MASK to a 32-bit variable
@ 2017-04-10 22:24 Matthias Kaehlcke
  2017-04-11  1:24 ` Bjorn Helgaas
  0 siblings, 1 reply; 5+ messages in thread
From: Matthias Kaehlcke @ 2017-04-10 22:24 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: linux-pci, linux-kernel, Grant Grundler, Greg Hackmann,
	Michael Davidson, Matthias Kaehlcke

This fixes a clang warning about "implicit conversion from 'unsigned
long' to 'u32'"

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
 drivers/pci/probe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index dfc9a2794141..148e80d5caf1 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -180,7 +180,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
 	u16 orig_cmd;
 	struct pci_bus_region region, inverted_region;
 
-	mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
+	mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
 
 	/* No printks while decoding is disabled! */
 	if (!dev->mmio_always_on) {
-- 
2.12.2.715.g7642488e1d-goog

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

* Re: [PATCH] PCI: Add cast when assigning PCI_ROM_ADDRESS_MASK to a 32-bit variable
  2017-04-10 22:24 [PATCH] PCI: Add cast when assigning PCI_ROM_ADDRESS_MASK to a 32-bit variable Matthias Kaehlcke
@ 2017-04-11  1:24 ` Bjorn Helgaas
  2017-04-11 10:08   ` Mason
  0 siblings, 1 reply; 5+ messages in thread
From: Bjorn Helgaas @ 2017-04-11  1:24 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Bjorn Helgaas, linux-pci, linux-kernel, Grant Grundler,
	Greg Hackmann, Michael Davidson

On Mon, Apr 10, 2017 at 03:24:57PM -0700, Matthias Kaehlcke wrote:
> This fixes a clang warning about "implicit conversion from 'unsigned
> long' to 'u32'"
> 
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> ---
>  drivers/pci/probe.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index dfc9a2794141..148e80d5caf1 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -180,7 +180,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
>  	u16 orig_cmd;
>  	struct pci_bus_region region, inverted_region;
>  
> -	mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
> +	mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;

Can we put the cast in the PCI_ROM_ADDRESS_MASK #define so we don't have to
repeat it in all the uses?

>  	/* No printks while decoding is disabled! */
>  	if (!dev->mmio_always_on) {
> -- 
> 2.12.2.715.g7642488e1d-goog
> 

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

* Re: [PATCH] PCI: Add cast when assigning PCI_ROM_ADDRESS_MASK to a 32-bit variable
  2017-04-11  1:24 ` Bjorn Helgaas
@ 2017-04-11 10:08   ` Mason
  2017-04-11 17:23     ` Matthias Kaehlcke
  0 siblings, 1 reply; 5+ messages in thread
From: Mason @ 2017-04-11 10:08 UTC (permalink / raw)
  To: Bjorn Helgaas, Matthias Kaehlcke
  Cc: linux-pci, LKML, Grant Grundler, Greg Hackmann, Michael Davidson

On 11/04/2017 03:24, Bjorn Helgaas wrote:

> On Mon, Apr 10, 2017 at 03:24:57PM -0700, Matthias Kaehlcke wrote:
>
>> This fixes a clang warning about "implicit conversion from 'unsigned
>> long' to 'u32'"
>>
>> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
>> ---
>>  drivers/pci/probe.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
>> index dfc9a2794141..148e80d5caf1 100644
>> --- a/drivers/pci/probe.c
>> +++ b/drivers/pci/probe.c
>> @@ -180,7 +180,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
>>  	u16 orig_cmd;
>>  	struct pci_bus_region region, inverted_region;
>>  
>> -	mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
>> +	mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
> 
> Can we put the cast in the PCI_ROM_ADDRESS_MASK #define so we don't have to
> repeat it in all the uses?

Fixing these "implicit conversion" warnings, especially for
unsigned types, is a slippery slope. (The behavior of the
conversion is well-defined.)

How about changing the type of PCI_ROM_ADDRESS_MASK instead?
It's defined as ~0x7ffUL but it's only used in the context
of u32.

So make it an unsigned int:
#define PCI_ROM_ADDRESS_MASK (~0x7ffU)

AFAIU, unsigned int is 32 bits on all platforms supported
by Linux.

Regards.

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

* Re: [PATCH] PCI: Add cast when assigning PCI_ROM_ADDRESS_MASK to a 32-bit variable
  2017-04-11 10:08   ` Mason
@ 2017-04-11 17:23     ` Matthias Kaehlcke
  2017-04-11 17:28       ` Mason
  0 siblings, 1 reply; 5+ messages in thread
From: Matthias Kaehlcke @ 2017-04-11 17:23 UTC (permalink / raw)
  To: Mason
  Cc: Bjorn Helgaas, linux-pci, LKML, Grant Grundler, Greg Hackmann,
	Michael Davidson

El Tue, Apr 11, 2017 at 12:08:38PM +0200 Mason ha dit:

> On 11/04/2017 03:24, Bjorn Helgaas wrote:
> 
> > On Mon, Apr 10, 2017 at 03:24:57PM -0700, Matthias Kaehlcke wrote:
> >
> >> This fixes a clang warning about "implicit conversion from 'unsigned
> >> long' to 'u32'"
> >>
> >> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> >> ---
> >>  drivers/pci/probe.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> >> index dfc9a2794141..148e80d5caf1 100644
> >> --- a/drivers/pci/probe.c
> >> +++ b/drivers/pci/probe.c
> >> @@ -180,7 +180,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
> >>  	u16 orig_cmd;
> >>  	struct pci_bus_region region, inverted_region;
> >>  
> >> -	mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
> >> +	mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
> > 
> > Can we put the cast in the PCI_ROM_ADDRESS_MASK #define so we don't have to
> > repeat it in all the uses?
> 
> Fixing these "implicit conversion" warnings, especially for
> unsigned types, is a slippery slope. (The behavior of the
> conversion is well-defined.)
> 
> How about changing the type of PCI_ROM_ADDRESS_MASK instead?
> It's defined as ~0x7ffUL but it's only used in the context
> of u32.
> 
> So make it an unsigned int:
> #define PCI_ROM_ADDRESS_MASK (~0x7ffU)
> 
> AFAIU, unsigned int is 32 bits on all platforms supported
> by Linux.

I considered this initially, but wasn't sure if the unsigned long
mask might be needed in some cases. From the comments I interpret that
there should be no problems with using a 32 bit mask everywhere.

I'll send out an updated patch shortly.

Thanks

Matthias

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

* Re: [PATCH] PCI: Add cast when assigning PCI_ROM_ADDRESS_MASK to a 32-bit variable
  2017-04-11 17:23     ` Matthias Kaehlcke
@ 2017-04-11 17:28       ` Mason
  0 siblings, 0 replies; 5+ messages in thread
From: Mason @ 2017-04-11 17:28 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Bjorn Helgaas, linux-pci, LKML, Grant Grundler, Greg Hackmann,
	Michael Davidson

On 11/04/2017 19:23, Matthias Kaehlcke wrote:

> El Tue, Apr 11, 2017 at 12:08:38PM +0200 Mason ha dit:
> 
>> On 11/04/2017 03:24, Bjorn Helgaas wrote:
>>
>>> On Mon, Apr 10, 2017 at 03:24:57PM -0700, Matthias Kaehlcke wrote:
>>>
>>>> This fixes a clang warning about "implicit conversion from 'unsigned
>>>> long' to 'u32'"
>>>>
>>>> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
>>>> ---
>>>>  drivers/pci/probe.c | 2 +-
>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
>>>> index dfc9a2794141..148e80d5caf1 100644
>>>> --- a/drivers/pci/probe.c
>>>> +++ b/drivers/pci/probe.c
>>>> @@ -180,7 +180,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
>>>>  	u16 orig_cmd;
>>>>  	struct pci_bus_region region, inverted_region;
>>>>  
>>>> -	mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
>>>> +	mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
>>>
>>> Can we put the cast in the PCI_ROM_ADDRESS_MASK #define so we don't have to
>>> repeat it in all the uses?
>>
>> Fixing these "implicit conversion" warnings, especially for
>> unsigned types, is a slippery slope. (The behavior of the
>> conversion is well-defined.)
>>
>> How about changing the type of PCI_ROM_ADDRESS_MASK instead?
>> It's defined as ~0x7ffUL but it's only used in the context
>> of u32.
>>
>> So make it an unsigned int:
>> #define PCI_ROM_ADDRESS_MASK (~0x7ffU)
>>
>> AFAIU, unsigned int is 32 bits on all platforms supported
>> by Linux.
> 
> I considered this initially, but wasn't sure if the unsigned long
> mask might be needed in some cases. From the comments I interpret that
> there should be no problems with using a 32 bit mask everywhere.
> 
> I'll send out an updated patch shortly.

Full disclaimer: I'm just a grunt with no knowledge of
the PCI framework. Bjorn is the authority here ;-)

Regards.

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

end of thread, other threads:[~2017-04-11 17:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-10 22:24 [PATCH] PCI: Add cast when assigning PCI_ROM_ADDRESS_MASK to a 32-bit variable Matthias Kaehlcke
2017-04-11  1:24 ` Bjorn Helgaas
2017-04-11 10:08   ` Mason
2017-04-11 17:23     ` Matthias Kaehlcke
2017-04-11 17:28       ` Mason

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox