[PATCH] char/moxa.c: fix endianess and multiple-card issues

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>

authored by Dirk Eibach and committed by Linus Torvalds 01cfaf0d a0cc621f

+6 -2
+6 -2
drivers/char/moxa.c
··· 142 143 static moxa_board_conf moxa_boards[MAX_BOARDS]; 144 static void __iomem *moxaBaseAddr[MAX_BOARDS]; 145 146 struct moxa_str { 147 int type; ··· 1689 if (moxaCard == 0) 1690 return (-1); 1691 for (card = 0; card < MAX_BOARDS; card++) { 1692 if ((ports = moxa_boards[card].numPorts) == 0) 1693 continue; 1694 if (readb(moxaIntPend[card]) == 0xff) { ··· 2906 } 2907 break; 2908 } 2909 return (0); 2910 } 2911 ··· 2924 len1 = len >> 1; 2925 ptr = (ushort *) moxaBuff; 2926 for (i = 0; i < len1; i++) 2927 - usum += *(ptr + i); 2928 retry = 0; 2929 do { 2930 len1 = len >> 1; ··· 2996 wlen = len >> 1; 2997 uptr = (ushort *) moxaBuff; 2998 for (i = 0; i < wlen; i++) 2999 - usum += uptr[i]; 3000 retry = 0; 3001 j = 0; 3002 do {
··· 142 143 static moxa_board_conf moxa_boards[MAX_BOARDS]; 144 static void __iomem *moxaBaseAddr[MAX_BOARDS]; 145 + static int loadstat[MAX_BOARDS]; 146 147 struct moxa_str { 148 int type; ··· 1688 if (moxaCard == 0) 1689 return (-1); 1690 for (card = 0; card < MAX_BOARDS; card++) { 1691 + if (loadstat[card] == 0) 1692 + continue; 1693 if ((ports = moxa_boards[card].numPorts) == 0) 1694 continue; 1695 if (readb(moxaIntPend[card]) == 0xff) { ··· 2903 } 2904 break; 2905 } 2906 + loadstat[cardno] = 1; 2907 return (0); 2908 } 2909 ··· 2920 len1 = len >> 1; 2921 ptr = (ushort *) moxaBuff; 2922 for (i = 0; i < len1; i++) 2923 + usum += le16_to_cpu(*(ptr + i)); 2924 retry = 0; 2925 do { 2926 len1 = len >> 1; ··· 2992 wlen = len >> 1; 2993 uptr = (ushort *) moxaBuff; 2994 for (i = 0; i < wlen; i++) 2995 + usum += le16_to_cpu(uptr[i]); 2996 retry = 0; 2997 j = 0; 2998 do {