aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Ritz <daniel.ritz-ml@swissonline.ch>2007-10-16 04:23:52 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-16 12:42:50 -0400
commitdc0cf6a263d5a094d8c17287407aad1032a613b3 (patch)
tree71bf5e86e21f55b8838f02b6b8af7ba7238c0f3b
parentb5446b514c00b3034017609ec4e5a09117b9c8fd (diff)
pcmcia: cistpl: use get_unaligned() in CIS parsing
Based on a patch by Haavard Skinnemoen posted to linux-pcmcia, but using static inlines for readability reasons. this should fix PCMCIA an AVR32 Signed-off-by: Daniel Ritz <daniel.ritz@gmx.ch> Cc: Haavard Skinnemoen <hskinnemoen@atmel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/pcmcia/cistpl.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c
index d154dee76e7..06a85d7d5aa 100644
--- a/drivers/pcmcia/cistpl.c
+++ b/drivers/pcmcia/cistpl.c
@@ -25,6 +25,7 @@
25#include <linux/ioport.h> 25#include <linux/ioport.h>
26#include <asm/io.h> 26#include <asm/io.h>
27#include <asm/byteorder.h> 27#include <asm/byteorder.h>
28#include <asm/unaligned.h>
28 29
29#include <pcmcia/cs_types.h> 30#include <pcmcia/cs_types.h>
30#include <pcmcia/ss.h> 31#include <pcmcia/ss.h>
@@ -401,6 +402,15 @@ EXPORT_SYMBOL(pcmcia_replace_cis);
401 402
402======================================================================*/ 403======================================================================*/
403 404
405static inline u16 cis_get_u16(void *ptr)
406{
407 return le16_to_cpu(get_unaligned((__le16 *) ptr));
408}
409static inline u32 cis_get_u32(void *ptr)
410{
411 return le32_to_cpu(get_unaligned((__le32 *) ptr));
412}
413
404typedef struct tuple_flags { 414typedef struct tuple_flags {
405 u_int link_space:4; 415 u_int link_space:4;
406 u_int has_link:1; 416 u_int has_link:1;
@@ -461,7 +471,7 @@ static int follow_link(struct pcmcia_socket *s, tuple_t *tuple)
461 /* Get indirect link from the MFC tuple */ 471 /* Get indirect link from the MFC tuple */
462 read_cis_cache(s, LINK_SPACE(tuple->Flags), 472 read_cis_cache(s, LINK_SPACE(tuple->Flags),
463 tuple->LinkOffset, 5, link); 473 tuple->LinkOffset, 5, link);
464 ofs = le32_to_cpu(*(__le32 *)(link+1)); 474 ofs = cis_get_u32(link + 1);
465 SPACE(tuple->Flags) = (link[0] == CISTPL_MFC_ATTR); 475 SPACE(tuple->Flags) = (link[0] == CISTPL_MFC_ATTR);
466 /* Move to the next indirect link */ 476 /* Move to the next indirect link */
467 tuple->LinkOffset += 5; 477 tuple->LinkOffset += 5;
@@ -668,10 +678,10 @@ static int parse_checksum(tuple_t *tuple, cistpl_checksum_t *csum)
668 u_char *p; 678 u_char *p;
669 if (tuple->TupleDataLen < 5) 679 if (tuple->TupleDataLen < 5)
670 return CS_BAD_TUPLE; 680 return CS_BAD_TUPLE;
671 p = (u_char *)tuple->TupleData; 681 p = (u_char *) tuple->TupleData;
672 csum->addr = tuple->CISOffset+(short)le16_to_cpu(*(__le16 *)p)-2; 682 csum->addr = tuple->CISOffset + cis_get_u16(p) - 2;
673 csum->len = le16_to_cpu(*(__le16 *)(p + 2)); 683 csum->len = cis_get_u16(p + 2);
674 csum->sum = *(p+4); 684 csum->sum = *(p + 4);
675 return CS_SUCCESS; 685 return CS_SUCCESS;
676} 686}
677 687
@@ -681,7 +691,7 @@ static int parse_longlink(tuple_t *tuple, cistpl_longlink_t *link)
681{ 691{
682 if (tuple->TupleDataLen < 4) 692 if (tuple->TupleDataLen < 4)
683 return CS_BAD_TUPLE; 693 return CS_BAD_TUPLE;
684 link->addr = le32_to_cpu(*(__le32 *)tuple->TupleData); 694 link->addr = cis_get_u32(tuple->TupleData);
685 return CS_SUCCESS; 695 return CS_SUCCESS;
686} 696}
687 697
@@ -700,7 +710,8 @@ static int parse_longlink_mfc(tuple_t *tuple,
700 return CS_BAD_TUPLE; 710 return CS_BAD_TUPLE;
701 for (i = 0; i < link->nfn; i++) { 711 for (i = 0; i < link->nfn; i++) {
702 link->fn[i].space = *p; p++; 712 link->fn[i].space = *p; p++;
703 link->fn[i].addr = le32_to_cpu(*(__le32 *)p); p += 4; 713 link->fn[i].addr = cis_get_u32(p);
714 p += 4;
704 } 715 }
705 return CS_SUCCESS; 716 return CS_SUCCESS;
706} 717}
@@ -787,12 +798,10 @@ static int parse_jedec(tuple_t *tuple, cistpl_jedec_t *jedec)
787 798
788static int parse_manfid(tuple_t *tuple, cistpl_manfid_t *m) 799static int parse_manfid(tuple_t *tuple, cistpl_manfid_t *m)
789{ 800{
790 __le16 *p;
791 if (tuple->TupleDataLen < 4) 801 if (tuple->TupleDataLen < 4)
792 return CS_BAD_TUPLE; 802 return CS_BAD_TUPLE;
793 p = (__le16 *)tuple->TupleData; 803 m->manf = cis_get_u16(tuple->TupleData);
794 m->manf = le16_to_cpu(p[0]); 804 m->card = cis_get_u16(tuple->TupleData + 2);
795 m->card = le16_to_cpu(p[1]);
796 return CS_SUCCESS; 805 return CS_SUCCESS;
797} 806}
798 807
@@ -1091,7 +1100,7 @@ static int parse_cftable_entry(tuple_t *tuple,
1091 break; 1100 break;
1092 case 0x20: 1101 case 0x20:
1093 entry->mem.nwin = 1; 1102 entry->mem.nwin = 1;
1094 entry->mem.win[0].len = le16_to_cpu(*(__le16 *)p) << 8; 1103 entry->mem.win[0].len = cis_get_u16(p) << 8;
1095 entry->mem.win[0].card_addr = 0; 1104 entry->mem.win[0].card_addr = 0;
1096 entry->mem.win[0].host_addr = 0; 1105 entry->mem.win[0].host_addr = 0;
1097 p += 2; 1106 p += 2;
@@ -1099,9 +1108,8 @@ static int parse_cftable_entry(tuple_t *tuple,
1099 break; 1108 break;
1100 case 0x40: 1109 case 0x40:
1101 entry->mem.nwin = 1; 1110 entry->mem.nwin = 1;
1102 entry->mem.win[0].len = le16_to_cpu(*(__le16 *)p) << 8; 1111 entry->mem.win[0].len = cis_get_u16(p) << 8;
1103 entry->mem.win[0].card_addr = 1112 entry->mem.win[0].card_addr = cis_get_u16(p + 2) << 8;
1104 le16_to_cpu(*(__le16 *)(p+2)) << 8;
1105 entry->mem.win[0].host_addr = 0; 1113 entry->mem.win[0].host_addr = 0;
1106 p += 4; 1114 p += 4;
1107 if (p > q) return CS_BAD_TUPLE; 1115 if (p > q) return CS_BAD_TUPLE;
@@ -1138,7 +1146,7 @@ static int parse_bar(tuple_t *tuple, cistpl_bar_t *bar)
1138 p = (u_char *)tuple->TupleData; 1146 p = (u_char *)tuple->TupleData;
1139 bar->attr = *p; 1147 bar->attr = *p;
1140 p += 2; 1148 p += 2;
1141 bar->size = le32_to_cpu(*(__le32 *)p); 1149 bar->size = cis_get_u32(p);
1142 return CS_SUCCESS; 1150 return CS_SUCCESS;
1143} 1151}
1144 1152
@@ -1151,7 +1159,7 @@ static int parse_config_cb(tuple_t *tuple, cistpl_config_t *config)
1151 return CS_BAD_TUPLE; 1159 return CS_BAD_TUPLE;
1152 config->last_idx = *(++p); 1160 config->last_idx = *(++p);
1153 p++; 1161 p++;
1154 config->base = le32_to_cpu(*(__le32 *)p); 1162 config->base = cis_get_u32(p);
1155 config->subtuples = tuple->TupleDataLen - 6; 1163 config->subtuples = tuple->TupleDataLen - 6;
1156 return CS_SUCCESS; 1164 return CS_SUCCESS;
1157} 1165}
@@ -1267,7 +1275,7 @@ static int parse_vers_2(tuple_t *tuple, cistpl_vers_2_t *v2)
1267 1275
1268 v2->vers = p[0]; 1276 v2->vers = p[0];
1269 v2->comply = p[1]; 1277 v2->comply = p[1];
1270 v2->dindex = le16_to_cpu(*(__le16 *)(p+2)); 1278 v2->dindex = cis_get_u16(p +2 );
1271 v2->vspec8 = p[6]; 1279 v2->vspec8 = p[6];
1272 v2->vspec9 = p[7]; 1280 v2->vspec9 = p[7];
1273 v2->nhdr = p[8]; 1281 v2->nhdr = p[8];
@@ -1308,8 +1316,8 @@ static int parse_format(tuple_t *tuple, cistpl_format_t *fmt)
1308 1316
1309 fmt->type = p[0]; 1317 fmt->type = p[0];
1310 fmt->edc = p[1]; 1318 fmt->edc = p[1];
1311 fmt->offset = le32_to_cpu(*(__le32 *)(p+2)); 1319 fmt->offset = cis_get_u32(p + 2);
1312 fmt->length = le32_to_cpu(*(__le32 *)(p+6)); 1320 fmt->length = cis_get_u32(p + 6);
1313 1321
1314 return CS_SUCCESS; 1322 return CS_SUCCESS;
1315} 1323}