Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • L linux
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Kirill Smelkov
  • linux
  • Repository
  • linux
  • kernel
  • module.c
Find file BlameHistoryPermalink
  • Gustavo A. R. Silva's avatar
    kernel: module: Use struct_size() helper · 2bcda838
    Gustavo A. R. Silva authored Jun 06, 2019
    commit 8d1b73dd
    
     upstream.
    
    One of the more common cases of allocation size calculations is finding
    the size of a structure that has a zero-sized array at the end, along
    with memory for some number of elements for that array. For example:
    
    struct module_sect_attrs {
    	...
            struct module_sect_attr attrs[0];
    };
    
    Make use of the struct_size() helper instead of an open-coded version
    in order to avoid any potential type mistakes.
    
    So, replace the following form:
    
    sizeof(*sect_attrs) + nloaded * sizeof(sect_attrs->attrs[0]
    
    with:
    
    struct_size(sect_attrs, attrs, nloaded)
    
    This code was detected with the help of Coccinelle.
    
    Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
    Signed-off-by: default avatarJessica Yu <jeyu@kernel.org>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    2bcda838
GitLab Nexedi Edition | About GitLab | About Nexedi | 沪ICP备2021021310号-2 | 沪ICP备2021021310号-7