Skip to contentSkip to conversation

infiniband: avoid uninitialized variable warning in create_udata

PATCH Applied Arnd Bergmann 3 participants 3 messages Nov 10, 2017 – Nov 13, 2017 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 infiniband: avoid uninitialized variable warning in create_udata

As Dan pointed out, the rework I did makes it harder for smatch and other static checkers to figure out what is going on with the uninitialized pointers.

By open-coding the call in create_udata(), we make it more readable for both humans and tools.

Fixes 12f727721eee ("IB/uverbs: clean up INIT_UDATA_BUF_OR_NULL usage")
---
 drivers/infiniband/core/uverbs_std_types.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
drivers/infiniband/core/uverbs_std_types.c +10 -11
index b095bce7f238..c3ee5d9b336d 100644
@@ -227,27 +227,26 @@ static void create_udata(struct uverbs_attr_bundle *ctx,
 	 * to use uverbs_attr_bundle instead of ib_udata.
 	 * Assume attr == 0 is input and attr == 1 is output.
 	 */
-	void __user *inbuf;
-	size_t inbuf_len = 0;
-	void __user *outbuf;
-	size_t outbuf_len = 0;
 	const struct uverbs_attr *uhw_in =
 		uverbs_attr_get(ctx, UVERBS_UHW_IN);
 	const struct uverbs_attr *uhw_out =
 		uverbs_attr_get(ctx, UVERBS_UHW_OUT);
 
 	if (!IS_ERR(uhw_in)) {
-		inbuf = uhw_in->ptr_attr.ptr;
-		inbuf_len = uhw_in->ptr_attr.len;
+		udata->inbuf = uhw_in->ptr_attr.ptr;
+		udata->inlen = uhw_in->ptr_attr.len;
+	} else {
+		udata->inbuf = NULL;
+		udata->inlen = 0;
 	}
 
 	if (!IS_ERR(uhw_out)) {
-		outbuf = uhw_out->ptr_attr.ptr;
-		outbuf_len = uhw_out->ptr_attr.len;
+		udata->outbuf = uhw_out->ptr_attr.ptr;
+		udata->outlen = uhw_out->ptr_attr.len;
+	} else {
+		udata->outbuf = NULL;
+		udata->outlen = 0;
 	}
-
-	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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Arnd Bergmann

As Dan pointed out, the rework I did makes it harder for smatch and other static checkers to figure out what is going on with the uninitialized pointers.

By open-coding the call in create_udata(), we make it more readable for both humans and tools.

Quoted 7 lines
Fixes 12f727721eee ("IB/uverbs: clean up INIT_UDATA_BUF_OR_NULL usage")
---
 drivers/infiniband/core/uverbs_std_types.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

Thanks,

Applied
#2 lore raw
Quoted 16 lines · Leon Romanovsky
Quoted 7 lines · Arnd Bergmann

As Dan pointed out, the rework I did makes it harder for smatch and other static checkers to figure out what is going on with the uninitialized pointers.

By open-coding the call in create_udata(), we make it more readable for both humans and tools.

Quoted 7 lines
Fixes 12f727721eee ("IB/uverbs: clean up INIT_UDATA_BUF_OR_NULL usage")
---
 drivers/infiniband/core/uverbs_std_types.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
Quoted 2 lines

Thanks,

Thanks, applied.

Signature · 3 lines
Doug Ledford <[email protected]>
    GPG KeyID: B826A3330E572FDD
    Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD