The patch titled Subject: random-simplify-api-for-random-address-requests-v2 has been added to the -mm tree. Its filename is random-simplify-api-for-random-address-requests-v2.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/random-simplify-api-for-random-address-requests-v2.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/random-simplify-api-for-random-address-requests-v2.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Jason Cooper <jason@xxxxxxxxxxxxxx> Subject: random-simplify-api-for-random-address-requests-v2 s/randomize_page/randomize_addr/ Link: http://lkml.kernel.org/r/20160728204730.27453-2-jason@xxxxxxxxxxxxxx Signed-off-by: Jason Cooper <jason@xxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- drivers/char/random.c | 23 ++++++++--------------- include/linux/random.h | 2 +- 2 files changed, 9 insertions(+), 16 deletions(-) diff -puN drivers/char/random.c~random-simplify-api-for-random-address-requests-v2 drivers/char/random.c --- a/drivers/char/random.c~random-simplify-api-for-random-address-requests-v2 +++ a/drivers/char/random.c @@ -2120,36 +2120,29 @@ randomize_range(unsigned long start, uns } /** - * randomize_page - Generate a random, page aligned address + * randomize_addr - Generate a random, page aligned address * @start: The smallest acceptable address the caller will take. * @range: The size of the area, starting at @start, within which the * random address must fall. * - * If @start + @range would overflow, @range is capped. + * Before page alignment, the random address generated can be any value from + * @start, to @start + @range - 1 inclusive. * - * NOTE: Historical use of randomize_range, which this replaces, presumed that - * @start was already page aligned. We now align it regardless. + * If @start + @range would overflow, @range is capped. * * Return: A page aligned address within [start, start + range). On error, * @start is returned. */ unsigned long -randomize_page(unsigned long start, unsigned long range) +randomize_addr(unsigned long start, unsigned long range) { - if (!PAGE_ALIGNED(start)) { - range -= PAGE_ALIGN(start) - start; - start = PAGE_ALIGN(start); - } + if (range == 0) + return start; if (start > ULONG_MAX - range) range = ULONG_MAX - start; - range >>= PAGE_SHIFT; - - if (range == 0) - return start; - - return start + (get_random_long() % range << PAGE_SHIFT); + return PAGE_ALIGN(get_random_long() % range + start); } /* Interface for in-kernel drivers of true hardware RNGs. diff -puN include/linux/random.h~random-simplify-api-for-random-address-requests-v2 include/linux/random.h --- a/include/linux/random.h~random-simplify-api-for-random-address-requests-v2 +++ a/include/linux/random.h @@ -35,7 +35,7 @@ extern const struct file_operations rand unsigned int get_random_int(void); unsigned long get_random_long(void); unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len); -unsigned long randomize_page(unsigned long start, unsigned long range); +unsigned long randomize_addr(unsigned long start, unsigned long range); u32 prandom_u32(void); void prandom_bytes(void *buf, size_t nbytes); _ Patches currently in -mm which might be from jason@xxxxxxxxxxxxxx are random-simplify-api-for-random-address-requests.patch random-simplify-api-for-random-address-requests-v2.patch x86-use-simpler-api-for-random-address-requests.patch x86-use-simpler-api-for-random-address-requests-v2.patch arm-use-simpler-api-for-random-address-requests.patch arm-use-simpler-api-for-random-address-requests-v2.patch arm64-use-simpler-api-for-random-address-requests.patch arm64-use-simpler-api-for-random-address-requests-v2.patch tile-use-simpler-api-for-random-address-requests.patch tile-use-simpler-api-for-random-address-requests-v2.patch unicore32-use-simpler-api-for-random-address-requests.patch unicore32-use-simpler-api-for-random-address-requests-v2.patch random-remove-unused-randomize_range.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html