• Jakub Kicinski's avatar
    ethtool: netlink: handle SET intro/outro in the common code · 99132b6e
    Jakub Kicinski authored
    Most ethtool SET callbacks follow the same general structure.
    
      ethnl_parse_header_dev_get()
      rtnl_lock()
      ethnl_ops_begin()
    
      ... do stuff ...
    
      ethtool_notify()
      ethnl_ops_complete()
      rtnl_unlock()
      ethnl_parse_header_dev_put()
    
    This leads to a lot of copy / pasted code an bugs when people
    mis-handle the error path.
    
    Add a generic implementation of this pattern with a .set callback
    in struct ethnl_request_ops called to "do stuff".
    
    Also add an optional .set_validate which is called before
    ethnl_ops_begin() -- a lot of implementations do basic request
    capability / sanity checking at that point.
    
    Because we want to avoid generating the notification when
    no change happened - adopt a slightly hairy return values:
     - 0 means nothing to do (no notification)
     - 1 means done / continue
     - negative error codes on error
    
    Reuse .hdr_attr from struct ethnl_request_ops, GET and SET
    use the same attr spaces in all cases.
    
    Convert pause as an example (and to avoid unused function warnings).
    Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    99132b6e
netlink.h 19.5 KB