Skip to contentSkip to conversation

ptp: ocp: Avoid operator precedence warning in ptp_ocp_summary_show()

PATCH Superseded Nathan Chancellor 2 participants 2 messages Sep 16, 2021 – Sep 17, 2021

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ptp: ocp: Avoid operator precedence warning in ptp_ocp_summary_show()

Clang warns twice:

drivers/ptp/ptp_ocp.c:2065:16: error: operator '?:' has lower precedence than '&'; '&' will be evaluated first [-Werror,-Wbitwise-conditional-parentheses]

                           on & map ? " ON" : "OFF", src);
                           ~~~~~~~~ ^
drivers/ptp/ptp_ocp.c:2065:16: note: place parentheses around the '&'
expression to silence this warning
                           on & map ? " ON" : "OFF", src);
                                    ^
                           (       )
drivers/ptp/ptp_ocp.c:2065:16: note: place parentheses around the '?:'
expression to evaluate it first
                           on & map ? " ON" : "OFF", src);
                                    ^

It is clearly intentional that the bitwise operation be done before the ternary operation so add the parentheses as it suggests to fix the warning.

Fixes a62a56d04e63 ("ptp: ocp: Enable 4th timestamper / PPS generator")
---
 drivers/ptp/ptp_ocp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/ptp/ptp_ocp.c +2 -2
index 844b1401cc5d..4ba3fb254a92 100644
@@ -2062,11 +2062,11 @@ ptp_ocp_summary_show(struct seq_file *s, void *data)
 		on = ioread32(&ts_reg->enable);
 		map = !!(bp->pps_req_map & OCP_REQ_TIMESTAMP);
 		seq_printf(s, "%7s: %s, src: %s\n", "TS3",
-			   on & map ? " ON" : "OFF", src);
+			   (on & map) ? " ON" : "OFF", src);
 
 		map = !!(bp->pps_req_map & OCP_REQ_PPS);
 		seq_printf(s, "%7s: %s, src: %s\n", "PPS",
-			   on & map ? " ON" : "OFF", src);
+			   (on & map) ? " ON" : "OFF", src);
 	}
 
 	if (bp->irig_out) {

base-commit: 4b5a3ab17c6c942bd428984b6b37fe3c07f18ab3

Signature · 1 line
2.33.0
#1 lore raw
Quoted 17 lines · Nathan Chancellor

Clang warns twice:

drivers/ptp/ptp_ocp.c:2065:16: error: operator '?:' has lower precedence than '&'; '&' will be evaluated first [-Werror,-Wbitwise-conditional-parentheses]

                           on & map ? " ON" : "OFF", src);
                           ~~~~~~~~ ^
drivers/ptp/ptp_ocp.c:2065:16: note: place parentheses around the '&'
expression to silence this warning
                           on & map ? " ON" : "OFF", src);
                                    ^
                           (       )
drivers/ptp/ptp_ocp.c:2065:16: note: place parentheses around the '?:'
expression to evaluate it first
                           on & map ? " ON" : "OFF", src);
                                    ^
Quoted 3 lines

It is clearly intentional that the bitwise operation be done before the ternary operation so add the parentheses as it suggests to fix the warning.

Actually, the correct fix is to change '&' to '&&', so a logical operation is done instead of an arithmetic operation. I believe this will silence the warning from clang.

Signature · 1 line
Jonathan