Skip to contentSkip to conversation

qeth: don't rely on signedness of char

PATCH In review Rasmus Villemoes 3 participants 4 messages Dec 5, 2015 – Dec 7, 2015

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

PATCH 1/1 qeth: don't rely on signedness of char

AFAICT, char is unsigned on s390. Relying on that is a little subtle. The problem here is that if char happens to be signed and e.g. card->info.mcl_level[2] contains the value -16, the formatted output will be "fffffff0", thus overflowing card->info.mcl_level (which has size 5). To help future readers, simply do an explicit mask so that the value passed to sprintf is in 0-255. If char is indeed unsigned, gcc should be able to elide the masking.

In any case, the subsequent 0-termination is redundant, since sprintf has done that.

---
 drivers/s390/net/qeth_core_main.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/s390/net/qeth_core_main.c +2 -4
index 31ac53fa5cee..84bc4b862fbb 100644
@@ -2682,10 +2682,8 @@ void qeth_print_status_message(struct qeth_card *card)
 		 * */
 		if (!card->info.mcl_level[0]) {
 			sprintf(card->info.mcl_level, "%02x%02x",
-				card->info.mcl_level[2],
-				card->info.mcl_level[3]);
-
-			card->info.mcl_level[QETH_MCL_LENGTH] = 0;
+				card->info.mcl_level[2] & 0xff,
+				card->info.mcl_level[3] & 0xff);
 			break;
 		}
 		/* fallthrough */
Signature · 1 line
2.6.1
#1 lore raw

Rasmus,

I do not see a need for your first patch proposal. Our code works fine in our environment.

But I will pickup your second part to remove the explicit setting of the 0-termination. Thanks!

Regards, Ursula

Quoted 33 lines · Rasmus Villemoes

AFAICT, char is unsigned on s390. Relying on that is a little subtle. The problem here is that if char happens to be signed and e.g. card->info.mcl_level[2] contains the value -16, the formatted output will be "fffffff0", thus overflowing card->info.mcl_level (which has size 5). To help future readers, simply do an explicit mask so that the value passed to sprintf is in 0-255. If char is indeed unsigned, gcc should be able to elide the masking.

In any case, the subsequent 0-termination is redundant, since sprintf has done that.

---
 drivers/s390/net/qeth_core_main.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/s390/net/qeth_core_main.c +2 -4
index 31ac53fa5cee..84bc4b862fbb 100644
@@ -2682,10 +2682,8 @@ void qeth_print_status_message(struct qeth_card *card)
 		 * */
 		if (!card->info.mcl_level[0]) {
 			sprintf(card->info.mcl_level, "%02x%02x",
-				card->info.mcl_level[2],
-				card->info.mcl_level[3]);
-
-			card->info.mcl_level[QETH_MCL_LENGTH] = 0;
+				card->info.mcl_level[2] & 0xff,
+				card->info.mcl_level[3] & 0xff);
 			break;
 		}
 		/* fallthrough */
#2 lore raw
Quoted 9 lines · Ursula Braun

Rasmus,

I do not see a need for your first patch proposal. Our code works fine in our environment.

But I will pickup your second part to remove the explicit setting of the 0-termination. Thanks!

Regards, Ursula

Hi Uschi,

das untenstehende habe ich schon diverse male geschrieben, um zu verhindern, dass "wir" uns mit einfach vermeidbaren Dingen auf externen Mailinglisten unbeliebt machen:

Just a general comment and unrelated to this patch. Please, when replying:

- don't top-post
- use interleaved style with an empty line after each quoted block
- trim your replies to only the relevant parts

See also: https://en.wikipedia.org/wiki/Posting_style

This should make your and everybody else's life easier when your are participating on external mailing lists.

#3 lore raw
Quoted 9 lines · Heiko Carstens
Quoted 8 lines · Ursula Braun

Rasmus,

I do not see a need for your first patch proposal. Our code works fine in our environment.

But I will pickup your second part to remove the explicit setting of the 0-termination. Thanks!

Quoted 7 lines
Quoted 1 line

Regards, Ursula

Hi Uschi,

das untenstehende habe ich schon diverse male geschrieben, um zu verhindern, dass "wir" uns mit einfach vermeidbaren Dingen auf externen Mailinglisten unbeliebt machen:

Ooops, this was not supposed to go to everybody... ;)