Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754933AbbLGMCt (ORCPT ); Mon, 7 Dec 2015 07:02:49 -0500 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:54613 "EHLO e06smtp13.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754685AbbLGMCr (ORCPT ); Mon, 7 Dec 2015 07:02:47 -0500 X-IBM-Helo: d06dlp01.portsmouth.uk.ibm.com X-IBM-MailFrom: ubraun@linux.vnet.ibm.com X-IBM-RcptTo: linux-kernel@vger.kernel.org;linux-s390@vger.kernel.org Message-ID: <1449489755.18521.7.camel@BR9GV9YG.de.ibm.com> Subject: Re: [PATCH] qeth: don't rely on signedness of char From: Ursula Braun To: Rasmus Villemoes Cc: Ursula Braun , Martin Schwidefsky , Heiko Carstens , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 07 Dec 2015 13:02:35 +0100 In-Reply-To: <1449351173-6915-1-git-send-email-linux@rasmusvillemoes.dk> References: <1449351173-6915-1-git-send-email-linux@rasmusvillemoes.dk> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.2.3-0ubuntu6 Content-Transfer-Encoding: 7bit Mime-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15120712-0013-0000-0000-000007E9BCB7 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1875 Lines: 51 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 On Sat, 2015-12-05 at 22:32 +0100, Rasmus Villemoes wrote: > 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 > --- > 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 */ -- 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/