diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Kconfig.debug | 147 | ||||
| -rw-r--r-- | lib/assoc_array.c | 51 | ||||
| -rw-r--r-- | lib/digsig.c | 6 | ||||
| -rw-r--r-- | lib/locking-selftest.c | 2 | ||||
| -rw-r--r-- | lib/scatterlist.c | 95 | ||||
| -rw-r--r-- | lib/ts_fsm.c | 2 | ||||
| -rw-r--r-- | lib/ts_kmp.c | 2 |
7 files changed, 168 insertions, 137 deletions
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 2689b7c50c52..dfdad67d8f6c 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
| @@ -1092,8 +1092,8 @@ config PROVE_LOCKING | |||
| 1092 | select DEBUG_MUTEXES | 1092 | select DEBUG_MUTEXES |
| 1093 | select DEBUG_RT_MUTEXES if RT_MUTEXES | 1093 | select DEBUG_RT_MUTEXES if RT_MUTEXES |
| 1094 | select DEBUG_LOCK_ALLOC | 1094 | select DEBUG_LOCK_ALLOC |
| 1095 | select LOCKDEP_CROSSRELEASE | 1095 | select LOCKDEP_CROSSRELEASE if BROKEN |
| 1096 | select LOCKDEP_COMPLETIONS | 1096 | select LOCKDEP_COMPLETIONS if BROKEN |
| 1097 | select TRACE_IRQFLAGS | 1097 | select TRACE_IRQFLAGS |
| 1098 | default n | 1098 | default n |
| 1099 | help | 1099 | help |
| @@ -1590,6 +1590,54 @@ config LATENCYTOP | |||
| 1590 | 1590 | ||
| 1591 | source kernel/trace/Kconfig | 1591 | source kernel/trace/Kconfig |
| 1592 | 1592 | ||
| 1593 | config PROVIDE_OHCI1394_DMA_INIT | ||
| 1594 | bool "Remote debugging over FireWire early on boot" | ||
| 1595 | depends on PCI && X86 | ||
| 1596 | help | ||
| 1597 | If you want to debug problems which hang or crash the kernel early | ||
| 1598 | on boot and the crashing machine has a FireWire port, you can use | ||
| 1599 | this feature to remotely access the memory of the crashed machine | ||
| 1600 | over FireWire. This employs remote DMA as part of the OHCI1394 | ||
| 1601 | specification which is now the standard for FireWire controllers. | ||
| 1602 | |||
| 1603 | With remote DMA, you can monitor the printk buffer remotely using | ||
| 1604 | firescope and access all memory below 4GB using fireproxy from gdb. | ||
| 1605 | Even controlling a kernel debugger is possible using remote DMA. | ||
| 1606 | |||
| 1607 | Usage: | ||
| 1608 | |||
| 1609 | If ohci1394_dma=early is used as boot parameter, it will initialize | ||
| 1610 | all OHCI1394 controllers which are found in the PCI config space. | ||
| 1611 | |||
| 1612 | As all changes to the FireWire bus such as enabling and disabling | ||
| 1613 | devices cause a bus reset and thereby disable remote DMA for all | ||
| 1614 | devices, be sure to have the cable plugged and FireWire enabled on | ||
| 1615 | the debugging host before booting the debug target for debugging. | ||
| 1616 | |||
| 1617 | This code (~1k) is freed after boot. By then, the firewire stack | ||
| 1618 | in charge of the OHCI-1394 controllers should be used instead. | ||
| 1619 | |||
| 1620 | See Documentation/debugging-via-ohci1394.txt for more information. | ||
| 1621 | |||
| 1622 | config DMA_API_DEBUG | ||
| 1623 | bool "Enable debugging of DMA-API usage" | ||
| 1624 | depends on HAVE_DMA_API_DEBUG | ||
| 1625 | help | ||
| 1626 | Enable this option to debug the use of the DMA API by device drivers. | ||
| 1627 | With this option you will be able to detect common bugs in device | ||
| 1628 | drivers like double-freeing of DMA mappings or freeing mappings that | ||
| 1629 | were never allocated. | ||
| 1630 | |||
| 1631 | This also attempts to catch cases where a page owned by DMA is | ||
| 1632 | accessed by the cpu in a way that could cause data corruption. For | ||
| 1633 | example, this enables cow_user_page() to check that the source page is | ||
| 1634 | not undergoing DMA. | ||
| 1635 | |||
| 1636 | This option causes a performance degradation. Use only if you want to | ||
| 1637 | debug device drivers and dma interactions. | ||
| 1638 | |||
| 1639 | If unsure, say N. | ||
| 1640 | |||
| 1593 | menu "Runtime Testing" | 1641 | menu "Runtime Testing" |
| 1594 | 1642 | ||
| 1595 | config LKDTM | 1643 | config LKDTM |
| @@ -1749,56 +1797,6 @@ config TEST_PARMAN | |||
| 1749 | 1797 | ||
| 1750 | If unsure, say N. | 1798 | If unsure, say N. |
| 1751 | 1799 | ||
| 1752 | endmenu # runtime tests | ||
| 1753 | |||
| 1754 | config PROVIDE_OHCI1394_DMA_INIT | ||
| 1755 | bool "Remote debugging over FireWire early on boot" | ||
| 1756 | depends on PCI && X86 | ||
| 1757 | help | ||
| 1758 | If you want to debug problems which hang or crash the kernel early | ||
| 1759 | on boot and the crashing machine has a FireWire port, you can use | ||
| 1760 | this feature to remotely access the memory of the crashed machine | ||
| 1761 | over FireWire. This employs remote DMA as part of the OHCI1394 | ||
| 1762 | specification which is now the standard for FireWire controllers. | ||
| 1763 | |||
| 1764 | With remote DMA, you can monitor the printk buffer remotely using | ||
| 1765 | firescope and access all memory below 4GB using fireproxy from gdb. | ||
| 1766 | Even controlling a kernel debugger is possible using remote DMA. | ||
| 1767 | |||
| 1768 | Usage: | ||
| 1769 | |||
| 1770 | If ohci1394_dma=early is used as boot parameter, it will initialize | ||
| 1771 | all OHCI1394 controllers which are found in the PCI config space. | ||
| 1772 | |||
| 1773 | As all changes to the FireWire bus such as enabling and disabling | ||
| 1774 | devices cause a bus reset and thereby disable remote DMA for all | ||
| 1775 | devices, be sure to have the cable plugged and FireWire enabled on | ||
| 1776 | the debugging host before booting the debug target for debugging. | ||
| 1777 | |||
| 1778 | This code (~1k) is freed after boot. By then, the firewire stack | ||
| 1779 | in charge of the OHCI-1394 controllers should be used instead. | ||
| 1780 | |||
| 1781 | See Documentation/debugging-via-ohci1394.txt for more information. | ||
| 1782 | |||
| 1783 | config DMA_API_DEBUG | ||
| 1784 | bool "Enable debugging of DMA-API usage" | ||
| 1785 | depends on HAVE_DMA_API_DEBUG | ||
| 1786 | help | ||
| 1787 | Enable this option to debug the use of the DMA API by device drivers. | ||
| 1788 | With this option you will be able to detect common bugs in device | ||
| 1789 | drivers like double-freeing of DMA mappings or freeing mappings that | ||
| 1790 | were never allocated. | ||
| 1791 | |||
| 1792 | This also attempts to catch cases where a page owned by DMA is | ||
| 1793 | accessed by the cpu in a way that could cause data corruption. For | ||
| 1794 | example, this enables cow_user_page() to check that the source page is | ||
| 1795 | not undergoing DMA. | ||
| 1796 | |||
| 1797 | This option causes a performance degradation. Use only if you want to | ||
| 1798 | debug device drivers and dma interactions. | ||
| 1799 | |||
| 1800 | If unsure, say N. | ||
| 1801 | |||
| 1802 | config TEST_LKM | 1800 | config TEST_LKM |
| 1803 | tristate "Test module loading with 'hello world' module" | 1801 | tristate "Test module loading with 'hello world' module" |
| 1804 | default n | 1802 | default n |
| @@ -1873,18 +1871,6 @@ config TEST_UDELAY | |||
| 1873 | 1871 | ||
| 1874 | If unsure, say N. | 1872 | If unsure, say N. |
| 1875 | 1873 | ||
| 1876 | config MEMTEST | ||
| 1877 | bool "Memtest" | ||
| 1878 | depends on HAVE_MEMBLOCK | ||
| 1879 | ---help--- | ||
| 1880 | This option adds a kernel parameter 'memtest', which allows memtest | ||
| 1881 | to be set. | ||
| 1882 | memtest=0, mean disabled; -- default | ||
| 1883 | memtest=1, mean do 1 test pattern; | ||
| 1884 | ... | ||
| 1885 | memtest=17, mean do 17 test patterns. | ||
| 1886 | If you are unsure how to answer this question, answer N. | ||
| 1887 | |||
| 1888 | config TEST_STATIC_KEYS | 1874 | config TEST_STATIC_KEYS |
| 1889 | tristate "Test static keys" | 1875 | tristate "Test static keys" |
| 1890 | default n | 1876 | default n |
| @@ -1894,16 +1880,6 @@ config TEST_STATIC_KEYS | |||
| 1894 | 1880 | ||
| 1895 | If unsure, say N. | 1881 | If unsure, say N. |
| 1896 | 1882 | ||
| 1897 | config BUG_ON_DATA_CORRUPTION | ||
| 1898 | bool "Trigger a BUG when data corruption is detected" | ||
| 1899 | select DEBUG_LIST | ||
| 1900 | help | ||
| 1901 | Select this option if the kernel should BUG when it encounters | ||
| 1902 | data corruption in kernel memory structures when they get checked | ||
| 1903 | for validity. | ||
| 1904 | |||
| 1905 | If unsure, say N. | ||
| 1906 | |||
| 1907 | config TEST_KMOD | 1883 | config TEST_KMOD |
| 1908 | tristate "kmod stress tester" | 1884 | tristate "kmod stress tester" |
| 1909 | default n | 1885 | default n |
| @@ -1941,6 +1917,29 @@ config TEST_DEBUG_VIRTUAL | |||
| 1941 | 1917 | ||
| 1942 | If unsure, say N. | 1918 | If unsure, say N. |
| 1943 | 1919 | ||
| 1920 | endmenu # runtime tests | ||
| 1921 | |||
| 1922 | config MEMTEST | ||
| 1923 | bool "Memtest" | ||
| 1924 | depends on HAVE_MEMBLOCK | ||
| 1925 | ---help--- | ||
| 1926 | This option adds a kernel parameter 'memtest', which allows memtest | ||
| 1927 | to be set. | ||
| 1928 | memtest=0, mean disabled; -- default | ||
| 1929 | memtest=1, mean do 1 test pattern; | ||
| 1930 | ... | ||
| 1931 | memtest=17, mean do 17 test patterns. | ||
| 1932 | If you are unsure how to answer this question, answer N. | ||
| 1933 | |||
| 1934 | config BUG_ON_DATA_CORRUPTION | ||
| 1935 | bool "Trigger a BUG when data corruption is detected" | ||
| 1936 | select DEBUG_LIST | ||
| 1937 | help | ||
| 1938 | Select this option if the kernel should BUG when it encounters | ||
| 1939 | data corruption in kernel memory structures when they get checked | ||
| 1940 | for validity. | ||
| 1941 | |||
| 1942 | If unsure, say N. | ||
| 1944 | 1943 | ||
| 1945 | source "samples/Kconfig" | 1944 | source "samples/Kconfig" |
| 1946 | 1945 | ||
diff --git a/lib/assoc_array.c b/lib/assoc_array.c index 155c55d8db5f..4e53be8bc590 100644 --- a/lib/assoc_array.c +++ b/lib/assoc_array.c | |||
| @@ -598,21 +598,31 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit, | |||
| 598 | if ((edit->segment_cache[ASSOC_ARRAY_FAN_OUT] ^ base_seg) == 0) | 598 | if ((edit->segment_cache[ASSOC_ARRAY_FAN_OUT] ^ base_seg) == 0) |
| 599 | goto all_leaves_cluster_together; | 599 | goto all_leaves_cluster_together; |
| 600 | 600 | ||
| 601 | /* Otherwise we can just insert a new node ahead of the old | 601 | /* Otherwise all the old leaves cluster in the same slot, but |
| 602 | * one. | 602 | * the new leaf wants to go into a different slot - so we |
| 603 | * create a new node (n0) to hold the new leaf and a pointer to | ||
| 604 | * a new node (n1) holding all the old leaves. | ||
| 605 | * | ||
| 606 | * This can be done by falling through to the node splitting | ||
| 607 | * path. | ||
| 603 | */ | 608 | */ |
| 604 | goto present_leaves_cluster_but_not_new_leaf; | 609 | pr_devel("present leaves cluster but not new leaf\n"); |
| 605 | } | 610 | } |
| 606 | 611 | ||
| 607 | split_node: | 612 | split_node: |
| 608 | pr_devel("split node\n"); | 613 | pr_devel("split node\n"); |
| 609 | 614 | ||
| 610 | /* We need to split the current node; we know that the node doesn't | 615 | /* We need to split the current node. The node must contain anything |
| 611 | * simply contain a full set of leaves that cluster together (it | 616 | * from a single leaf (in the one leaf case, this leaf will cluster |
| 612 | * contains meta pointers and/or non-clustering leaves). | 617 | * with the new leaf) and the rest meta-pointers, to all leaves, some |
| 618 | * of which may cluster. | ||
| 619 | * | ||
| 620 | * It won't contain the case in which all the current leaves plus the | ||
| 621 | * new leaves want to cluster in the same slot. | ||
| 613 | * | 622 | * |
| 614 | * We need to expel at least two leaves out of a set consisting of the | 623 | * We need to expel at least two leaves out of a set consisting of the |
| 615 | * leaves in the node and the new leaf. | 624 | * leaves in the node and the new leaf. The current meta pointers can |
| 625 | * just be copied as they shouldn't cluster with any of the leaves. | ||
| 616 | * | 626 | * |
| 617 | * We need a new node (n0) to replace the current one and a new node to | 627 | * We need a new node (n0) to replace the current one and a new node to |
| 618 | * take the expelled nodes (n1). | 628 | * take the expelled nodes (n1). |
| @@ -717,33 +727,6 @@ found_slot_for_multiple_occupancy: | |||
| 717 | pr_devel("<--%s() = ok [split node]\n", __func__); | 727 | pr_devel("<--%s() = ok [split node]\n", __func__); |
| 718 | return true; | 728 | return true; |
| 719 | 729 | ||
| 720 | present_leaves_cluster_but_not_new_leaf: | ||
| 721 | /* All the old leaves cluster in the same slot, but the new leaf wants | ||
| 722 | * to go into a different slot, so we create a new node to hold the new | ||
| 723 | * leaf and a pointer to a new node holding all the old leaves. | ||
| 724 | */ | ||
| 725 | pr_devel("present leaves cluster but not new leaf\n"); | ||
| 726 | |||
| 727 | new_n0->back_pointer = node->back_pointer; | ||
| 728 | new_n0->parent_slot = node->parent_slot; | ||
| 729 | new_n0->nr_leaves_on_branch = node->nr_leaves_on_branch; | ||
| 730 | new_n1->back_pointer = assoc_array_node_to_ptr(new_n0); | ||
| 731 | new_n1->parent_slot = edit->segment_cache[0]; | ||
| 732 | new_n1->nr_leaves_on_branch = node->nr_leaves_on_branch; | ||
| 733 | edit->adjust_count_on = new_n0; | ||
| 734 | |||
| 735 | for (i = 0; i < ASSOC_ARRAY_FAN_OUT; i++) | ||
| 736 | new_n1->slots[i] = node->slots[i]; | ||
| 737 | |||
| 738 | new_n0->slots[edit->segment_cache[0]] = assoc_array_node_to_ptr(new_n0); | ||
| 739 | edit->leaf_p = &new_n0->slots[edit->segment_cache[ASSOC_ARRAY_FAN_OUT]]; | ||
| 740 | |||
| 741 | edit->set[0].ptr = &assoc_array_ptr_to_node(node->back_pointer)->slots[node->parent_slot]; | ||
| 742 | edit->set[0].to = assoc_array_node_to_ptr(new_n0); | ||
| 743 | edit->excised_meta[0] = assoc_array_node_to_ptr(node); | ||
| 744 | pr_devel("<--%s() = ok [insert node before]\n", __func__); | ||
| 745 | return true; | ||
| 746 | |||
| 747 | all_leaves_cluster_together: | 730 | all_leaves_cluster_together: |
| 748 | /* All the leaves, new and old, want to cluster together in this node | 731 | /* All the leaves, new and old, want to cluster together in this node |
| 749 | * in the same slot, so we have to replace this node with a shortcut to | 732 | * in the same slot, so we have to replace this node with a shortcut to |
diff --git a/lib/digsig.c b/lib/digsig.c index 03d7c63837ae..6ba6fcd92dd1 100644 --- a/lib/digsig.c +++ b/lib/digsig.c | |||
| @@ -87,6 +87,12 @@ static int digsig_verify_rsa(struct key *key, | |||
| 87 | down_read(&key->sem); | 87 | down_read(&key->sem); |
| 88 | ukp = user_key_payload_locked(key); | 88 | ukp = user_key_payload_locked(key); |
| 89 | 89 | ||
| 90 | if (!ukp) { | ||
| 91 | /* key was revoked before we acquired its semaphore */ | ||
| 92 | err = -EKEYREVOKED; | ||
| 93 | goto err1; | ||
| 94 | } | ||
| 95 | |||
| 90 | if (ukp->datalen < sizeof(*pkh)) | 96 | if (ukp->datalen < sizeof(*pkh)) |
| 91 | goto err1; | 97 | goto err1; |
| 92 | 98 | ||
diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c index cd0b5c964bd0..2b827b8a1d8c 100644 --- a/lib/locking-selftest.c +++ b/lib/locking-selftest.c | |||
| @@ -2031,11 +2031,13 @@ void locking_selftest(void) | |||
| 2031 | print_testname("mixed read-lock/lock-write ABBA"); | 2031 | print_testname("mixed read-lock/lock-write ABBA"); |
| 2032 | pr_cont(" |"); | 2032 | pr_cont(" |"); |
| 2033 | dotest(rlock_ABBA1, FAILURE, LOCKTYPE_RWLOCK); | 2033 | dotest(rlock_ABBA1, FAILURE, LOCKTYPE_RWLOCK); |
| 2034 | #ifdef CONFIG_PROVE_LOCKING | ||
| 2034 | /* | 2035 | /* |
| 2035 | * Lockdep does indeed fail here, but there's nothing we can do about | 2036 | * Lockdep does indeed fail here, but there's nothing we can do about |
| 2036 | * that now. Don't kill lockdep for it. | 2037 | * that now. Don't kill lockdep for it. |
| 2037 | */ | 2038 | */ |
| 2038 | unexpected_testcase_failures--; | 2039 | unexpected_testcase_failures--; |
| 2040 | #endif | ||
| 2039 | 2041 | ||
| 2040 | pr_cont(" |"); | 2042 | pr_cont(" |"); |
| 2041 | dotest(rwsem_ABBA1, FAILURE, LOCKTYPE_RWSEM); | 2043 | dotest(rwsem_ABBA1, FAILURE, LOCKTYPE_RWSEM); |
diff --git a/lib/scatterlist.c b/lib/scatterlist.c index be7b4dd6b68d..7c1c55f7daaa 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c | |||
| @@ -370,41 +370,49 @@ int sg_alloc_table(struct sg_table *table, unsigned int nents, gfp_t gfp_mask) | |||
| 370 | EXPORT_SYMBOL(sg_alloc_table); | 370 | EXPORT_SYMBOL(sg_alloc_table); |
| 371 | 371 | ||
| 372 | /** | 372 | /** |
| 373 | * sg_alloc_table_from_pages - Allocate and initialize an sg table from | 373 | * __sg_alloc_table_from_pages - Allocate and initialize an sg table from |
| 374 | * an array of pages | 374 | * an array of pages |
| 375 | * @sgt: The sg table header to use | 375 | * @sgt: The sg table header to use |
| 376 | * @pages: Pointer to an array of page pointers | 376 | * @pages: Pointer to an array of page pointers |
| 377 | * @n_pages: Number of pages in the pages array | 377 | * @n_pages: Number of pages in the pages array |
| 378 | * @offset: Offset from start of the first page to the start of a buffer | 378 | * @offset: Offset from start of the first page to the start of a buffer |
| 379 | * @size: Number of valid bytes in the buffer (after offset) | 379 | * @size: Number of valid bytes in the buffer (after offset) |
| 380 | * @gfp_mask: GFP allocation mask | 380 | * @max_segment: Maximum size of a scatterlist node in bytes (page aligned) |
| 381 | * @gfp_mask: GFP allocation mask | ||
| 381 | * | 382 | * |
| 382 | * Description: | 383 | * Description: |
| 383 | * Allocate and initialize an sg table from a list of pages. Contiguous | 384 | * Allocate and initialize an sg table from a list of pages. Contiguous |
| 384 | * ranges of the pages are squashed into a single scatterlist node. A user | 385 | * ranges of the pages are squashed into a single scatterlist node up to the |
| 385 | * may provide an offset at a start and a size of valid data in a buffer | 386 | * maximum size specified in @max_segment. An user may provide an offset at a |
| 386 | * specified by the page array. The returned sg table is released by | 387 | * start and a size of valid data in a buffer specified by the page array. |
| 387 | * sg_free_table. | 388 | * The returned sg table is released by sg_free_table. |
| 388 | * | 389 | * |
| 389 | * Returns: | 390 | * Returns: |
| 390 | * 0 on success, negative error on failure | 391 | * 0 on success, negative error on failure |
| 391 | */ | 392 | */ |
| 392 | int sg_alloc_table_from_pages(struct sg_table *sgt, | 393 | int __sg_alloc_table_from_pages(struct sg_table *sgt, struct page **pages, |
| 393 | struct page **pages, unsigned int n_pages, | 394 | unsigned int n_pages, unsigned int offset, |
| 394 | unsigned long offset, unsigned long size, | 395 | unsigned long size, unsigned int max_segment, |
| 395 | gfp_t gfp_mask) | 396 | gfp_t gfp_mask) |
| 396 | { | 397 | { |
| 397 | unsigned int chunks; | 398 | unsigned int chunks, cur_page, seg_len, i; |
| 398 | unsigned int i; | ||
| 399 | unsigned int cur_page; | ||
| 400 | int ret; | 399 | int ret; |
| 401 | struct scatterlist *s; | 400 | struct scatterlist *s; |
| 402 | 401 | ||
| 402 | if (WARN_ON(!max_segment || offset_in_page(max_segment))) | ||
| 403 | return -EINVAL; | ||
| 404 | |||
| 403 | /* compute number of contiguous chunks */ | 405 | /* compute number of contiguous chunks */ |
| 404 | chunks = 1; | 406 | chunks = 1; |
| 405 | for (i = 1; i < n_pages; ++i) | 407 | seg_len = 0; |
| 406 | if (page_to_pfn(pages[i]) != page_to_pfn(pages[i - 1]) + 1) | 408 | for (i = 1; i < n_pages; i++) { |
| 407 | ++chunks; | 409 | seg_len += PAGE_SIZE; |
| 410 | if (seg_len >= max_segment || | ||
| 411 | page_to_pfn(pages[i]) != page_to_pfn(pages[i - 1]) + 1) { | ||
| 412 | chunks++; | ||
| 413 | seg_len = 0; | ||
| 414 | } | ||
| 415 | } | ||
| 408 | 416 | ||
| 409 | ret = sg_alloc_table(sgt, chunks, gfp_mask); | 417 | ret = sg_alloc_table(sgt, chunks, gfp_mask); |
| 410 | if (unlikely(ret)) | 418 | if (unlikely(ret)) |
| @@ -413,17 +421,21 @@ int sg_alloc_table_from_pages(struct sg_table *sgt, | |||
| 413 | /* merging chunks and putting them into the scatterlist */ | 421 | /* merging chunks and putting them into the scatterlist */ |
| 414 | cur_page = 0; | 422 | cur_page = 0; |
| 415 | for_each_sg(sgt->sgl, s, sgt->orig_nents, i) { | 423 | for_each_sg(sgt->sgl, s, sgt->orig_nents, i) { |
| 416 | unsigned long chunk_size; | 424 | unsigned int j, chunk_size; |
| 417 | unsigned int j; | ||
| 418 | 425 | ||
| 419 | /* look for the end of the current chunk */ | 426 | /* look for the end of the current chunk */ |
| 420 | for (j = cur_page + 1; j < n_pages; ++j) | 427 | seg_len = 0; |
| 421 | if (page_to_pfn(pages[j]) != | 428 | for (j = cur_page + 1; j < n_pages; j++) { |
| 429 | seg_len += PAGE_SIZE; | ||
| 430 | if (seg_len >= max_segment || | ||
| 431 | page_to_pfn(pages[j]) != | ||
| 422 | page_to_pfn(pages[j - 1]) + 1) | 432 | page_to_pfn(pages[j - 1]) + 1) |
| 423 | break; | 433 | break; |
| 434 | } | ||
| 424 | 435 | ||
| 425 | chunk_size = ((j - cur_page) << PAGE_SHIFT) - offset; | 436 | chunk_size = ((j - cur_page) << PAGE_SHIFT) - offset; |
| 426 | sg_set_page(s, pages[cur_page], min(size, chunk_size), offset); | 437 | sg_set_page(s, pages[cur_page], |
| 438 | min_t(unsigned long, size, chunk_size), offset); | ||
| 427 | size -= chunk_size; | 439 | size -= chunk_size; |
| 428 | offset = 0; | 440 | offset = 0; |
| 429 | cur_page = j; | 441 | cur_page = j; |
| @@ -431,6 +443,35 @@ int sg_alloc_table_from_pages(struct sg_table *sgt, | |||
| 431 | 443 | ||
| 432 | return 0; | 444 | return 0; |
| 433 | } | 445 | } |
| 446 | EXPORT_SYMBOL(__sg_alloc_table_from_pages); | ||
| 447 | |||
| 448 | /** | ||
| 449 | * sg_alloc_table_from_pages - Allocate and initialize an sg table from | ||
| 450 | * an array of pages | ||
| 451 | * @sgt: The sg table header to use | ||
| 452 | * @pages: Pointer to an array of page pointers | ||
| 453 | * @n_pages: Number of pages in the pages array | ||
| 454 | * @offset: Offset from start of the first page to the start of a buffer | ||
| 455 | * @size: Number of valid bytes in the buffer (after offset) | ||
| 456 | * @gfp_mask: GFP allocation mask | ||
| 457 | * | ||
| 458 | * Description: | ||
| 459 | * Allocate and initialize an sg table from a list of pages. Contiguous | ||
| 460 | * ranges of the pages are squashed into a single scatterlist node. A user | ||
| 461 | * may provide an offset at a start and a size of valid data in a buffer | ||
| 462 | * specified by the page array. The returned sg table is released by | ||
| 463 | * sg_free_table. | ||
| 464 | * | ||
| 465 | * Returns: | ||
| 466 | * 0 on success, negative error on failure | ||
| 467 | */ | ||
| 468 | int sg_alloc_table_from_pages(struct sg_table *sgt, struct page **pages, | ||
| 469 | unsigned int n_pages, unsigned int offset, | ||
| 470 | unsigned long size, gfp_t gfp_mask) | ||
| 471 | { | ||
| 472 | return __sg_alloc_table_from_pages(sgt, pages, n_pages, offset, size, | ||
| 473 | SCATTERLIST_MAX_SEGMENT, gfp_mask); | ||
| 474 | } | ||
| 434 | EXPORT_SYMBOL(sg_alloc_table_from_pages); | 475 | EXPORT_SYMBOL(sg_alloc_table_from_pages); |
| 435 | 476 | ||
| 436 | void __sg_page_iter_start(struct sg_page_iter *piter, | 477 | void __sg_page_iter_start(struct sg_page_iter *piter, |
diff --git a/lib/ts_fsm.c b/lib/ts_fsm.c index 5696a35184e4..69557c74ef9f 100644 --- a/lib/ts_fsm.c +++ b/lib/ts_fsm.c | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | * ========================================================================== | 11 | * ========================================================================== |
| 12 | * | 12 | * |
| 13 | * A finite state machine consists of n states (struct ts_fsm_token) | 13 | * A finite state machine consists of n states (struct ts_fsm_token) |
| 14 | * representing the pattern as a finite automation. The data is read | 14 | * representing the pattern as a finite automaton. The data is read |
| 15 | * sequentially on an octet basis. Every state token specifies the number | 15 | * sequentially on an octet basis. Every state token specifies the number |
| 16 | * of recurrences and the type of value accepted which can be either a | 16 | * of recurrences and the type of value accepted which can be either a |
| 17 | * specific character or ctype based set of characters. The available | 17 | * specific character or ctype based set of characters. The available |
diff --git a/lib/ts_kmp.c b/lib/ts_kmp.c index 632f783e65f1..ffbe66cbb0ed 100644 --- a/lib/ts_kmp.c +++ b/lib/ts_kmp.c | |||
| @@ -27,7 +27,7 @@ | |||
| 27 | * | 27 | * |
| 28 | * [1] Cormen, Leiserson, Rivest, Stein | 28 | * [1] Cormen, Leiserson, Rivest, Stein |
| 29 | * Introdcution to Algorithms, 2nd Edition, MIT Press | 29 | * Introdcution to Algorithms, 2nd Edition, MIT Press |
| 30 | * [2] See finite automation theory | 30 | * [2] See finite automaton theory |
| 31 | */ | 31 | */ |
| 32 | 32 | ||
| 33 | #include <linux/module.h> | 33 | #include <linux/module.h> |
