media: camss: csiphy-3ph: avoid undefined behavior
Subsystems (4)
PATCH 1/1 media: camss: csiphy-3ph: avoid undefined behavior
From: Arnd Bergmann <[email protected]>
Marking a case of the switch statement as unreachable means the compiler treats it as undefined behavior, which is then caught by an objtool warning:
drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.o: warning: objtool: csiphy_lanes_enable() falls through to next function csiphy_lanes_disable()
Instead of simply continuing execution at a random place of the driver, print a warning and return from to the caller, which makes it possible to understand what happens and avoids the warning.
--- drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c +2 -1
@@ -429,7 +429,8 @@ static void csiphy_gen2_config_lanes(struct csiphy_device *csiphy, array_size =ARRAY_SIZE (lane_regs_sm8250[0 ]);break ;default : -unreachable (); +WARN (1 ,"unknown cspi version\n" ); +return ; }for (l =0 ; l <5 ; l++) {
Signature · 1 line
2.35.1
Quoted 35 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Marking a case of the switch statement as unreachable means the compiler treats it as undefined behavior, which is then caught by an objtool warning:
drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.o: warning: objtool:csiphy_lanes_enable()falls through to next functioncsiphy_lanes_disable()Instead of simply continuing execution at a random place of the driver, print a warning and return from to the caller, which makes it possible to understand what happens and avoids the warning.
Fixes 53655d2a0ff2 ("media: camss: csiphy-3ph: add support for SM8250 CSI DPHY")Signed-off-by Arnd Bergmann <[email protected]>--- drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c +2
-2@@ -429,7 +429,8 @@ static void csiphy_gen2_config_lanes(struct csiphy_device *csiphy, array_size =ARRAY_SIZE (lane_regs_sm8250[0 ]);break ;default : -unreachable (); +WARN (1 ,"unknown cspi version\n" ); +return ; }for (l =0 ; l <5 ; l++) { --
Quoted 2 lines
2.35.1
Quoted 24 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Marking a case of the switch statement as unreachable means the compiler treats it as undefined behavior, which is then caught by an objtool warning:
drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.o: warning: objtool:csiphy_lanes_enable()falls through to next functioncsiphy_lanes_disable()Instead of simply continuing execution at a random place of the driver, print a warning and return from to the caller, which makes it possible to understand what happens and avoids the warning.
Fixes 53655d2a0ff2 ("media: camss: csiphy-3ph: add support for SM8250 CSI DPHY")Signed-off-by Arnd Bergmann <[email protected]>--- drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c +0
-0
drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c static void csiphy_gen2_config_lanes(struct csiphy_device *csiphy, · line 434
Quoted 7 lines
drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c +2
-1@@ -429,7 +429,8 @@ static void csiphy_gen2_config_lanes(struct csiphy_device *csiphy, array_size =ARRAY_SIZE (lane_regs_sm8250[0 ]);break ;default : -unreachable (); +WARN (1 ,"unknown cspi version\n" ); +return ; }
So no real objection here; but unreachable() does have an objtool annotation inside, so clearly the compiler managed to defeat that -- perhaps we should look at that too.
Quoted 17 lines · Peter Zijlstra
drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c static void csiphy_gen2_config_lanes(struct csiphy_device *csiphy, · line 434
Quoted 12 lines · Arnd Bergmann
drivers/media/platform/qcom/camss/camss-csiphy-3ph-1-0.c +2
-1@@ -429,7 +429,8 @@ static void csiphy_gen2_config_lanes(struct csiphy_device *csiphy, array_size =ARRAY_SIZE (lane_regs_sm8250[0 ]);break ;default : -unreachable (); +WARN (1 ,"unknown cspi version\n" ); +return ; }So no real objection here; but
unreachable()does have an objtool annotation inside, so clearly the compiler managed to defeat that -- perhaps we should look at that too.
Ah, I forgot this annotation existed. I see that this particular objtool warning only happens with clang (I used version 14.0.6), but it does not happen with gcc-12.2.
I see the function ends in
jmp .LBB3_45
.LBB3_54:
#APP
.Ltmp0:
.section .discard.unreachable,"",@progbits
.Ltmp1:
.long .Ltmp0-.Ltmp1 .text
#NO_APP
.Lfunc_end3:
.size csiphy_lanes_enable, .Lfunc_end3-csiphy_lanes_enable
# -- End function
full assembler output at https://pastebin.com/F8HGCUvk, object file attached.
Arnd