2006-08-26 02:01:25

by Adrian Bunk

[permalink] [raw]
Subject: drivers/char/synclink_gt.c: chars don't have more than 8 bits

The GNU C compiler (SVN version) spotted the following buggy code in
drivers/char/synclink_gt.c:

<-- snip -->

...
static void rx_async(struct slgt_info *info)
{
...
unsigned char *p;
unsigned char status;
...
if ((status = *(p+1) & (BIT9 + BIT8))) {
if (status & BIT9)
icount->parity++;
else if (status & BIT8)
icount->frame++;
/* discard char if tty control flags say so */
if (status & info->ignore_status_mask)
continue;
if (status & BIT9)
stat = TTY_PARITY;
else if (status & BIT8)
stat = TTY_FRAME;
}
...

<-- snip -->

Since there are no bits 8 or 9 in a char this code is currently
dead code.

cu
Adrian

--

Gentoo kernels are 42 times more popular than SUSE kernels among
KLive users (a service by SUSE contractor Andrea Arcangeli that
gathers data about kernels from many users worldwide).

There are three kinds of lies: Lies, Damn Lies, and Statistics.
Benjamin Disraeli


2006-08-26 02:51:31

by Paul Fulghum

[permalink] [raw]
Subject: Re: drivers/char/synclink_gt.c: chars don't have more than 8 bits

Adrian Bunk wrote:
> The GNU C compiler (SVN version) spotted the following buggy code in
> drivers/char/synclink_gt.c:
> ...
> Since there are no bits 8 or 9 in a char this code is currently
> dead code.

Yes, that is a bug.

Status and data come in byte pairs, bits 9 and 8 are
referenced from the 16 bit combination.

The code is operating on individual bytes in the buffer,
so it should be bits 1 and 0 that are tested.

I will make a patch and post it.

Thanks,
Paul


2006-08-28 19:09:28

by Paul Fulghum

[permalink] [raw]
Subject: [PATCH] synclink_gt fix receive tty error handling

Fix receive tty error handling in synclink_gt driver.
Adrian reported compiler warning for incorrect bit test
against char variable. I determined these and other
device specific error bits were incorrectly defined.

Signed-off-by: Paul Fulghum <[email protected]>

--- linux-2.6.18-rc5/drivers/char/synclink_gt.c 2006-08-28 08:39:18.000000000 -0500
+++ b/drivers/char/synclink_gt.c 2006-08-28 10:38:49.000000000 -0500
@@ -391,8 +391,8 @@ static MGSL_PARAMS default_params = {
#define DESC_LIST_SIZE 4096

#define MASK_PARITY BIT1
-#define MASK_FRAMING BIT2
-#define MASK_BREAK BIT3
+#define MASK_FRAMING BIT0
+#define MASK_BREAK BIT14
#define MASK_OVERRUN BIT4

#define GSR 0x00 /* global status */
@@ -1800,17 +1800,17 @@ static void rx_async(struct slgt_info *i

stat = 0;

- if ((status = *(p+1) & (BIT9 + BIT8))) {
- if (status & BIT9)
+ if ((status = *(p+1) & (BIT1 + BIT0))) {
+ if (status & BIT1)
icount->parity++;
- else if (status & BIT8)
+ else if (status & BIT0)
icount->frame++;
/* discard char if tty control flags say so */
if (status & info->ignore_status_mask)
continue;
- if (status & BIT9)
+ if (status & BIT1)
stat = TTY_PARITY;
- else if (status & BIT8)
+ else if (status & BIT0)
stat = TTY_FRAME;
}
if (tty) {