1. 06 Jun, 2018 1 commit
    • Kees Cook's avatar
      treewide: Use struct_size() for devm_kmalloc() and friends · 0ed2dd03
      Kees Cook authored
      Replaces open-coded struct size calculations with struct_size() for
      devm_*, f2fs_*, and sock_* allocations. Automatically generated (and
      manually adjusted) from the following Coccinelle script:
      
      // Direct reference to struct field.
      @@
      identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
      expression HANDLE;
      expression GFP;
      identifier VAR, ELEMENT;
      expression COUNT;
      @@
      
      - alloc(HANDLE, sizeof(*VAR) + COUNT * sizeof(*VAR->ELEMENT), GFP)
      + alloc(HANDLE, struct_size(VAR, ELEMENT, COUNT), GFP)
      
      // mr = kzalloc(sizeof(*mr) + m * sizeof(mr->map[0]), GFP_KERNEL);
      @@
      identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
      expression HANDLE;
      expression GFP;
      identifier VAR, ELEMENT;
      expression COUNT;
      @@
      
      - alloc(HANDLE, sizeof(*VAR) + COUNT * sizeof(VAR->ELEMENT[0]), GFP)
      + alloc(HANDLE, struct_size(VAR, ELEMENT, COUNT), GFP)
      
      // Same pattern, but can't trivially locate the trailing element name,
      // or variable name.
      @@
      identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
      expression HANDLE;
      expression GFP;
      expression SOMETHING, COUNT, ELEMENT;
      @@
      
      - alloc(HANDLE, sizeof(SOMETHING) + COUNT * sizeof(ELEMENT), GFP)
      + alloc(HANDLE, CHECKME_struct_size(&SOMETHING, ELEMENT, COUNT), GFP)
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      0ed2dd03
  2. 06 Apr, 2018 1 commit
  3. 19 Mar, 2018 2 commits
  4. 25 Sep, 2017 1 commit
  5. 02 Jun, 2017 3 commits
  6. 21 Jan, 2017 3 commits
  7. 12 Dec, 2016 1 commit
  8. 08 Dec, 2016 3 commits
  9. 23 Nov, 2016 1 commit
  10. 17 Oct, 2016 1 commit
  11. 15 Sep, 2016 1 commit
  12. 07 Sep, 2016 4 commits
  13. 20 Apr, 2016 2 commits
  14. 17 Mar, 2016 11 commits
  15. 03 Mar, 2016 1 commit
  16. 26 Feb, 2016 1 commit
  17. 16 Feb, 2016 2 commits
  18. 25 Dec, 2015 1 commit