scsi: bfa: Avoid implicit enum conversion in bfad_im_post_vendor_event
Subsystems (2)
PATCH 1/1 scsi: bfa: Avoid implicit enum conversion in bfad_im_post_vendor_event
Clang warns when one enumerated type is implicitly converted to another.
drivers/scsi/bfa/bfa_fcs_lport.c:379:26: warning: implicit conversion from enumeration type 'enum bfa_lport_aen_event' to different enumeration type 'enum bfa_ioc_aen_event' [-Wenum-conversion]
BFA_AEN_CAT_LPORT, event);
^~~~~The root cause of these warnings is the bfad_im_post_vendor_event function, which expects a value from enum bfa_ioc_aen_event but there are multiple instances of values from enums bfa_port_aen_event, bfa_audit_aen_event, and bfa_lport_aen_event being used in this function.
Given that this doesn't appear to be a problem since cat helps with differentiating the events, just change evt's type to int so that no conversion needs to happen and Clang won't warn.
---
The alternate way of fixing these warnings is to explicitly cast the conversion when calling the function but since there are about 8-10 of these warnings, it seems logical to just change the function definiton which is cleaner in my opinion.
See commits 3eb95feac113 ("mm/zsmalloc.c: change stat type parameter to int") and 04fecbf51b3c ("mm: memcontrol: use int for event/state parameter in several functions") for similar fixes.
drivers/scsi/bfa/bfad_im.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/bfa/bfad_im.h +1 -1
@@ -143,7 +143,7 @@ struct bfad_im_s {static inline void bfad_im_post_vendor_event (struct bfa_aen_entry_s *entry,struct bfad_s *drv,int cnt,enum bfa_aen_category cat, -enum bfa_ioc_aen_event evt) +int evt) {struct timespec64 ts;
Signature · 1 line
2.19.0
Quoted 6 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/scsi/bfa/bfa_fcs_lport.c:379:26: warning: implicit conversion from enumeration type 'enumbfa_lport_aen_event' to different enumeration type 'enumbfa_ioc_aen_event' [-Wenum-conversion]
Quoted 8 lines
BFA_AEN_CAT_LPORT, event); ^~~~~The root cause of these warnings is the
bfad_im_post_vendor_eventfunction, which expects a value from enumbfa_ioc_aen_eventbut there are multiple instances of values from enumsbfa_port_aen_event,bfa_audit_aen_event, andbfa_lport_aen_eventbeing used in this function.
Indeed, it seems that bfad_im_post_vendor_event() assigns this parameter to
161 entry->aen_type = evt;
which is defined as:
1456 u32 aen_type;
so already we know that aen_type is meant to be a grab bag of enum values. bfad_im_post_vendor_event() is already passed many different types of enums, as you mention. Does changing aen_type to an int produce further warnings, because it would be nice to have that change in this one, too. AFAICT, it's only ever saved away in a containing struct.
Quoted 37 lines
Given that this doesn't appear to be a problem since cat helps with differentiating the events, just change evt's type to int so that no conversion needs to happen and Clang won't warn.
Signed-off-by Nathan Chancellor <[email protected]>---
The alternate way of fixing these warnings is to explicitly cast the conversion when calling the function but since there are about 8-10 of these warnings, it seems logical to just change the function definiton which is cleaner in my opinion.
See commits
3eb95feac113("mm/zsmalloc.c: change stat type parameter to int") and04fecbf51b3c("mm: memcontrol: use int for event/state parameter in several functions") for similar fixes.drivers/scsi/bfa/bfad_im.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/scsi/bfa/bfad_im.h +1
-2@@ -143,7 +143,7 @@ struct bfad_im_s {static inline void bfad_im_post_vendor_event (struct bfa_aen_entry_s *entry,struct bfad_s *drv,int cnt,enum bfa_aen_category cat, -enum bfa_ioc_aen_event evt) +int evt) {struct timespec64 ts; --2.19.0
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 22 lines · Nick Desaulniers
Quoted 6 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/scsi/bfa/bfa_fcs_lport.c:379:26: warning: implicit conversion from enumeration type 'enumbfa_lport_aen_event' to different enumeration type 'enumbfa_ioc_aen_event' [-Wenum-conversion]Quoted 8 lines
BFA_AEN_CAT_LPORT, event); ^~~~~The root cause of these warnings is the
bfad_im_post_vendor_eventfunction, which expects a value from enumbfa_ioc_aen_eventbut there are multiple instances of values from enumsbfa_port_aen_event,bfa_audit_aen_event, andbfa_lport_aen_eventbeing used in this function.Indeed, it seems that
bfad_im_post_vendor_event()assigns this parameter to
161entry->aen_type= evt;which is defined as:
Quoted 9 lines
1456 u32
aen_type;so already we know that
aen_typeis meant to be a grab bag of enum values.bfad_im_post_vendor_event()is already passed many different types of enums, as you mention. Does changingaen_typeto anintproduce further warnings, because it would be nice to have that change in this one, too. AFAICT, it's only ever saved away in a containing struct.
No, it doesn't introduce any new warnings. I can send that as a v2 here shortly.
Nathan
Quoted 42 lines
Quoted 37 lines
Given that this doesn't appear to be a problem since cat helps with differentiating the events, just change evt's type to int so that no conversion needs to happen and Clang won't warn.
Signed-off-by Nathan Chancellor <[email protected]>---
The alternate way of fixing these warnings is to explicitly cast the conversion when calling the function but since there are about 8-10 of these warnings, it seems logical to just change the function definiton which is cleaner in my opinion.
See commits
3eb95feac113("mm/zsmalloc.c: change stat type parameter to int") and04fecbf51b3c("mm: memcontrol: use int for event/state parameter in several functions") for similar fixes.drivers/scsi/bfa/bfad_im.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/scsi/bfa/bfad_im.h +1
-2@@ -143,7 +143,7 @@ struct bfad_im_s {static inline void bfad_im_post_vendor_event (struct bfa_aen_entry_s *entry,struct bfad_s *drv,int cnt,enum bfa_aen_category cat, -enum bfa_ioc_aen_event evt) +int evt) {struct timespec64 ts; --2.19.0
Signature · 2 lines
Thanks, ~Nick Desaulniers
PATCH v2 1/1 scsi: bfa: Avoid implicit enum conversion in bfad_im_post_vendor_event
In reply to Nathan ChancellorClang warns when one enumerated type is implicitly converted to another.
drivers/scsi/bfa/bfa_fcs_lport.c:379:26: warning: implicit conversion from enumeration type 'enum bfa_lport_aen_event' to different enumeration type 'enum bfa_ioc_aen_event' [-Wenum-conversion]
BFA_AEN_CAT_LPORT, event);
^~~~~The root cause of these warnings is the bfad_im_post_vendor_event function, which expects a value from enum bfa_ioc_aen_event but there are multiple instances of values from enums bfa_port_aen_event, bfa_audit_aen_event, and bfa_lport_aen_event being used in this function.
Given that this doesn't appear to be a problem since cat helps with differentiating the events, just change evt's type to int so that no conversion needs to happen and Clang won't warn. Update aen_type's type in bfa_aen_entry_s as members that hold enumerated types should be int.
---
v1 -> v2:
* Update aen_type's type in bfa_aen_entry_s to match evt
drivers/scsi/bfa/bfa_defs_svc.h | 2 +- drivers/scsi/bfa/bfad_im.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/bfa/bfa_defs_svc.h +1 -1
@@ -1453,7 +1453,7 @@ union bfa_aen_data_u {struct bfa_aen_entry_s {struct list_head qe;enum bfa_aen_category aen_category; -u32 aen_type; +int aen_type;union bfa_aen_data_u aen_data;u64 aen_tv_sec;u64 aen_tv_usec;
drivers/scsi/bfa/bfad_im.h +1 -1
@@ -143,7 +143,7 @@ struct bfad_im_s {static inline void bfad_im_post_vendor_event (struct bfa_aen_entry_s *entry,struct bfad_s *drv,int cnt,enum bfa_aen_category cat, -enum bfa_ioc_aen_event evt) +int evt) {struct timespec64 ts;
Signature · 1 line
2.19.0
Quoted 20 lines · Nathan Chancellor
Clang warns when one enumerated type is implicitly converted to another.
drivers/scsi/bfa/bfa_fcs_lport.c:379:26: warning: implicit conversion from enumeration type 'enumbfa_lport_aen_event' to different enumeration type 'enumbfa_ioc_aen_event' [-Wenum-conversion]BFA_AEN_CAT_LPORT, event); ^~~~~The root cause of these warnings is the
bfad_im_post_vendor_eventfunction, which expects a value from enumbfa_ioc_aen_eventbut there are multiple instances of values from enumsbfa_port_aen_event,bfa_audit_aen_event, andbfa_lport_aen_eventbeing used in this function.Given that this doesn't appear to be a problem since cat helps with differentiating the events, just change evt's type to int so that no conversion needs to happen and Clang won't warn. Update aen_type's type in
bfa_aen_entry_sas members that hold enumerated types should be int.
Quoted 7 lines
Signed-off-by Nathan Chancellor <[email protected]>---
v1 -> v2:
* Update aen_type's type in
bfa_aen_entry_sto match evt
Thanks for respinning with this addition.
Quoted 34 lines
drivers/scsi/bfa/bfa_defs_svc.h | 2 +- drivers/scsi/bfa/bfad_im.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/scsi/bfa/bfa_defs_svc.h +1
-1@@ -1453,7 +1453,7 @@ union bfa_aen_data_u {struct bfa_aen_entry_s {struct list_head qe;enum bfa_aen_category aen_category; -u32 aen_type; +int aen_type;union bfa_aen_data_u aen_data;u64 aen_tv_sec;u64 aen_tv_usec;drivers/scsi/bfa/bfad_im.h +1
-2@@ -143,7 +143,7 @@ struct bfad_im_s {static inline void bfad_im_post_vendor_event (struct bfa_aen_entry_s *entry,struct bfad_s *drv,int cnt,enum bfa_aen_category cat, -enum bfa_ioc_aen_event evt) +int evt) {struct timespec64 ts; --2.19.0
Signature · 2 lines
Thanks, ~Nick Desaulniers
Martin K. Petersen
AppliedNathan,
Quoted 7 lines
Clang warns when one enumerated type is implicitly converted to another.
drivers/scsi/bfa/bfa_fcs_lport.c:379:26: warning: implicit conversion from enumeration type 'enumbfa_lport_aen_event' to different enumeration type 'enumbfa_ioc_aen_event' [-Wenum-conversion]BFA_AEN_CAT_LPORT, event); ^~~~~
Applied to 4.20/scsi-queue.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering