All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] qeth: don't rely on signedness of char
@ 2015-12-05 21:32 Rasmus Villemoes
  2015-12-07 12:02 ` Ursula Braun
  0 siblings, 1 reply; 4+ messages in thread
From: Rasmus Villemoes @ 2015-12-05 21:32 UTC (permalink / raw)
  To: Ursula Braun, Martin Schwidefsky, Heiko Carstens
  Cc: Rasmus Villemoes, linux-s390, linux-kernel

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] qeth: don't rely on signedness of char
  2015-12-05 21:32 [PATCH] qeth: don't rely on signedness of char Rasmus Villemoes
@ 2015-12-07 12:02 ` Ursula Braun
  2015-12-07 13:47   ` Heiko Carstens
  0 siblings, 1 reply; 4+ messages in thread
From: Ursula Braun @ 2015-12-07 12:02 UTC (permalink / raw)
  To: Rasmus Villemoes
  Cc: Ursula Braun, Martin Schwidefsky, Heiko Carstens, linux-s390,
	linux-kernel

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 <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 */



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] qeth: don't rely on signedness of char
  2015-12-07 12:02 ` Ursula Braun
@ 2015-12-07 13:47   ` Heiko Carstens
  2015-12-07 13:54     ` Heiko Carstens
  0 siblings, 1 reply; 4+ messages in thread
From: Heiko Carstens @ 2015-12-07 13:47 UTC (permalink / raw)
  To: Ursula Braun
  Cc: Rasmus Villemoes, Ursula Braun, Martin Schwidefsky, linux-s390,
	linux-kernel

On Mon, Dec 07, 2015 at 01:02:35PM +0100, Ursula Braun wrote:
> 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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] qeth: don't rely on signedness of char
  2015-12-07 13:47   ` Heiko Carstens
@ 2015-12-07 13:54     ` Heiko Carstens
  0 siblings, 0 replies; 4+ messages in thread
From: Heiko Carstens @ 2015-12-07 13:54 UTC (permalink / raw)
  To: Ursula Braun, Rasmus Villemoes, Ursula Braun, Martin Schwidefsky,
	linux-s390, linux-kernel

On Mon, Dec 07, 2015 at 02:47:44PM +0100, Heiko Carstens wrote:
> On Mon, Dec 07, 2015 at 01:02:35PM +0100, Ursula Braun wrote:
> > 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:

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-12-07 13:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-05 21:32 [PATCH] qeth: don't rely on signedness of char Rasmus Villemoes
2015-12-07 12:02 ` Ursula Braun
2015-12-07 13:47   ` Heiko Carstens
2015-12-07 13:54     ` Heiko Carstens

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.