diff mbox series

[net,4/4] net: Comment copy_from_sockptr() explaining its behaviour

Message ID 20241115-sockptr-copy-fixes-v1-4-d183c87fcbd5@rbox.co (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series net: Fix some callers of copy_from_sockptr() | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 202 this patch: 202
netdev/build_tools success Errors and warnings before: 0 (+0) this patch: 0 (+0)
netdev/cc_maintainers warning 1 maintainers not CCed: surenb@google.com
netdev/build_clang success Errors and warnings before: 253 this patch: 253
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 6962 this patch: 6962
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest pending net-next-2024-11-15--03-00 (tests: 0)

Commit Message

Michal Luczaj Nov. 14, 2024, 11:27 p.m. UTC
copy_from_sockptr() has a history of misuse. Add a comment explaining that
the function follows API of copy_from_user(), i.e. returns 0 for success,
or number of bytes not copied on error.

Signed-off-by: Michal Luczaj <mhal@rbox.co>
---
 include/linux/sockptr.h | 2 ++
 1 file changed, 2 insertions(+)

Comments

David Wei Nov. 15, 2024, 2:43 a.m. UTC | #1
On 2024-11-14 15:27, Michal Luczaj wrote:
> copy_from_sockptr() has a history of misuse. Add a comment explaining that
> the function follows API of copy_from_user(), i.e. returns 0 for success,
> or number of bytes not copied on error.
> 
> Signed-off-by: Michal Luczaj <mhal@rbox.co>
> ---
>  include/linux/sockptr.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/include/linux/sockptr.h b/include/linux/sockptr.h
> index 195debe2b1dbc5abf768aa806eb6c73b99421e27..3e6c8e9d67aef66e8ac5a4e474c278ac08244163 100644
> --- a/include/linux/sockptr.h
> +++ b/include/linux/sockptr.h
> @@ -53,6 +53,8 @@ static inline int copy_from_sockptr_offset(void *dst, sockptr_t src,
>  /* Deprecated.
>   * This is unsafe, unless caller checked user provided optlen.
>   * Prefer copy_safe_from_sockptr() instead.
> + *
> + * Returns 0 for success, or number of bytes not copied on error.
>   */
>  static inline int copy_from_sockptr(void *dst, sockptr_t src, size_t size)
>  {
> 

In addition to this, please update the docs for copy_safe_from_sockptr()
that calls into copy_from_sockptr() which also contains the
misunderstanding of what copy_from_sockptr() returns.
diff mbox series

Patch

diff --git a/include/linux/sockptr.h b/include/linux/sockptr.h
index 195debe2b1dbc5abf768aa806eb6c73b99421e27..3e6c8e9d67aef66e8ac5a4e474c278ac08244163 100644
--- a/include/linux/sockptr.h
+++ b/include/linux/sockptr.h
@@ -53,6 +53,8 @@  static inline int copy_from_sockptr_offset(void *dst, sockptr_t src,
 /* Deprecated.
  * This is unsafe, unless caller checked user provided optlen.
  * Prefer copy_safe_from_sockptr() instead.
+ *
+ * Returns 0 for success, or number of bytes not copied on error.
  */
 static inline int copy_from_sockptr(void *dst, sockptr_t src, size_t size)
 {