Skip to contentSkip to conversation

PCI / PM: enforce type casting for pci_power_t

PATCH Applied Andy Shevchenko 3 participants 6 messages Jun 7, 2016 – Jun 13, 2016 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI / PM: enforce type casting for pci_power_t

When cast pci_power_t type of variables a static analizer tool complains on that.

include/linux/pci.h:119:37: warning: cast from restricted pci_power_t

Enforce type casting to make static analizer happy.

---
 include/linux/pci.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/pci.h +1 -1
index b67e4df..8d74834 100644
@@ -116,7 +116,7 @@ extern const char *pci_power_names[];
 
 static inline const char *pci_power_name(pci_power_t state)
 {
-	return pci_power_names[1 + (int) state];
+	return pci_power_names[1 + (__force int) state];
 }
 
 #define PCI_PM_D2_DELAY		200
Signature · 1 line
2.8.1
#1 lore raw
Quoted 8 lines · Andy Shevchenko

When cast pci_power_t type of variables a static analizer tool complains on that.

include/linux/pci.h:119:37: warning: cast from restricted pci_power_t

Enforce type casting to make static analizer happy.

ACK

Quoted 18 lines
---
 include/linux/pci.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/pci.h +1 -1
index b67e4df..8d74834 100644
@@ -116,7 +116,7 @@ extern const char *pci_power_names[];
 
 static inline const char *pci_power_name(pci_power_t state)
 {
-	return pci_power_names[1 + (int) state];
+	return pci_power_names[1 + (__force int) state];
 }
 
 #define PCI_PM_D2_DELAY		200
#2 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko

When cast pci_power_t type of variables a static analizer tool complains on that.

include/linux/pci.h:119:37: warning: cast from restricted pci_power_t

Enforce type casting to make static analizer happy.

Applied to pci/pm for v4.8, thanks, Andy.

Quoted 24 lines
---
 include/linux/pci.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/pci.h +1 -1
index b67e4df..8d74834 100644
@@ -116,7 +116,7 @@ extern const char *pci_power_names[];
 
 static inline const char *pci_power_name(pci_power_t state)
 {
-	return pci_power_names[1 + (int) state];
+	return pci_power_names[1 + (__force int) state];
 }
 
 #define PCI_PM_D2_DELAY		200
Signature · 6 lines
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
Quoted 5 lines · Bjorn Helgaas
Quoted 4 lines · Andy Shevchenko

When cast pci_power_t type of variables a static analizer tool complains on
that.

Quoted 8 lines
Quoted 6 lines

include/linux/pci.h:119:37: warning: cast from restricted
pci_power_t

Enforce type casting to make static analizer happy.

Applied to pci/pm for v4.8, thanks, Andy.

Thanks.

By the way, what was the main point to use __bitwise annotation to this type in the first place?

Quoted 26 lines
Quoted 26 lines

---
 include/linux/pci.h | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/pci.h +0 -0
index b67e4df..8d74834 100644
@@ -116,7 +116,7 @@ extern const char *pci_power_names[];


 static inline const char *pci_power_name(pci_power_t state) {

include/linux/pci.h +1 -1
-	return pci_power_names[1 + (int) state];
+	return pci_power_names[1 + (__force int) state];

 }

 #define PCI_PM_D2_DELAY 200
--
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#4 lore raw
Quoted 11 lines · Andy Shevchenko
Quoted 10 lines · Bjorn Helgaas
Quoted 9 lines · Andy Shevchenko

When cast pci_power_t type of variables a static analizer tool complains on
that.

include/linux/pci.h:119:37: warning: cast from restricted
pci_power_t

Enforce type casting to make static analizer happy.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Applied to pci/pm for v4.8, thanks, Andy.

Thanks.

By the way, what was the main point to use __bitwise annotation to this type in the first place?

I don't know. It looks like pci_power_t was the first use of __bitwise in pci.h, added by e8191db240d2 ("[PATCH] PCI: Cleanup PCI power states"). That changelog mentions type-safety, but I must admit that doesn't make it obvious to me.

Bjorn

#5 lore raw
Quoted 24 lines · Bjorn Helgaas
Quoted 15 lines · Andy Shevchenko
Quoted 14 lines · Bjorn Helgaas
Quoted 12 lines · Andy Shevchenko

When cast pci_power_t type of variables a static analizer tool complains on
that.

	include/linux/pci.h:119:37: warning: cast from

restricted
pci_power_t

Enforce type casting to make static analizer happy.

m>

Quoted 7 lines
Quoted 1 line

Applied to pci/pm for v4.8, thanks, Andy.

Thanks.

By the way, what was the main point to use __bitwise annotation to this
type in the first place?

Quoted 7 lines

I don't know.  It looks like pci_power_t was the first use of __bitwise in
pci.h, added by e8191db240d2 ("[PATCH] PCI: Cleanup PCI power states").
That changelog mentions type-safety, but I must admit that doesn't make it
obvious to me.

I'm asking since any code which is using this type (all direct assignments or comparisons) brings a static analyzer complain. You may check by yourself with (my usual command to build kernel)

% make C=1 CF=-D__CHECK_ENDIAN__ W=1 -j64

--
Andy Shevchenko <[email protected]> Intel Finland Oy