Skip to contentSkip to conversation

bridge: Fix format string for %ul

PATCH In review Oleg Drokin 3 participants 6 messages Aug 27, 2016 – Oct 3, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bridge: Fix format string for %ul

%ul would print an unsigned value and a letter l, likely it was %lu that was meant to print the long int, but in reality the values printed there are just regular signed ints, so just dropping the l altogether.

---
 net/bridge/br_stp_bpdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_stp_bpdu.c +1 -1
index 5881fbc..15c4a9c 100644
@@ -230,7 +230,7 @@ void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
 			if (net_ratelimit())
 				br_notice(p->br,
 					  "port %u config from %pM"
-					  " (message_age %ul > max_age %ul)\n",
+					  " (message_age %u > max_age %u)\n",
 					  p->port_no,
 					  eth_hdr(skb)->h_source,
 					  bpdu.message_age, bpdu.max_age);
Signature · 1 line
2.7.4
#1 lore raw

Hello.

Quoted 3 lines · Oleg Drokin

%ul would print an unsigned value and a letter l, likely it was %lu that was meant to print the long int, but in reality the values printed there are just regular signed

Signed? Then you need probably "%d" or "%i"...

Quoted 3 lines

ints, so just dropping the l altogether.

[...]

MBR, Sergei

#2 lore raw
Quoted 9 lines · Sergei Shtylyov

Hello.

Quoted 3 lines · Oleg Drokin

%ul would print an unsigned value and a letter l, likely it was %lu that was meant to print the long int, but in reality the values printed there are just regular signed

Signed? Then you need probably "%d" or "%i"…

They are signed in the struct definition, but in reality they designate time, so could not be negative, I imagine?

Quoted 7 lines
Quoted 4 lines

ints, so just dropping the l altogether.

[...]

MBR, Sergei

#3 lore raw

Hello.

Quoted 8 lines · Oleg Drokin
Quoted 5 lines
Quoted 3 lines

%ul would print an unsigned value and a letter l, likely it was %lu that was meant to print the long int, but in reality the values printed there are just regular signed

Signed? Then you need probably "%d" or "%i"…

They are signed in the struct definition, but in reality they designate time, so could not be negative, I imagine?

That doesn't matter. If the type is signed, it should be printed as signed.
Doesn't gcc complain about the format specifiers not matching the values passed?

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

ints, so just dropping the l altogether.

[...]

MBR, Sergei

#4 lore raw
Quoted 8 lines · Sergei Shtylyov

Hello.

Quoted 4 lines · Oleg Drokin
Quoted 4 lines
Quoted 3 lines

%ul would print an unsigned value and a letter l, likely it was %lu that was meant to print the long int, but in reality the values printed there are just regular signed

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Signed? Then you need probably "%d" or "%i"…

They are signed in the struct definition, but in reality they designate time, so could not be negative, I imagine?

That doesn't matter. If the type is signed, it should be printed as signed.
Doesn't gcc complain about the format specifiers not matching the values passed?

only if the size differs.

I don't care either way.
I can change the struct to unsigned too, but if we want super correctness, the problem lies deeper.

E.g. if we look how those times are derived, the age comes as:
static inline int br_get_ticks(const unsigned char *src)

{
        unsigned long ticks = get_unaligned_be16(src);

        return DIV_ROUND_UP(ticks * HZ, STP_HZ);
}

So we divide unsigned value by positive value and get a signed result ;)

there's a struct net_bridge_port with similar members in this are that are unsigned long, so I guess we should convert to unsigned long in the struct br_config_bpdu, do you want a patch for that separately or as part of this one?

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

ints, so just dropping the l altogether.

[...]

MBR, Sergei

#5 lore raw
In reply to Oleg Drokin
Quoted 15 lines · On Fri, 26 Aug 2016 23:10:28 -0400 Oleg Drokin <[email protected]> wrote:

%ul would print an unsigned value and a letter l, likely it was %lu that was meant to print the long int, but in reality the values printed there are just regular signed ints, so just dropping the l altogether.

---
 net/bridge/br_stp_bpdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_stp_bpdu.c +0 -0
index 5881fbc..15c4a9c 100644

net/bridge/br_stp_bpdu.c void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb, · line 236

Quoted 8 lines
net/bridge/br_stp_bpdu.c +1 -1
@@ -230,7 +230,7 @@ void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
 			if (net_ratelimit())
 				br_notice(p->br,
 					  "port %u config from %pM"
-					  " (message_age %ul > max_age %ul)\n",
+					  " (message_age %u > max_age %u)\n",
 					  p->port_no,
 					  eth_hdr(skb)->h_source,
 					  bpdu.message_age, bpdu.max_age);

Could you make the format string a single line plwase. And add Fixes tag.