]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - lib/bitmap.c
lib/genalloc.c: fix allocation of aligned buffer from non-aligned chunk
[mirror_ubuntu-bionic-kernel.git] / lib / bitmap.c
index d8f0c094b18eba130571a3e405796040750d9646..3deb9de0abb992c13aec7d1e7cf3f5637188cef3 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/bitops.h>
 #include <linux/bug.h>
 #include <linux/kernel.h>
+#include <linux/mm.h>
 #include <linux/string.h>
 #include <linux/uaccess.h>
 
@@ -468,14 +469,15 @@ EXPORT_SYMBOL(bitmap_parse_user);
  * ranges if list is specified or hex digits grouped into comma-separated
  * sets of 8 digits/set. Returns the number of characters written to buf.
  *
- * It is assumed that @buf is a pointer into a PAGE_SIZE area and that
- * sufficient storage remains at @buf to accommodate the
- * bitmap_print_to_pagebuf() output.
+ * It is assumed that @buf is a pointer into a PAGE_SIZE, page-aligned
+ * area and that sufficient storage remains at @buf to accommodate the
+ * bitmap_print_to_pagebuf() output. Returns the number of characters
+ * actually printed to @buf, excluding terminating '\0'.
  */
 int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp,
                            int nmaskbits)
 {
-       ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf;
+       ptrdiff_t len = PAGE_SIZE - offset_in_page(buf);
        int n = 0;
 
        if (len > 1)
@@ -607,7 +609,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
                /* if no digit is after '-', it's wrong*/
                if (at_start && in_range)
                        return -EINVAL;
-               if (!(a <= b) || !(used_size <= group_size))
+               if (!(a <= b) || group_size == 0 || !(used_size <= group_size))
                        return -EINVAL;
                if (b >= nmaskbits)
                        return -ERANGE;