Skip to content

Commit

Permalink
[PATCH] char/moxa.c: fix endianess and multiple-card issues
Browse files Browse the repository at this point in the history
While testing Moxa C218T/PCI on PowerPC 405EP I found that loading firmware
using the linux kernel driver fails because calculation of the checksum is
not endianess independent in the original code.

After I fixed this I found that uploading firmware in a system with
multiple cards causes a kernel oops.  I had a look in the recent moxa
sources and found that they do some kind of locking there.  Applying this
lock fixed the problem.

Alan sayeth:

  Checksum changes are clearly correct.  Other changes is an improvement but
  not I think enough to handle malicious firmware attacks.  That said such an
  attacker has CAP_SYS_RAWIO anyway so that part is irrelevant except for
  neatness.

[akpm@osdl.org: cleanups]
Signed-off-by: Dirk Eibach <eibach@gdsys.de>
Acked-by: Alan Cox <alan@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Dirk Eibach authored and Linus Torvalds committed Aug 27, 2006
1 parent a0cc621 commit 01cfaf0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/char/moxa.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ typedef struct _moxa_board_conf {

static moxa_board_conf moxa_boards[MAX_BOARDS];
static void __iomem *moxaBaseAddr[MAX_BOARDS];
static int loadstat[MAX_BOARDS];

struct moxa_str {
int type;
Expand Down Expand Up @@ -1688,6 +1689,8 @@ int MoxaDriverPoll(void)
if (moxaCard == 0)
return (-1);
for (card = 0; card < MAX_BOARDS; card++) {
if (loadstat[card] == 0)
continue;
if ((ports = moxa_boards[card].numPorts) == 0)
continue;
if (readb(moxaIntPend[card]) == 0xff) {
Expand Down Expand Up @@ -2903,6 +2906,7 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len)
}
break;
}
loadstat[cardno] = 1;
return (0);
}

Expand All @@ -2920,7 +2924,7 @@ static int moxaloadc218(int cardno, void __iomem *baseAddr, int len)
len1 = len >> 1;
ptr = (ushort *) moxaBuff;
for (i = 0; i < len1; i++)
usum += *(ptr + i);
usum += le16_to_cpu(*(ptr + i));
retry = 0;
do {
len1 = len >> 1;
Expand Down Expand Up @@ -2992,7 +2996,7 @@ static int moxaloadc320(int cardno, void __iomem *baseAddr, int len, int *numPor
wlen = len >> 1;
uptr = (ushort *) moxaBuff;
for (i = 0; i < wlen; i++)
usum += uptr[i];
usum += le16_to_cpu(uptr[i]);
retry = 0;
j = 0;
do {
Expand Down

0 comments on commit 01cfaf0

Please sign in to comment.