diff options
Diffstat (limited to 'drivers/pcmcia/cistpl.c')
-rw-r--r-- | drivers/pcmcia/cistpl.c | 297 |
1 files changed, 176 insertions, 121 deletions
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index 65129b54eb09..dcce9f5d8465 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c | |||
@@ -92,7 +92,8 @@ set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flag | |||
92 | if (!(s->features & SS_CAP_STATIC_MAP) && (mem->res == NULL)) { | 92 | if (!(s->features & SS_CAP_STATIC_MAP) && (mem->res == NULL)) { |
93 | mem->res = pcmcia_find_mem_region(0, s->map_size, s->map_size, 0, s); | 93 | mem->res = pcmcia_find_mem_region(0, s->map_size, s->map_size, 0, s); |
94 | if (mem->res == NULL) { | 94 | if (mem->res == NULL) { |
95 | printk(KERN_NOTICE "cs: unable to map card memory!\n"); | 95 | dev_printk(KERN_NOTICE, &s->dev, |
96 | "cs: unable to map card memory!\n"); | ||
96 | return NULL; | 97 | return NULL; |
97 | } | 98 | } |
98 | s->cis_virt = NULL; | 99 | s->cis_virt = NULL; |
@@ -265,13 +266,13 @@ EXPORT_SYMBOL(pcmcia_write_cis_mem); | |||
265 | ======================================================================*/ | 266 | ======================================================================*/ |
266 | 267 | ||
267 | static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, | 268 | static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, |
268 | u_int len, void *ptr) | 269 | size_t len, void *ptr) |
269 | { | 270 | { |
270 | struct cis_cache_entry *cis; | 271 | struct cis_cache_entry *cis; |
271 | int ret; | 272 | int ret; |
272 | 273 | ||
273 | if (s->fake_cis) { | 274 | if (s->fake_cis) { |
274 | if (s->fake_cis_len > addr+len) | 275 | if (s->fake_cis_len >= addr+len) |
275 | memcpy(ptr, s->fake_cis+addr, len); | 276 | memcpy(ptr, s->fake_cis+addr, len); |
276 | else | 277 | else |
277 | memset(ptr, 0xff, len); | 278 | memset(ptr, 0xff, len); |
@@ -351,7 +352,9 @@ int verify_cis_cache(struct pcmcia_socket *s) | |||
351 | 352 | ||
352 | buf = kmalloc(256, GFP_KERNEL); | 353 | buf = kmalloc(256, GFP_KERNEL); |
353 | if (buf == NULL) | 354 | if (buf == NULL) |
354 | return -1; | 355 | dev_printk(KERN_WARNING, &s->dev, |
356 | "no memory for verifying CIS\n"); | ||
357 | return -ENOMEM; | ||
355 | list_for_each_entry(cis, &s->cis_cache, node) { | 358 | list_for_each_entry(cis, &s->cis_cache, node) { |
356 | int len = cis->len; | 359 | int len = cis->len; |
357 | 360 | ||
@@ -380,18 +383,22 @@ int verify_cis_cache(struct pcmcia_socket *s) | |||
380 | 383 | ||
381 | ======================================================================*/ | 384 | ======================================================================*/ |
382 | 385 | ||
383 | int pcmcia_replace_cis(struct pcmcia_socket *s, cisdump_t *cis) | 386 | int pcmcia_replace_cis(struct pcmcia_socket *s, |
387 | const u8 *data, const size_t len) | ||
384 | { | 388 | { |
385 | kfree(s->fake_cis); | 389 | if (len > CISTPL_MAX_CIS_SIZE) { |
386 | s->fake_cis = NULL; | 390 | dev_printk(KERN_WARNING, &s->dev, "replacement CIS too big\n"); |
387 | if (cis->Length > CISTPL_MAX_CIS_SIZE) | 391 | return -EINVAL; |
388 | return CS_BAD_SIZE; | 392 | } |
389 | s->fake_cis = kmalloc(cis->Length, GFP_KERNEL); | 393 | kfree(s->fake_cis); |
390 | if (s->fake_cis == NULL) | 394 | s->fake_cis = kmalloc(len, GFP_KERNEL); |
391 | return CS_OUT_OF_RESOURCE; | 395 | if (s->fake_cis == NULL) { |
392 | s->fake_cis_len = cis->Length; | 396 | dev_printk(KERN_WARNING, &s->dev, "no memory to replace CIS\n"); |
393 | memcpy(s->fake_cis, cis->Data, cis->Length); | 397 | return -ENOMEM; |
394 | return CS_SUCCESS; | 398 | } |
399 | s->fake_cis_len = len; | ||
400 | memcpy(s->fake_cis, data, len); | ||
401 | return 0; | ||
395 | } | 402 | } |
396 | EXPORT_SYMBOL(pcmcia_replace_cis); | 403 | EXPORT_SYMBOL(pcmcia_replace_cis); |
397 | 404 | ||
@@ -418,9 +425,9 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int func, tuple_t *t | |||
418 | int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple_t *tuple) | 425 | int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple_t *tuple) |
419 | { | 426 | { |
420 | if (!s) | 427 | if (!s) |
421 | return CS_BAD_HANDLE; | 428 | return -EINVAL; |
422 | if (!(s->state & SOCKET_PRESENT)) | 429 | if (!(s->state & SOCKET_PRESENT)) |
423 | return CS_NO_CARD; | 430 | return -ENODEV; |
424 | tuple->TupleLink = tuple->Flags = 0; | 431 | tuple->TupleLink = tuple->Flags = 0; |
425 | #ifdef CONFIG_CARDBUS | 432 | #ifdef CONFIG_CARDBUS |
426 | if (s->state & SOCKET_CARDBUS) { | 433 | if (s->state & SOCKET_CARDBUS) { |
@@ -440,10 +447,10 @@ int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple | |||
440 | !(tuple->Attributes & TUPLE_RETURN_COMMON)) { | 447 | !(tuple->Attributes & TUPLE_RETURN_COMMON)) { |
441 | cisdata_t req = tuple->DesiredTuple; | 448 | cisdata_t req = tuple->DesiredTuple; |
442 | tuple->DesiredTuple = CISTPL_LONGLINK_MFC; | 449 | tuple->DesiredTuple = CISTPL_LONGLINK_MFC; |
443 | if (pccard_get_next_tuple(s, function, tuple) == CS_SUCCESS) { | 450 | if (pccard_get_next_tuple(s, function, tuple) == 0) { |
444 | tuple->DesiredTuple = CISTPL_LINKTARGET; | 451 | tuple->DesiredTuple = CISTPL_LINKTARGET; |
445 | if (pccard_get_next_tuple(s, function, tuple) != CS_SUCCESS) | 452 | if (pccard_get_next_tuple(s, function, tuple) != 0) |
446 | return CS_NO_MORE_ITEMS; | 453 | return -ENOSPC; |
447 | } else | 454 | } else |
448 | tuple->CISOffset = tuple->TupleLink = 0; | 455 | tuple->CISOffset = tuple->TupleLink = 0; |
449 | tuple->DesiredTuple = req; | 456 | tuple->DesiredTuple = req; |
@@ -498,9 +505,9 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_ | |||
498 | int ofs, i, attr; | 505 | int ofs, i, attr; |
499 | 506 | ||
500 | if (!s) | 507 | if (!s) |
501 | return CS_BAD_HANDLE; | 508 | return -EINVAL; |
502 | if (!(s->state & SOCKET_PRESENT)) | 509 | if (!(s->state & SOCKET_PRESENT)) |
503 | return CS_NO_CARD; | 510 | return -ENODEV; |
504 | 511 | ||
505 | link[1] = tuple->TupleLink; | 512 | link[1] = tuple->TupleLink; |
506 | ofs = tuple->CISOffset + tuple->TupleLink; | 513 | ofs = tuple->CISOffset + tuple->TupleLink; |
@@ -519,7 +526,7 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_ | |||
519 | /* End of chain? Follow long link if possible */ | 526 | /* End of chain? Follow long link if possible */ |
520 | if (link[0] == CISTPL_END) { | 527 | if (link[0] == CISTPL_END) { |
521 | if ((ofs = follow_link(s, tuple)) < 0) | 528 | if ((ofs = follow_link(s, tuple)) < 0) |
522 | return CS_NO_MORE_ITEMS; | 529 | return -ENOSPC; |
523 | attr = SPACE(tuple->Flags); | 530 | attr = SPACE(tuple->Flags); |
524 | read_cis_cache(s, attr, ofs, 2, link); | 531 | read_cis_cache(s, attr, ofs, 2, link); |
525 | } | 532 | } |
@@ -577,13 +584,13 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_ | |||
577 | } | 584 | } |
578 | if (i == MAX_TUPLES) { | 585 | if (i == MAX_TUPLES) { |
579 | cs_dbg(s, 1, "cs: overrun in pcmcia_get_next_tuple\n"); | 586 | cs_dbg(s, 1, "cs: overrun in pcmcia_get_next_tuple\n"); |
580 | return CS_NO_MORE_ITEMS; | 587 | return -ENOSPC; |
581 | } | 588 | } |
582 | 589 | ||
583 | tuple->TupleCode = link[0]; | 590 | tuple->TupleCode = link[0]; |
584 | tuple->TupleLink = link[1]; | 591 | tuple->TupleLink = link[1]; |
585 | tuple->CISOffset = ofs + 2; | 592 | tuple->CISOffset = ofs + 2; |
586 | return CS_SUCCESS; | 593 | return 0; |
587 | } | 594 | } |
588 | EXPORT_SYMBOL(pccard_get_next_tuple); | 595 | EXPORT_SYMBOL(pccard_get_next_tuple); |
589 | 596 | ||
@@ -596,18 +603,18 @@ int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple) | |||
596 | u_int len; | 603 | u_int len; |
597 | 604 | ||
598 | if (!s) | 605 | if (!s) |
599 | return CS_BAD_HANDLE; | 606 | return -EINVAL; |
600 | 607 | ||
601 | if (tuple->TupleLink < tuple->TupleOffset) | 608 | if (tuple->TupleLink < tuple->TupleOffset) |
602 | return CS_NO_MORE_ITEMS; | 609 | return -ENOSPC; |
603 | len = tuple->TupleLink - tuple->TupleOffset; | 610 | len = tuple->TupleLink - tuple->TupleOffset; |
604 | tuple->TupleDataLen = tuple->TupleLink; | 611 | tuple->TupleDataLen = tuple->TupleLink; |
605 | if (len == 0) | 612 | if (len == 0) |
606 | return CS_SUCCESS; | 613 | return 0; |
607 | read_cis_cache(s, SPACE(tuple->Flags), | 614 | read_cis_cache(s, SPACE(tuple->Flags), |
608 | tuple->CISOffset + tuple->TupleOffset, | 615 | tuple->CISOffset + tuple->TupleOffset, |
609 | _MIN(len, tuple->TupleDataMax), tuple->TupleData); | 616 | _MIN(len, tuple->TupleDataMax), tuple->TupleData); |
610 | return CS_SUCCESS; | 617 | return 0; |
611 | } | 618 | } |
612 | EXPORT_SYMBOL(pccard_get_tuple_data); | 619 | EXPORT_SYMBOL(pccard_get_tuple_data); |
613 | 620 | ||
@@ -640,25 +647,31 @@ static int parse_device(tuple_t *tuple, cistpl_device_t *device) | |||
640 | case 3: device->dev[i].speed = 150; break; | 647 | case 3: device->dev[i].speed = 150; break; |
641 | case 4: device->dev[i].speed = 100; break; | 648 | case 4: device->dev[i].speed = 100; break; |
642 | case 7: | 649 | case 7: |
643 | if (++p == q) return CS_BAD_TUPLE; | 650 | if (++p == q) |
651 | return -EINVAL; | ||
644 | device->dev[i].speed = SPEED_CVT(*p); | 652 | device->dev[i].speed = SPEED_CVT(*p); |
645 | while (*p & 0x80) | 653 | while (*p & 0x80) |
646 | if (++p == q) return CS_BAD_TUPLE; | 654 | if (++p == q) |
655 | return -EINVAL; | ||
647 | break; | 656 | break; |
648 | default: | 657 | default: |
649 | return CS_BAD_TUPLE; | 658 | return -EINVAL; |
650 | } | 659 | } |
651 | 660 | ||
652 | if (++p == q) return CS_BAD_TUPLE; | 661 | if (++p == q) |
653 | if (*p == 0xff) break; | 662 | return -EINVAL; |
663 | if (*p == 0xff) | ||
664 | break; | ||
654 | scale = *p & 7; | 665 | scale = *p & 7; |
655 | if (scale == 7) return CS_BAD_TUPLE; | 666 | if (scale == 7) |
667 | return -EINVAL; | ||
656 | device->dev[i].size = ((*p >> 3) + 1) * (512 << (scale*2)); | 668 | device->dev[i].size = ((*p >> 3) + 1) * (512 << (scale*2)); |
657 | device->ndev++; | 669 | device->ndev++; |
658 | if (++p == q) break; | 670 | if (++p == q) |
671 | break; | ||
659 | } | 672 | } |
660 | 673 | ||
661 | return CS_SUCCESS; | 674 | return 0; |
662 | } | 675 | } |
663 | 676 | ||
664 | /*====================================================================*/ | 677 | /*====================================================================*/ |
@@ -667,12 +680,12 @@ static int parse_checksum(tuple_t *tuple, cistpl_checksum_t *csum) | |||
667 | { | 680 | { |
668 | u_char *p; | 681 | u_char *p; |
669 | if (tuple->TupleDataLen < 5) | 682 | if (tuple->TupleDataLen < 5) |
670 | return CS_BAD_TUPLE; | 683 | return -EINVAL; |
671 | p = (u_char *) tuple->TupleData; | 684 | p = (u_char *) tuple->TupleData; |
672 | csum->addr = tuple->CISOffset + get_unaligned_le16(p) - 2; | 685 | csum->addr = tuple->CISOffset + get_unaligned_le16(p) - 2; |
673 | csum->len = get_unaligned_le16(p + 2); | 686 | csum->len = get_unaligned_le16(p + 2); |
674 | csum->sum = *(p + 4); | 687 | csum->sum = *(p + 4); |
675 | return CS_SUCCESS; | 688 | return 0; |
676 | } | 689 | } |
677 | 690 | ||
678 | /*====================================================================*/ | 691 | /*====================================================================*/ |
@@ -680,9 +693,9 @@ static int parse_checksum(tuple_t *tuple, cistpl_checksum_t *csum) | |||
680 | static int parse_longlink(tuple_t *tuple, cistpl_longlink_t *link) | 693 | static int parse_longlink(tuple_t *tuple, cistpl_longlink_t *link) |
681 | { | 694 | { |
682 | if (tuple->TupleDataLen < 4) | 695 | if (tuple->TupleDataLen < 4) |
683 | return CS_BAD_TUPLE; | 696 | return -EINVAL; |
684 | link->addr = get_unaligned_le32(tuple->TupleData); | 697 | link->addr = get_unaligned_le32(tuple->TupleData); |
685 | return CS_SUCCESS; | 698 | return 0; |
686 | } | 699 | } |
687 | 700 | ||
688 | /*====================================================================*/ | 701 | /*====================================================================*/ |
@@ -697,13 +710,13 @@ static int parse_longlink_mfc(tuple_t *tuple, | |||
697 | 710 | ||
698 | link->nfn = *p; p++; | 711 | link->nfn = *p; p++; |
699 | if (tuple->TupleDataLen <= link->nfn*5) | 712 | if (tuple->TupleDataLen <= link->nfn*5) |
700 | return CS_BAD_TUPLE; | 713 | return -EINVAL; |
701 | for (i = 0; i < link->nfn; i++) { | 714 | for (i = 0; i < link->nfn; i++) { |
702 | link->fn[i].space = *p; p++; | 715 | link->fn[i].space = *p; p++; |
703 | link->fn[i].addr = get_unaligned_le32(p); | 716 | link->fn[i].addr = get_unaligned_le32(p); |
704 | p += 4; | 717 | p += 4; |
705 | } | 718 | } |
706 | return CS_SUCCESS; | 719 | return 0; |
707 | } | 720 | } |
708 | 721 | ||
709 | /*====================================================================*/ | 722 | /*====================================================================*/ |
@@ -713,24 +726,27 @@ static int parse_strings(u_char *p, u_char *q, int max, | |||
713 | { | 726 | { |
714 | int i, j, ns; | 727 | int i, j, ns; |
715 | 728 | ||
716 | if (p == q) return CS_BAD_TUPLE; | 729 | if (p == q) |
730 | return -EINVAL; | ||
717 | ns = 0; j = 0; | 731 | ns = 0; j = 0; |
718 | for (i = 0; i < max; i++) { | 732 | for (i = 0; i < max; i++) { |
719 | if (*p == 0xff) break; | 733 | if (*p == 0xff) |
734 | break; | ||
720 | ofs[i] = j; | 735 | ofs[i] = j; |
721 | ns++; | 736 | ns++; |
722 | for (;;) { | 737 | for (;;) { |
723 | s[j++] = (*p == 0xff) ? '\0' : *p; | 738 | s[j++] = (*p == 0xff) ? '\0' : *p; |
724 | if ((*p == '\0') || (*p == 0xff)) break; | 739 | if ((*p == '\0') || (*p == 0xff)) break; |
725 | if (++p == q) return CS_BAD_TUPLE; | 740 | if (++p == q) |
741 | return -EINVAL; | ||
726 | } | 742 | } |
727 | if ((*p == 0xff) || (++p == q)) break; | 743 | if ((*p == 0xff) || (++p == q)) break; |
728 | } | 744 | } |
729 | if (found) { | 745 | if (found) { |
730 | *found = ns; | 746 | *found = ns; |
731 | return CS_SUCCESS; | 747 | return 0; |
732 | } else { | 748 | } else { |
733 | return (ns == max) ? CS_SUCCESS : CS_BAD_TUPLE; | 749 | return (ns == max) ? 0 : -EINVAL; |
734 | } | 750 | } |
735 | } | 751 | } |
736 | 752 | ||
@@ -745,7 +761,8 @@ static int parse_vers_1(tuple_t *tuple, cistpl_vers_1_t *vers_1) | |||
745 | 761 | ||
746 | vers_1->major = *p; p++; | 762 | vers_1->major = *p; p++; |
747 | vers_1->minor = *p; p++; | 763 | vers_1->minor = *p; p++; |
748 | if (p >= q) return CS_BAD_TUPLE; | 764 | if (p >= q) |
765 | return -EINVAL; | ||
749 | 766 | ||
750 | return parse_strings(p, q, CISTPL_VERS_1_MAX_PROD_STRINGS, | 767 | return parse_strings(p, q, CISTPL_VERS_1_MAX_PROD_STRINGS, |
751 | vers_1->str, vers_1->ofs, &vers_1->ns); | 768 | vers_1->str, vers_1->ofs, &vers_1->ns); |
@@ -781,7 +798,7 @@ static int parse_jedec(tuple_t *tuple, cistpl_jedec_t *jedec) | |||
781 | p += 2; | 798 | p += 2; |
782 | } | 799 | } |
783 | jedec->nid = nid; | 800 | jedec->nid = nid; |
784 | return CS_SUCCESS; | 801 | return 0; |
785 | } | 802 | } |
786 | 803 | ||
787 | /*====================================================================*/ | 804 | /*====================================================================*/ |
@@ -789,10 +806,10 @@ static int parse_jedec(tuple_t *tuple, cistpl_jedec_t *jedec) | |||
789 | static int parse_manfid(tuple_t *tuple, cistpl_manfid_t *m) | 806 | static int parse_manfid(tuple_t *tuple, cistpl_manfid_t *m) |
790 | { | 807 | { |
791 | if (tuple->TupleDataLen < 4) | 808 | if (tuple->TupleDataLen < 4) |
792 | return CS_BAD_TUPLE; | 809 | return -EINVAL; |
793 | m->manf = get_unaligned_le16(tuple->TupleData); | 810 | m->manf = get_unaligned_le16(tuple->TupleData); |
794 | m->card = get_unaligned_le16(tuple->TupleData + 2); | 811 | m->card = get_unaligned_le16(tuple->TupleData + 2); |
795 | return CS_SUCCESS; | 812 | return 0; |
796 | } | 813 | } |
797 | 814 | ||
798 | /*====================================================================*/ | 815 | /*====================================================================*/ |
@@ -801,11 +818,11 @@ static int parse_funcid(tuple_t *tuple, cistpl_funcid_t *f) | |||
801 | { | 818 | { |
802 | u_char *p; | 819 | u_char *p; |
803 | if (tuple->TupleDataLen < 2) | 820 | if (tuple->TupleDataLen < 2) |
804 | return CS_BAD_TUPLE; | 821 | return -EINVAL; |
805 | p = (u_char *)tuple->TupleData; | 822 | p = (u_char *)tuple->TupleData; |
806 | f->func = p[0]; | 823 | f->func = p[0]; |
807 | f->sysinit = p[1]; | 824 | f->sysinit = p[1]; |
808 | return CS_SUCCESS; | 825 | return 0; |
809 | } | 826 | } |
810 | 827 | ||
811 | /*====================================================================*/ | 828 | /*====================================================================*/ |
@@ -815,12 +832,12 @@ static int parse_funce(tuple_t *tuple, cistpl_funce_t *f) | |||
815 | u_char *p; | 832 | u_char *p; |
816 | int i; | 833 | int i; |
817 | if (tuple->TupleDataLen < 1) | 834 | if (tuple->TupleDataLen < 1) |
818 | return CS_BAD_TUPLE; | 835 | return -EINVAL; |
819 | p = (u_char *)tuple->TupleData; | 836 | p = (u_char *)tuple->TupleData; |
820 | f->type = p[0]; | 837 | f->type = p[0]; |
821 | for (i = 1; i < tuple->TupleDataLen; i++) | 838 | for (i = 1; i < tuple->TupleDataLen; i++) |
822 | f->data[i-1] = p[i]; | 839 | f->data[i-1] = p[i]; |
823 | return CS_SUCCESS; | 840 | return 0; |
824 | } | 841 | } |
825 | 842 | ||
826 | /*====================================================================*/ | 843 | /*====================================================================*/ |
@@ -834,7 +851,7 @@ static int parse_config(tuple_t *tuple, cistpl_config_t *config) | |||
834 | rasz = *p & 0x03; | 851 | rasz = *p & 0x03; |
835 | rmsz = (*p & 0x3c) >> 2; | 852 | rmsz = (*p & 0x3c) >> 2; |
836 | if (tuple->TupleDataLen < rasz+rmsz+4) | 853 | if (tuple->TupleDataLen < rasz+rmsz+4) |
837 | return CS_BAD_TUPLE; | 854 | return -EINVAL; |
838 | config->last_idx = *(++p); | 855 | config->last_idx = *(++p); |
839 | p++; | 856 | p++; |
840 | config->base = 0; | 857 | config->base = 0; |
@@ -846,7 +863,7 @@ static int parse_config(tuple_t *tuple, cistpl_config_t *config) | |||
846 | for (i = 0; i <= rmsz; i++) | 863 | for (i = 0; i <= rmsz; i++) |
847 | config->rmask[i>>2] += p[i] << (8*(i%4)); | 864 | config->rmask[i>>2] += p[i] << (8*(i%4)); |
848 | config->subtuples = tuple->TupleDataLen - (rasz+rmsz+4); | 865 | config->subtuples = tuple->TupleDataLen - (rasz+rmsz+4); |
849 | return CS_SUCCESS; | 866 | return 0; |
850 | } | 867 | } |
851 | 868 | ||
852 | /*====================================================================== | 869 | /*====================================================================== |
@@ -1002,10 +1019,12 @@ static u_char *parse_mem(u_char *p, u_char *q, cistpl_mem_t *mem) | |||
1002 | 1019 | ||
1003 | static u_char *parse_irq(u_char *p, u_char *q, cistpl_irq_t *irq) | 1020 | static u_char *parse_irq(u_char *p, u_char *q, cistpl_irq_t *irq) |
1004 | { | 1021 | { |
1005 | if (p == q) return NULL; | 1022 | if (p == q) |
1023 | return NULL; | ||
1006 | irq->IRQInfo1 = *p; p++; | 1024 | irq->IRQInfo1 = *p; p++; |
1007 | if (irq->IRQInfo1 & IRQ_INFO2_VALID) { | 1025 | if (irq->IRQInfo1 & IRQ_INFO2_VALID) { |
1008 | if (p+2 > q) return NULL; | 1026 | if (p+2 > q) |
1027 | return NULL; | ||
1009 | irq->IRQInfo2 = (p[1]<<8) + p[0]; | 1028 | irq->IRQInfo2 = (p[1]<<8) + p[0]; |
1010 | p += 2; | 1029 | p += 2; |
1011 | } | 1030 | } |
@@ -1026,7 +1045,8 @@ static int parse_cftable_entry(tuple_t *tuple, | |||
1026 | if (*p & 0x40) | 1045 | if (*p & 0x40) |
1027 | entry->flags |= CISTPL_CFTABLE_DEFAULT; | 1046 | entry->flags |= CISTPL_CFTABLE_DEFAULT; |
1028 | if (*p & 0x80) { | 1047 | if (*p & 0x80) { |
1029 | if (++p == q) return CS_BAD_TUPLE; | 1048 | if (++p == q) |
1049 | return -EINVAL; | ||
1030 | if (*p & 0x10) | 1050 | if (*p & 0x10) |
1031 | entry->flags |= CISTPL_CFTABLE_BVDS; | 1051 | entry->flags |= CISTPL_CFTABLE_BVDS; |
1032 | if (*p & 0x20) | 1052 | if (*p & 0x20) |
@@ -1040,30 +1060,35 @@ static int parse_cftable_entry(tuple_t *tuple, | |||
1040 | entry->interface = 0; | 1060 | entry->interface = 0; |
1041 | 1061 | ||
1042 | /* Process optional features */ | 1062 | /* Process optional features */ |
1043 | if (++p == q) return CS_BAD_TUPLE; | 1063 | if (++p == q) |
1064 | return -EINVAL; | ||
1044 | features = *p; p++; | 1065 | features = *p; p++; |
1045 | 1066 | ||
1046 | /* Power options */ | 1067 | /* Power options */ |
1047 | if ((features & 3) > 0) { | 1068 | if ((features & 3) > 0) { |
1048 | p = parse_power(p, q, &entry->vcc); | 1069 | p = parse_power(p, q, &entry->vcc); |
1049 | if (p == NULL) return CS_BAD_TUPLE; | 1070 | if (p == NULL) |
1071 | return -EINVAL; | ||
1050 | } else | 1072 | } else |
1051 | entry->vcc.present = 0; | 1073 | entry->vcc.present = 0; |
1052 | if ((features & 3) > 1) { | 1074 | if ((features & 3) > 1) { |
1053 | p = parse_power(p, q, &entry->vpp1); | 1075 | p = parse_power(p, q, &entry->vpp1); |
1054 | if (p == NULL) return CS_BAD_TUPLE; | 1076 | if (p == NULL) |
1077 | return -EINVAL; | ||
1055 | } else | 1078 | } else |
1056 | entry->vpp1.present = 0; | 1079 | entry->vpp1.present = 0; |
1057 | if ((features & 3) > 2) { | 1080 | if ((features & 3) > 2) { |
1058 | p = parse_power(p, q, &entry->vpp2); | 1081 | p = parse_power(p, q, &entry->vpp2); |
1059 | if (p == NULL) return CS_BAD_TUPLE; | 1082 | if (p == NULL) |
1083 | return -EINVAL; | ||
1060 | } else | 1084 | } else |
1061 | entry->vpp2.present = 0; | 1085 | entry->vpp2.present = 0; |
1062 | 1086 | ||
1063 | /* Timing options */ | 1087 | /* Timing options */ |
1064 | if (features & 0x04) { | 1088 | if (features & 0x04) { |
1065 | p = parse_timing(p, q, &entry->timing); | 1089 | p = parse_timing(p, q, &entry->timing); |
1066 | if (p == NULL) return CS_BAD_TUPLE; | 1090 | if (p == NULL) |
1091 | return -EINVAL; | ||
1067 | } else { | 1092 | } else { |
1068 | entry->timing.wait = 0; | 1093 | entry->timing.wait = 0; |
1069 | entry->timing.ready = 0; | 1094 | entry->timing.ready = 0; |
@@ -1073,14 +1098,16 @@ static int parse_cftable_entry(tuple_t *tuple, | |||
1073 | /* I/O window options */ | 1098 | /* I/O window options */ |
1074 | if (features & 0x08) { | 1099 | if (features & 0x08) { |
1075 | p = parse_io(p, q, &entry->io); | 1100 | p = parse_io(p, q, &entry->io); |
1076 | if (p == NULL) return CS_BAD_TUPLE; | 1101 | if (p == NULL) |
1102 | return -EINVAL; | ||
1077 | } else | 1103 | } else |
1078 | entry->io.nwin = 0; | 1104 | entry->io.nwin = 0; |
1079 | 1105 | ||
1080 | /* Interrupt options */ | 1106 | /* Interrupt options */ |
1081 | if (features & 0x10) { | 1107 | if (features & 0x10) { |
1082 | p = parse_irq(p, q, &entry->irq); | 1108 | p = parse_irq(p, q, &entry->irq); |
1083 | if (p == NULL) return CS_BAD_TUPLE; | 1109 | if (p == NULL) |
1110 | return -EINVAL; | ||
1084 | } else | 1111 | } else |
1085 | entry->irq.IRQInfo1 = 0; | 1112 | entry->irq.IRQInfo1 = 0; |
1086 | 1113 | ||
@@ -1094,7 +1121,8 @@ static int parse_cftable_entry(tuple_t *tuple, | |||
1094 | entry->mem.win[0].card_addr = 0; | 1121 | entry->mem.win[0].card_addr = 0; |
1095 | entry->mem.win[0].host_addr = 0; | 1122 | entry->mem.win[0].host_addr = 0; |
1096 | p += 2; | 1123 | p += 2; |
1097 | if (p > q) return CS_BAD_TUPLE; | 1124 | if (p > q) |
1125 | return -EINVAL; | ||
1098 | break; | 1126 | break; |
1099 | case 0x40: | 1127 | case 0x40: |
1100 | entry->mem.nwin = 1; | 1128 | entry->mem.nwin = 1; |
@@ -1102,26 +1130,30 @@ static int parse_cftable_entry(tuple_t *tuple, | |||
1102 | entry->mem.win[0].card_addr = get_unaligned_le16(p + 2) << 8; | 1130 | entry->mem.win[0].card_addr = get_unaligned_le16(p + 2) << 8; |
1103 | entry->mem.win[0].host_addr = 0; | 1131 | entry->mem.win[0].host_addr = 0; |
1104 | p += 4; | 1132 | p += 4; |
1105 | if (p > q) return CS_BAD_TUPLE; | 1133 | if (p > q) |
1134 | return -EINVAL; | ||
1106 | break; | 1135 | break; |
1107 | case 0x60: | 1136 | case 0x60: |
1108 | p = parse_mem(p, q, &entry->mem); | 1137 | p = parse_mem(p, q, &entry->mem); |
1109 | if (p == NULL) return CS_BAD_TUPLE; | 1138 | if (p == NULL) |
1139 | return -EINVAL; | ||
1110 | break; | 1140 | break; |
1111 | } | 1141 | } |
1112 | 1142 | ||
1113 | /* Misc features */ | 1143 | /* Misc features */ |
1114 | if (features & 0x80) { | 1144 | if (features & 0x80) { |
1115 | if (p == q) return CS_BAD_TUPLE; | 1145 | if (p == q) |
1146 | return -EINVAL; | ||
1116 | entry->flags |= (*p << 8); | 1147 | entry->flags |= (*p << 8); |
1117 | while (*p & 0x80) | 1148 | while (*p & 0x80) |
1118 | if (++p == q) return CS_BAD_TUPLE; | 1149 | if (++p == q) |
1150 | return -EINVAL; | ||
1119 | p++; | 1151 | p++; |
1120 | } | 1152 | } |
1121 | 1153 | ||
1122 | entry->subtuples = q-p; | 1154 | entry->subtuples = q-p; |
1123 | 1155 | ||
1124 | return CS_SUCCESS; | 1156 | return 0; |
1125 | } | 1157 | } |
1126 | 1158 | ||
1127 | /*====================================================================*/ | 1159 | /*====================================================================*/ |
@@ -1132,12 +1164,12 @@ static int parse_bar(tuple_t *tuple, cistpl_bar_t *bar) | |||
1132 | { | 1164 | { |
1133 | u_char *p; | 1165 | u_char *p; |
1134 | if (tuple->TupleDataLen < 6) | 1166 | if (tuple->TupleDataLen < 6) |
1135 | return CS_BAD_TUPLE; | 1167 | return -EINVAL; |
1136 | p = (u_char *)tuple->TupleData; | 1168 | p = (u_char *)tuple->TupleData; |
1137 | bar->attr = *p; | 1169 | bar->attr = *p; |
1138 | p += 2; | 1170 | p += 2; |
1139 | bar->size = get_unaligned_le32(p); | 1171 | bar->size = get_unaligned_le32(p); |
1140 | return CS_SUCCESS; | 1172 | return 0; |
1141 | } | 1173 | } |
1142 | 1174 | ||
1143 | static int parse_config_cb(tuple_t *tuple, cistpl_config_t *config) | 1175 | static int parse_config_cb(tuple_t *tuple, cistpl_config_t *config) |
@@ -1146,12 +1178,12 @@ static int parse_config_cb(tuple_t *tuple, cistpl_config_t *config) | |||
1146 | 1178 | ||
1147 | p = (u_char *)tuple->TupleData; | 1179 | p = (u_char *)tuple->TupleData; |
1148 | if ((*p != 3) || (tuple->TupleDataLen < 6)) | 1180 | if ((*p != 3) || (tuple->TupleDataLen < 6)) |
1149 | return CS_BAD_TUPLE; | 1181 | return -EINVAL; |
1150 | config->last_idx = *(++p); | 1182 | config->last_idx = *(++p); |
1151 | p++; | 1183 | p++; |
1152 | config->base = get_unaligned_le32(p); | 1184 | config->base = get_unaligned_le32(p); |
1153 | config->subtuples = tuple->TupleDataLen - 6; | 1185 | config->subtuples = tuple->TupleDataLen - 6; |
1154 | return CS_SUCCESS; | 1186 | return 0; |
1155 | } | 1187 | } |
1156 | 1188 | ||
1157 | static int parse_cftable_entry_cb(tuple_t *tuple, | 1189 | static int parse_cftable_entry_cb(tuple_t *tuple, |
@@ -1167,29 +1199,34 @@ static int parse_cftable_entry_cb(tuple_t *tuple, | |||
1167 | entry->flags |= CISTPL_CFTABLE_DEFAULT; | 1199 | entry->flags |= CISTPL_CFTABLE_DEFAULT; |
1168 | 1200 | ||
1169 | /* Process optional features */ | 1201 | /* Process optional features */ |
1170 | if (++p == q) return CS_BAD_TUPLE; | 1202 | if (++p == q) |
1203 | return -EINVAL; | ||
1171 | features = *p; p++; | 1204 | features = *p; p++; |
1172 | 1205 | ||
1173 | /* Power options */ | 1206 | /* Power options */ |
1174 | if ((features & 3) > 0) { | 1207 | if ((features & 3) > 0) { |
1175 | p = parse_power(p, q, &entry->vcc); | 1208 | p = parse_power(p, q, &entry->vcc); |
1176 | if (p == NULL) return CS_BAD_TUPLE; | 1209 | if (p == NULL) |
1210 | return -EINVAL; | ||
1177 | } else | 1211 | } else |
1178 | entry->vcc.present = 0; | 1212 | entry->vcc.present = 0; |
1179 | if ((features & 3) > 1) { | 1213 | if ((features & 3) > 1) { |
1180 | p = parse_power(p, q, &entry->vpp1); | 1214 | p = parse_power(p, q, &entry->vpp1); |
1181 | if (p == NULL) return CS_BAD_TUPLE; | 1215 | if (p == NULL) |
1216 | return -EINVAL; | ||
1182 | } else | 1217 | } else |
1183 | entry->vpp1.present = 0; | 1218 | entry->vpp1.present = 0; |
1184 | if ((features & 3) > 2) { | 1219 | if ((features & 3) > 2) { |
1185 | p = parse_power(p, q, &entry->vpp2); | 1220 | p = parse_power(p, q, &entry->vpp2); |
1186 | if (p == NULL) return CS_BAD_TUPLE; | 1221 | if (p == NULL) |
1222 | return -EINVAL; | ||
1187 | } else | 1223 | } else |
1188 | entry->vpp2.present = 0; | 1224 | entry->vpp2.present = 0; |
1189 | 1225 | ||
1190 | /* I/O window options */ | 1226 | /* I/O window options */ |
1191 | if (features & 0x08) { | 1227 | if (features & 0x08) { |
1192 | if (p == q) return CS_BAD_TUPLE; | 1228 | if (p == q) |
1229 | return -EINVAL; | ||
1193 | entry->io = *p; p++; | 1230 | entry->io = *p; p++; |
1194 | } else | 1231 | } else |
1195 | entry->io = 0; | 1232 | entry->io = 0; |
@@ -1197,32 +1234,37 @@ static int parse_cftable_entry_cb(tuple_t *tuple, | |||
1197 | /* Interrupt options */ | 1234 | /* Interrupt options */ |
1198 | if (features & 0x10) { | 1235 | if (features & 0x10) { |
1199 | p = parse_irq(p, q, &entry->irq); | 1236 | p = parse_irq(p, q, &entry->irq); |
1200 | if (p == NULL) return CS_BAD_TUPLE; | 1237 | if (p == NULL) |
1238 | return -EINVAL; | ||
1201 | } else | 1239 | } else |
1202 | entry->irq.IRQInfo1 = 0; | 1240 | entry->irq.IRQInfo1 = 0; |
1203 | 1241 | ||
1204 | if (features & 0x20) { | 1242 | if (features & 0x20) { |
1205 | if (p == q) return CS_BAD_TUPLE; | 1243 | if (p == q) |
1244 | return -EINVAL; | ||
1206 | entry->mem = *p; p++; | 1245 | entry->mem = *p; p++; |
1207 | } else | 1246 | } else |
1208 | entry->mem = 0; | 1247 | entry->mem = 0; |
1209 | 1248 | ||
1210 | /* Misc features */ | 1249 | /* Misc features */ |
1211 | if (features & 0x80) { | 1250 | if (features & 0x80) { |
1212 | if (p == q) return CS_BAD_TUPLE; | 1251 | if (p == q) |
1252 | return -EINVAL; | ||
1213 | entry->flags |= (*p << 8); | 1253 | entry->flags |= (*p << 8); |
1214 | if (*p & 0x80) { | 1254 | if (*p & 0x80) { |
1215 | if (++p == q) return CS_BAD_TUPLE; | 1255 | if (++p == q) |
1256 | return -EINVAL; | ||
1216 | entry->flags |= (*p << 16); | 1257 | entry->flags |= (*p << 16); |
1217 | } | 1258 | } |
1218 | while (*p & 0x80) | 1259 | while (*p & 0x80) |
1219 | if (++p == q) return CS_BAD_TUPLE; | 1260 | if (++p == q) |
1261 | return -EINVAL; | ||
1220 | p++; | 1262 | p++; |
1221 | } | 1263 | } |
1222 | 1264 | ||
1223 | entry->subtuples = q-p; | 1265 | entry->subtuples = q-p; |
1224 | 1266 | ||
1225 | return CS_SUCCESS; | 1267 | return 0; |
1226 | } | 1268 | } |
1227 | 1269 | ||
1228 | #endif | 1270 | #endif |
@@ -1248,7 +1290,7 @@ static int parse_device_geo(tuple_t *tuple, cistpl_device_geo_t *geo) | |||
1248 | p += 6; | 1290 | p += 6; |
1249 | } | 1291 | } |
1250 | geo->ngeo = n; | 1292 | geo->ngeo = n; |
1251 | return CS_SUCCESS; | 1293 | return 0; |
1252 | } | 1294 | } |
1253 | 1295 | ||
1254 | /*====================================================================*/ | 1296 | /*====================================================================*/ |
@@ -1258,7 +1300,7 @@ static int parse_vers_2(tuple_t *tuple, cistpl_vers_2_t *v2) | |||
1258 | u_char *p, *q; | 1300 | u_char *p, *q; |
1259 | 1301 | ||
1260 | if (tuple->TupleDataLen < 10) | 1302 | if (tuple->TupleDataLen < 10) |
1261 | return CS_BAD_TUPLE; | 1303 | return -EINVAL; |
1262 | 1304 | ||
1263 | p = tuple->TupleData; | 1305 | p = tuple->TupleData; |
1264 | q = p + tuple->TupleDataLen; | 1306 | q = p + tuple->TupleDataLen; |
@@ -1282,15 +1324,18 @@ static int parse_org(tuple_t *tuple, cistpl_org_t *org) | |||
1282 | 1324 | ||
1283 | p = tuple->TupleData; | 1325 | p = tuple->TupleData; |
1284 | q = p + tuple->TupleDataLen; | 1326 | q = p + tuple->TupleDataLen; |
1285 | if (p == q) return CS_BAD_TUPLE; | 1327 | if (p == q) |
1328 | return -EINVAL; | ||
1286 | org->data_org = *p; | 1329 | org->data_org = *p; |
1287 | if (++p == q) return CS_BAD_TUPLE; | 1330 | if (++p == q) |
1331 | return -EINVAL; | ||
1288 | for (i = 0; i < 30; i++) { | 1332 | for (i = 0; i < 30; i++) { |
1289 | org->desc[i] = *p; | 1333 | org->desc[i] = *p; |
1290 | if (*p == '\0') break; | 1334 | if (*p == '\0') break; |
1291 | if (++p == q) return CS_BAD_TUPLE; | 1335 | if (++p == q) |
1336 | return -EINVAL; | ||
1292 | } | 1337 | } |
1293 | return CS_SUCCESS; | 1338 | return 0; |
1294 | } | 1339 | } |
1295 | 1340 | ||
1296 | /*====================================================================*/ | 1341 | /*====================================================================*/ |
@@ -1300,7 +1345,7 @@ static int parse_format(tuple_t *tuple, cistpl_format_t *fmt) | |||
1300 | u_char *p; | 1345 | u_char *p; |
1301 | 1346 | ||
1302 | if (tuple->TupleDataLen < 10) | 1347 | if (tuple->TupleDataLen < 10) |
1303 | return CS_BAD_TUPLE; | 1348 | return -EINVAL; |
1304 | 1349 | ||
1305 | p = tuple->TupleData; | 1350 | p = tuple->TupleData; |
1306 | 1351 | ||
@@ -1309,17 +1354,17 @@ static int parse_format(tuple_t *tuple, cistpl_format_t *fmt) | |||
1309 | fmt->offset = get_unaligned_le32(p + 2); | 1354 | fmt->offset = get_unaligned_le32(p + 2); |
1310 | fmt->length = get_unaligned_le32(p + 6); | 1355 | fmt->length = get_unaligned_le32(p + 6); |
1311 | 1356 | ||
1312 | return CS_SUCCESS; | 1357 | return 0; |
1313 | } | 1358 | } |
1314 | 1359 | ||
1315 | /*====================================================================*/ | 1360 | /*====================================================================*/ |
1316 | 1361 | ||
1317 | int pccard_parse_tuple(tuple_t *tuple, cisparse_t *parse) | 1362 | int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse) |
1318 | { | 1363 | { |
1319 | int ret = CS_SUCCESS; | 1364 | int ret = 0; |
1320 | 1365 | ||
1321 | if (tuple->TupleDataLen > tuple->TupleDataMax) | 1366 | if (tuple->TupleDataLen > tuple->TupleDataMax) |
1322 | return CS_BAD_TUPLE; | 1367 | return -EINVAL; |
1323 | switch (tuple->TupleCode) { | 1368 | switch (tuple->TupleCode) { |
1324 | case CISTPL_DEVICE: | 1369 | case CISTPL_DEVICE: |
1325 | case CISTPL_DEVICE_A: | 1370 | case CISTPL_DEVICE_A: |
@@ -1387,15 +1432,17 @@ int pccard_parse_tuple(tuple_t *tuple, cisparse_t *parse) | |||
1387 | break; | 1432 | break; |
1388 | case CISTPL_NO_LINK: | 1433 | case CISTPL_NO_LINK: |
1389 | case CISTPL_LINKTARGET: | 1434 | case CISTPL_LINKTARGET: |
1390 | ret = CS_SUCCESS; | 1435 | ret = 0; |
1391 | break; | 1436 | break; |
1392 | default: | 1437 | default: |
1393 | ret = CS_UNSUPPORTED_FUNCTION; | 1438 | ret = -EINVAL; |
1394 | break; | 1439 | break; |
1395 | } | 1440 | } |
1441 | if (ret) | ||
1442 | __cs_dbg(0, "parse_tuple failed %d\n", ret); | ||
1396 | return ret; | 1443 | return ret; |
1397 | } | 1444 | } |
1398 | EXPORT_SYMBOL(pccard_parse_tuple); | 1445 | EXPORT_SYMBOL(pcmcia_parse_tuple); |
1399 | 1446 | ||
1400 | /*====================================================================== | 1447 | /*====================================================================== |
1401 | 1448 | ||
@@ -1410,18 +1457,22 @@ int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t | |||
1410 | int ret; | 1457 | int ret; |
1411 | 1458 | ||
1412 | buf = kmalloc(256, GFP_KERNEL); | 1459 | buf = kmalloc(256, GFP_KERNEL); |
1413 | if (buf == NULL) | 1460 | if (buf == NULL) { |
1414 | return CS_OUT_OF_RESOURCE; | 1461 | dev_printk(KERN_WARNING, &s->dev, "no memory to read tuple\n"); |
1462 | return -ENOMEM; | ||
1463 | } | ||
1415 | tuple.DesiredTuple = code; | 1464 | tuple.DesiredTuple = code; |
1416 | tuple.Attributes = TUPLE_RETURN_COMMON; | 1465 | tuple.Attributes = TUPLE_RETURN_COMMON; |
1417 | ret = pccard_get_first_tuple(s, function, &tuple); | 1466 | ret = pccard_get_first_tuple(s, function, &tuple); |
1418 | if (ret != CS_SUCCESS) goto done; | 1467 | if (ret != 0) |
1468 | goto done; | ||
1419 | tuple.TupleData = buf; | 1469 | tuple.TupleData = buf; |
1420 | tuple.TupleOffset = 0; | 1470 | tuple.TupleOffset = 0; |
1421 | tuple.TupleDataMax = 255; | 1471 | tuple.TupleDataMax = 255; |
1422 | ret = pccard_get_tuple_data(s, &tuple); | 1472 | ret = pccard_get_tuple_data(s, &tuple); |
1423 | if (ret != CS_SUCCESS) goto done; | 1473 | if (ret != 0) |
1424 | ret = pccard_parse_tuple(&tuple, parse); | 1474 | goto done; |
1475 | ret = pcmcia_parse_tuple(&tuple, parse); | ||
1425 | done: | 1476 | done: |
1426 | kfree(buf); | 1477 | kfree(buf); |
1427 | return ret; | 1478 | return ret; |
@@ -1446,37 +1497,40 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, unsigned | |||
1446 | int ret, reserved, dev_ok = 0, ident_ok = 0; | 1497 | int ret, reserved, dev_ok = 0, ident_ok = 0; |
1447 | 1498 | ||
1448 | if (!s) | 1499 | if (!s) |
1449 | return CS_BAD_HANDLE; | 1500 | return -EINVAL; |
1450 | 1501 | ||
1451 | tuple = kmalloc(sizeof(*tuple), GFP_KERNEL); | 1502 | tuple = kmalloc(sizeof(*tuple), GFP_KERNEL); |
1452 | if (tuple == NULL) | 1503 | if (tuple == NULL) { |
1453 | return CS_OUT_OF_RESOURCE; | 1504 | dev_printk(KERN_WARNING, &s->dev, "no memory to validate CIS\n"); |
1505 | return -ENOMEM; | ||
1506 | } | ||
1454 | p = kmalloc(sizeof(*p), GFP_KERNEL); | 1507 | p = kmalloc(sizeof(*p), GFP_KERNEL); |
1455 | if (p == NULL) { | 1508 | if (p == NULL) { |
1456 | kfree(tuple); | 1509 | kfree(tuple); |
1457 | return CS_OUT_OF_RESOURCE; | 1510 | dev_printk(KERN_WARNING, &s->dev, "no memory to validate CIS\n"); |
1511 | return -ENOMEM; | ||
1458 | } | 1512 | } |
1459 | 1513 | ||
1460 | count = reserved = 0; | 1514 | count = reserved = 0; |
1461 | tuple->DesiredTuple = RETURN_FIRST_TUPLE; | 1515 | tuple->DesiredTuple = RETURN_FIRST_TUPLE; |
1462 | tuple->Attributes = TUPLE_RETURN_COMMON; | 1516 | tuple->Attributes = TUPLE_RETURN_COMMON; |
1463 | ret = pccard_get_first_tuple(s, function, tuple); | 1517 | ret = pccard_get_first_tuple(s, function, tuple); |
1464 | if (ret != CS_SUCCESS) | 1518 | if (ret != 0) |
1465 | goto done; | 1519 | goto done; |
1466 | 1520 | ||
1467 | /* First tuple should be DEVICE; we should really have either that | 1521 | /* First tuple should be DEVICE; we should really have either that |
1468 | or a CFTABLE_ENTRY of some sort */ | 1522 | or a CFTABLE_ENTRY of some sort */ |
1469 | if ((tuple->TupleCode == CISTPL_DEVICE) || | 1523 | if ((tuple->TupleCode == CISTPL_DEVICE) || |
1470 | (pccard_read_tuple(s, function, CISTPL_CFTABLE_ENTRY, p) == CS_SUCCESS) || | 1524 | (pccard_read_tuple(s, function, CISTPL_CFTABLE_ENTRY, p) == 0) || |
1471 | (pccard_read_tuple(s, function, CISTPL_CFTABLE_ENTRY_CB, p) == CS_SUCCESS)) | 1525 | (pccard_read_tuple(s, function, CISTPL_CFTABLE_ENTRY_CB, p) == 0)) |
1472 | dev_ok++; | 1526 | dev_ok++; |
1473 | 1527 | ||
1474 | /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2 | 1528 | /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2 |
1475 | tuple, for card identification. Certain old D-Link and Linksys | 1529 | tuple, for card identification. Certain old D-Link and Linksys |
1476 | cards have only a broken VERS_2 tuple; hence the bogus test. */ | 1530 | cards have only a broken VERS_2 tuple; hence the bogus test. */ |
1477 | if ((pccard_read_tuple(s, function, CISTPL_MANFID, p) == CS_SUCCESS) || | 1531 | if ((pccard_read_tuple(s, function, CISTPL_MANFID, p) == 0) || |
1478 | (pccard_read_tuple(s, function, CISTPL_VERS_1, p) == CS_SUCCESS) || | 1532 | (pccard_read_tuple(s, function, CISTPL_VERS_1, p) == 0) || |
1479 | (pccard_read_tuple(s, function, CISTPL_VERS_2, p) != CS_NO_MORE_ITEMS)) | 1533 | (pccard_read_tuple(s, function, CISTPL_VERS_2, p) != -ENOSPC)) |
1480 | ident_ok++; | 1534 | ident_ok++; |
1481 | 1535 | ||
1482 | if (!dev_ok && !ident_ok) | 1536 | if (!dev_ok && !ident_ok) |
@@ -1484,7 +1538,8 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, unsigned | |||
1484 | 1538 | ||
1485 | for (count = 1; count < MAX_TUPLES; count++) { | 1539 | for (count = 1; count < MAX_TUPLES; count++) { |
1486 | ret = pccard_get_next_tuple(s, function, tuple); | 1540 | ret = pccard_get_next_tuple(s, function, tuple); |
1487 | if (ret != CS_SUCCESS) break; | 1541 | if (ret != 0) |
1542 | break; | ||
1488 | if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) || | 1543 | if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) || |
1489 | ((tuple->TupleCode > 0x47) && (tuple->TupleCode < 0x80)) || | 1544 | ((tuple->TupleCode > 0x47) && (tuple->TupleCode < 0x80)) || |
1490 | ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff))) | 1545 | ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff))) |
@@ -1499,6 +1554,6 @@ done: | |||
1499 | *info = count; | 1554 | *info = count; |
1500 | kfree(tuple); | 1555 | kfree(tuple); |
1501 | kfree(p); | 1556 | kfree(p); |
1502 | return CS_SUCCESS; | 1557 | return 0; |
1503 | } | 1558 | } |
1504 | EXPORT_SYMBOL(pccard_validate_cis); | 1559 | EXPORT_SYMBOL(pccard_validate_cis); |