IB/uverbs: clean up INIT_UDATA_BUF_OR_NULL usage
PATCH v2 1/2 IB/uverbs: clean up INIT_UDATA_BUF_OR_NULL usage
We get a harmless warning about the fact that we use the result of a multiplication as a condition:
drivers/infiniband/core/uverbs_main.c: In function 'ib_uverbs_write':drivers/infiniband/core/uverbs_main.c:787:40: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context] drivers/infiniband/core/uverbs_main.c:787:117: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context] drivers/infiniband/core/uverbs_main.c:790:50: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context] drivers/infiniband/core/uverbs_main.c:790:151: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context]
This avoids the problem by using an inline function in place of the macro.
---
v2: completely rewrite the patch to a larger cleanup.
--- drivers/infiniband/core/uverbs.h | 15 ++++++++------- drivers/infiniband/core/uverbs_main.c | 22 ++++++++++------------ drivers/infiniband/core/uverbs_std_types.c | 3 ++- 3 files changed, 20 insertions(+), 20 deletions(-)
drivers/infiniband/core/uverbs.h +8 -7
@@ -55,13 +55,14 @@ (udata)->outlen = (olen); \ }while (0 ) -#define INIT_UDATA_BUF_OR_NULL (udata, ibuf, obuf, ilen, olen) \ - do { \ - (udata)->inbuf = (ilen) ? (const void __user *) (ibuf) : NULL; \ - (udata)->outbuf = (olen) ? (void __user *) (obuf) : NULL; \ - (udata)->inlen = (ilen); \ - (udata)->outlen = (olen); \ - } while (0) +static inline void +ib_uverbs_init_udata_buf_or_null (struct ib_udata *udata, +const void __user *ibuf, +void __user *obuf, +size_t ilen,size_t olen) +{ +INIT_UDATA (udata, ilen ? ibuf :NULL , olen ? obuf :NULL , ilen, olen); +}/* * Our lifetime rules for these structs are the following:
drivers/infiniband/core/uverbs_main.c +10 -12
@@ -763,7 +763,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, }if (!access_ok (VERIFY_WRITE , - (void __user *) (unsigned long ) ex_hdr.response, +u64_to_user_ptr (ex_hdr.response), (hdr.out_words + ex_hdr.provider_out_words) *8 )) { ret = -EFAULT ; goto out;
@@ -775,19 +775,17 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, } } -INIT_UDATA_BUF_OR_NULL (&ucore, buf, (unsigned long ) ex_hdr.response, - hdr.in_words *8 , hdr.out_words *8 ); +ib_uverbs_init_udata_buf_or_null (&ucore, buf, +u64_to_user_ptr (ex_hdr.response), + hdr.in_words *8 , hdr.out_words *8 ); -INIT_UDATA_BUF_OR_NULL (&uhw, - buf + ucore.inlen, - (unsigned long ) ex_hdr.response + ucore.outlen, - ex_hdr.provider_in_words *8 , - ex_hdr.provider_out_words *8 ); +ib_uverbs_init_udata_buf_or_null (&uhw, + buf + ucore.inlen, +u64_to_user_ptr (ex_hdr.response) + ucore.outlen, + ex_hdr.provider_in_words *8 , + ex_hdr.provider_out_words *8 ); - ret = uverbs_ex_cmd_table[command](file, - ib_dev, - &ucore, - &uhw); + ret = uverbs_ex_cmd_table[command](file, ib_dev, &ucore, &uhw);if (!ret) ret = written_count; }else {
drivers/infiniband/core/uverbs_std_types.c +2 -1
@@ -246,7 +246,8 @@ static void create_udata(struct uverbs_attr_bundle *ctx, outbuf_len = uhw_out->ptr_attr.len; } -INIT_UDATA_BUF_OR_NULL (udata, inbuf, outbuf, inbuf_len, outbuf_len); +ib_uverbs_init_udata_buf_or_null (udata, inbuf, outbuf, inbuf_len, + outbuf_len); } static int uverbs_create_cq_handler(struct ib_device *ib_dev,
Signature · 1 line
2.9.0
PATCH 2/2 IB/uverbs: clean up INIT_UDATA() macro usage
After changing INIT_UDATA_BUF_OR_NULL() to an inline function, this does the same change to INIT_UDATA for consistency. I'm keeping it separate as this part is much larger and we wouldn't want to backport this to stable kernels if we ever want to address the gcc warnings by backporting the first patch.
Again, using an inline function gives us better type safety here among other issues with macros. I'm using u64_to_user_ptr() to convert the user pointer to simplify the logic rather than adding lots of new type casts.
--- drivers/infiniband/core/uverbs.h | 22 +++--- drivers/infiniband/core/uverbs_cmd.c | 125 +++++++++++++++-------------------- 2 files changed, 67 insertions(+), 80 deletions(-)
drivers/infiniband/core/uverbs.h +14 -8
@@ -47,13 +47,17 @@#include <rdma/ib_umem.h> #include <rdma/ib_user_verbs.h> -#define INIT_UDATA (udata, ibuf, obuf, ilen, olen) \ - do { \ - (udata)->inbuf = (const void __user *) (ibuf); \ - (udata)->outbuf = (void __user *) (obuf); \ - (udata)->inlen = (ilen); \ - (udata)->outlen = (olen); \ - } while (0) +static inline void +ib_uverbs_init_udata (struct ib_udata *udata, +const void __user *ibuf, +void __user *obuf, +size_t ilen,size_t olen) +{ + udata->inbuf = ibuf; + udata->outbuf = obuf; + udata->inlen = ilen; + udata->outlen = olen; +} static inline void ib_uverbs_init_udata_buf_or_null(struct ib_udata *udata,
@@ -61,7 +65,9 @@ ib_uverbs_init_udata_buf_or_null(struct ib_udata *udata,void __user *obuf, size_t ilen, size_t olen) { - INIT_UDATA(udata, ilen ? ibuf : NULL, olen ? obuf : NULL, ilen, olen); +ib_uverbs_init_udata (udata , + ilen ? ibuf : NULL, olen ? obuf : NULL, +ilen ,olen ); }/*
drivers/infiniband/core/uverbs_cmd.c +53 -72
342 lines not on this page · raw message
Signature · 1 line
2.9.0
Re: [PATCH 2/2] IB/uverbs: clean up INIT_UDATA() macro usage
Quoted 12 lines · Arnd Bergmann
After changing
INIT_UDATA_BUF_OR_NULL()to an inline function, this does the same change toINIT_UDATAfor consistency. I'm keeping it separate as this part is much larger and we wouldn't want to backport this to stable kernels if we ever want to address the gcc warnings by backporting the first patch.Again, using an inline function gives us better type safety here among other issues with macros. I'm using
u64_to_user_ptr()to convert the user pointer to simplify the logic rather than adding lots of new type casts.
Quoted 6 lines
Signed-off-by Arnd Bergmann <[email protected]>--- drivers/infiniband/core/uverbs.h | 22 +++--- drivers/infiniband/core/uverbs_cmd.c | 125 +++++++++++++++-------------------- 2 files changed, 67 insertions(+), 80 deletions(-)
Thanks, for doing it and for spotting light on u64_to_user_ptr().
Doug Ledford
AppliedRe: [PATCH 2/2] IB/uverbs: clean up INIT_UDATA() macro usage
In reply to Arnd BergmannQuoted 7 lines · Arnd Bergmann
After changing
INIT_UDATA_BUF_OR_NULL()to an inline function, this does the same change toINIT_UDATAfor consistency. I'm keeping it separate as this part is much larger and we wouldn't want to backport this to stable kernels if we ever want to address the gcc warnings by backporting the first patch.
Quoted 6 lines
Again, using an inline function gives us better type safety here among other issues with macros. I'm using
u64_to_user_ptr()to convert the user pointer to simplify the logic rather than adding lots of new type casts.Signed-off-by Arnd Bergmann <[email protected]>
Thanks, applied.
Signature · 8 lines
Doug Ledford <[email protected]> GPG KeyID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Doug Ledford
AppliedQuoted 13 lines · Arnd Bergmann
We get a harmless warning about the fact that we use the result of a multiplication as a condition:
drivers/infiniband/core/uverbs_main.c: In function 'ib_uverbs_write':drivers/infiniband/core/uverbs_main.c:787:40: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context]drivers/infiniband/core/uverbs_main.c:787:117: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context]drivers/infiniband/core/uverbs_main.c:790:50: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context]drivers/infiniband/core/uverbs_main.c:790:151: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context]
Quoted 8 lines
This avoids the problem by using an inline function in place of the macro.
Fixes a96e4e2ffe43 ("IB/uverbs: New macro to set pointers to NULL iflength is 0 in
INIT_UDATA()")Suggested-by Christoph Hellwig <[email protected]>Signed-off-by Arnd Bergmann <[email protected]>
Thanks, applied.
Signature · 3 lines
Doug Ledford <[email protected]> GPG KeyID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD