From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Ursula Braun <ursula.braun@de.ibm.com>,
Martin Schwidefsky <schwidefsky@de.ibm.com>,
Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>,
linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] qeth: don't rely on signedness of char
Date: Sat, 5 Dec 2015 22:32:52 +0100 [thread overview]
Message-ID: <1449351173-6915-1-git-send-email-linux@rasmusvillemoes.dk> (raw)
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.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
drivers/s390/net/qeth_core_main.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index 31ac53fa5cee..84bc4b862fbb 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -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.6.1
next reply other threads:[~2015-12-05 21:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-05 21:32 Rasmus Villemoes [this message]
2015-12-07 12:02 ` [PATCH] qeth: don't rely on signedness of char Ursula Braun
2015-12-07 13:47 ` Heiko Carstens
2015-12-07 13:54 ` Heiko Carstens
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1449351173-6915-1-git-send-email-linux@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=heiko.carstens@de.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=schwidefsky@de.ibm.com \
--cc=ursula.braun@de.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox