1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
| 702 static struct tnode *inflate(struct trie *t, struct tnode *tn) 703 { 704 struct tnode *oldtnode = tn; 705 int olen = tnode_child_length(tn); 706 int i; 707 708 pr_debug("In inflate\n"); 709 710 tn = tnode_new(oldtnode->key, oldtnode->pos, oldtnode->bits + 1); 711 712 if (!tn) 713 return ERR_PTR(-ENOMEM); 714 715
721 722 for (i = 0; i < olen; i++) { 723 struct tnode *inode; 724 725 inode = (struct tnode *) tnode_get_child(oldtnode, i); 726 if (inode && 727 IS_TNODE(inode) && 728 inode->pos == oldtnode->pos + oldtnode->bits && 729 inode->bits > 1) { 730 struct tnode *left, *right; 731 t_key m = ~0U << (KEYLENGTH - 1) >> inode->pos; 732 733 left = tnode_new(inode->key&(~m), inode->pos + 1, 734 inode->bits - 1); 735 if (!left) 736 goto nomem; 737 738 right = tnode_new(inode->key|m, inode->pos + 1, 739 inode->bits - 1); 740 741 if (!right) { 742 tnode_free(left); 743 goto nomem; 744 } 745 746 put_child(tn, 2*i, (struct rt_trie_node *) left); 747 put_child(tn, 2*i+1, (struct rt_trie_node *) right); 748 } 749 } 750 751 for (i = 0; i < olen; i++) { 752 struct tnode *inode; 753 struct rt_trie_node *node = tnode_get_child(oldtnode, i); 754 struct tnode *left, *right; 755 int size, j; 756 757 758 if (node == NULL) 759 continue; 760 761 762 763 if (IS_LEAF(node) || ((struct tnode *) node)->pos > 764 tn->pos + tn->bits - 1) { 765 put_child(tn, 766 tkey_extract_bits(node->key, oldtnode->pos, oldtnode->bits + 1), 767 node); 768 continue; 769 } 770 771 772 inode = (struct tnode *) node; 773 774 if (inode->bits == 1) { 775 put_child(tn, 2*i, rtnl_dereference(inode->child[0])); 776 put_child(tn, 2*i+1, rtnl_dereference(inode->child[1])); 777 778 tnode_free_safe(inode); 779 continue; 780 } 781 782 783 784
800 801
804 805 left = (struct tnode *) tnode_get_child(tn, 2*i); 806 put_child(tn, 2*i, NULL); 807 808 BUG_ON(!left); 809 810 right = (struct tnode *) tnode_get_child(tn, 2*i+1); 811 put_child(tn, 2*i+1, NULL); 812 813 BUG_ON(!right); 814 815 size = tnode_child_length(left); 816 for (j = 0; j < size; j++) { 817 put_child(left, j, rtnl_dereference(inode->child[j])); 818 put_child(right, j, rtnl_dereference(inode->child[j + size])); 819 } 820 put_child(tn, 2*i, resize(t, left)); 821 put_child(tn, 2*i+1, resize(t, right)); 822 823 tnode_free_safe(inode); 824 } 825 tnode_free_safe(oldtnode); 826 return tn; 827 nomem: 828 tnode_clean_free(tn); 829 return ERR_PTR(-ENOMEM); 830 }
|