Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1284649

[PATCH] qeth: don't rely on signedness of char

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod
From Rasmus Villemoes <linux@rasmusvillemoes.dk>
Newsgroups linux.kernel
Subject [PATCH] qeth: don't rely on signedness of char
Date Sat, 05 Dec 2015 22:40:02 +0100
Message-ID <qCsIG-6mL-1@gated-at.bofh.it> (permalink)
X-Original-To Ursula Braun <ursula.braun@de.ibm.com>, Martin Schwidefsky <schwidefsky@de.ibm.com>, Heiko Carstens <heiko.carstens@de.ibm.com>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id; bh=UX/t2J7RtrGssxOJjttTLyNkatLFNMEzPZtJy1kETT4=; b=F3sH73nNfvPpongbFHvxFXAbnn5sijuf6z5PFRAJJ7MvrXJpxlWoEXpQD0gUcYuJC8 7B38bZCmcRLchZhtF0bhtdcIx+cEDaHR12WLc7aI2/PL3BzY/+O6zAO0I0ZtlQCPBW6j L/233SyXofop6kTxlVThGl6VMFT1XB39uT9Ew=
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=UX/t2J7RtrGssxOJjttTLyNkatLFNMEzPZtJy1kETT4=; b=d1jcYe+OdFqt5AVIC9M9k8uyV6l8rO2kzrPgWOVvg7n1UhcH7rwTxYARcxtVj7CBq0 RqI7uHbSZ5o880PxShoiRjAeHNKy99lrkg63F436NVVjD/J6mLaqKrt72VDIMJI2pH4L nDgvcKgxt4omKGfwty/1oYxLlwTh4Md6m5mNf0f632dHRmv/0B8avOzgdeqozphU/1bR 8kFTYs1NktrUJyTwWbMhvMh9MUyjcma4pc2hPfb+qdMD/HqmVAmYPQP29dGbUH85jVLV JlVLtKprO0RgS4x+Rh67laXfpVyuHpJzAa4UNtXMohLrQRt3WRIvjQ3rp+ued060qgup RXCA==
X-Gm-Message-State ALoCoQkBEj2xvYf5gQSd3ku/PTbdSq5EDI7myZ9DscYC1MZkX2TmHW/dIRXNq9+uTNXWyXyZzKHS
X-Received by 10.25.161.78 with SMTP id k75mr9198720lfe.31.1449351193449; Sat, 05 Dec 2015 13:33:13 -0800 (PST)
X-Mailer git-send-email 2.6.1
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 41
Organization linux.* mail to news gateway
X-Original-Cc Rasmus Villemoes <linux@rasmusvillemoes.dk>, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org
X-Original-Date Sat, 5 Dec 2015 22:32:52 +0100
X-Original-Message-ID <1449351173-6915-1-git-send-email-linux@rasmusvillemoes.dk>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1284649

Show key headers only | View 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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] qeth: don't rely on signedness of char Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-12-05 22:40 +0100
  Re: [PATCH] qeth: don't rely on signedness of char Ursula Braun <ubraun@linux.vnet.ibm.com> - 2015-12-07 13:10 +0100
    Re: [PATCH] qeth: don't rely on signedness of char Heiko Carstens <heiko.carstens@de.ibm.com> - 2015-12-07 14:50 +0100
      Re: [PATCH] qeth: don't rely on signedness of char Heiko Carstens <heiko.carstens@de.ibm.com> - 2015-12-07 15:00 +0100

csiph-web