The definition of pci_channel_io_normal and friends is relatively
complicated and ugly:
typedef unsigned int __bitwise pci_channel_state_t;
enum pci_channel_state {
pci_channel_io_normal = (__force pci_channel_state_t) 1,
...
};
This is clearly motivated by a desire to have some strong typing
for this constants but:
* in C enums are weakly typed (they're essentially the same as 'int')
* sparse only allow to define bitwise ints, not bitwise enums.
This series is a preparation step to introduce bitwise enums.
This would allow to define these constant without having to use
the force cast:
enum __bitwise pci_channel_state {
pci_channel_io_normal = 1,
...
};
or, equivalently:
typedef enum __bitwise {
pci_channel_io_normal = 1,
...
} pci_channel_state_t;
Note: the first patch is, I think, uncontroversial, the other ones
less so but can be safely dropped.
Changes since v1:
* add missing conversion
* try to avoid using 'enum pci_channel_state' in include/linux/pci.h
* try to avoid using 'enum pci_channel_state' in the documentation
Luc Van Oostenryck (3):
pci: use 'pci_channel_state_t' instead of 'enum pci_channel_state'
pci: use anonymous 'enum' instead of 'enum pci_channel_state'
pci: update to doc to use 'pci_channel_state_t'
Documentation/PCI/pci-error-recovery.rst | 8 ++++----
arch/powerpc/kernel/eeh_driver.c | 2 +-
drivers/block/rsxx/core.c | 2 +-
drivers/dma/ioat/init.c | 2 +-
drivers/media/pci/ngene/ngene-cards.c | 2 +-
drivers/misc/genwqe/card_base.c | 2 +-
drivers/net/ethernet/intel/i40e/i40e_main.c | 2 +-
drivers/net/ethernet/intel/ice/ice_main.c | 2 +-
drivers/net/ethernet/intel/ixgb/ixgb_main.c | 4 ++--
drivers/net/ethernet/sfc/efx.c | 2 +-
drivers/net/ethernet/sfc/falcon/efx.c | 2 +-
drivers/pci/pci.h | 2 +-
drivers/pci/pcie/err.c | 4 ++--
drivers/pci/pcie/portdrv_pci.c | 2 +-
drivers/scsi/aacraid/linit.c | 2 +-
drivers/scsi/sym53c8xx_2/sym_glue.c | 2 +-
drivers/staging/qlge/qlge_main.c | 2 +-
include/linux/pci.h | 4 ++--
18 files changed, 24 insertions(+), 24 deletions(-)
--
2.27.0
For typechecking reasons, the typedef 'pci_channel_state_t'
should be used instead of the 'enum pci_channel_state'.
One simple way to enforce this is to remove the definition of
'enum pci_channel_state' and replace it by an anonymous 'enum'.
Signed-off-by: Luc Van Oostenryck <[email protected]>
---
include/linux/pci.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 7ee85e89e8ed..adcee9e30bfa 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -179,7 +179,7 @@ static inline const char *pci_power_name(pci_power_t state)
*/
typedef unsigned int __bitwise pci_channel_state_t;
-enum pci_channel_state {
+enum {
/* I/O channel is in normal state */
pci_channel_io_normal = (__force pci_channel_state_t) 1,
--
2.27.0
On Thu, Jul 02, 2020 at 06:26:48PM +0200, Luc Van Oostenryck wrote:
> The definition of pci_channel_io_normal and friends is relatively
> complicated and ugly:
> typedef unsigned int __bitwise pci_channel_state_t;
> enum pci_channel_state {
> pci_channel_io_normal = (__force pci_channel_state_t) 1,
> ...
> };
>
> This is clearly motivated by a desire to have some strong typing
> for this constants but:
> * in C enums are weakly typed (they're essentially the same as 'int')
> * sparse only allow to define bitwise ints, not bitwise enums.
>
> This series is a preparation step to introduce bitwise enums.
> This would allow to define these constant without having to use
> the force cast:
> enum __bitwise pci_channel_state {
> pci_channel_io_normal = 1,
> ...
> };
> or, equivalently:
> typedef enum __bitwise {
> pci_channel_io_normal = 1,
> ...
> } pci_channel_state_t;
>
>
> Note: the first patch is, I think, uncontroversial, the other ones
> less so but can be safely dropped.
>
>
> Changes since v1:
> * add missing conversion
> * try to avoid using 'enum pci_channel_state' in include/linux/pci.h
> * try to avoid using 'enum pci_channel_state' in the documentation
>
>
> Luc Van Oostenryck (3):
> pci: use 'pci_channel_state_t' instead of 'enum pci_channel_state'
> pci: use anonymous 'enum' instead of 'enum pci_channel_state'
> pci: update to doc to use 'pci_channel_state_t'
>
> Documentation/PCI/pci-error-recovery.rst | 8 ++++----
> arch/powerpc/kernel/eeh_driver.c | 2 +-
> drivers/block/rsxx/core.c | 2 +-
> drivers/dma/ioat/init.c | 2 +-
> drivers/media/pci/ngene/ngene-cards.c | 2 +-
> drivers/misc/genwqe/card_base.c | 2 +-
> drivers/net/ethernet/intel/i40e/i40e_main.c | 2 +-
> drivers/net/ethernet/intel/ice/ice_main.c | 2 +-
> drivers/net/ethernet/intel/ixgb/ixgb_main.c | 4 ++--
> drivers/net/ethernet/sfc/efx.c | 2 +-
> drivers/net/ethernet/sfc/falcon/efx.c | 2 +-
> drivers/pci/pci.h | 2 +-
> drivers/pci/pcie/err.c | 4 ++--
> drivers/pci/pcie/portdrv_pci.c | 2 +-
> drivers/scsi/aacraid/linit.c | 2 +-
> drivers/scsi/sym53c8xx_2/sym_glue.c | 2 +-
> drivers/staging/qlge/qlge_main.c | 2 +-
> include/linux/pci.h | 4 ++--
> 18 files changed, 24 insertions(+), 24 deletions(-)
Since it's all basically "use pci_channel_state_t instead of enum
pci_channel_state", I squashed these all together and applied the
result to pci/error for v5.8, thanks!