linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] infiniband: avoid uninitialized variable warning in create_udata
@ 2017-11-10 22:10 Arnd Bergmann
  2017-11-11  9:21 ` Leon Romanovsky
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2017-11-10 22:10 UTC (permalink / raw)
  To: Doug Ledford
  Cc: Christoph Hellwig, Dan Carpenter, Arnd Bergmann, Matan Barak,
	Yishai Hadas, Sean Hefty, Leon Romanovsky,
	Dasaratharaman Chandramouli, linux-rdma, linux-kernel

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.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: 12f727721eee ("IB/uverbs: clean up INIT_UDATA_BUF_OR_NULL usage")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/infiniband/core/uverbs_std_types.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/infiniband/core/uverbs_std_types.c b/drivers/infiniband/core/uverbs_std_types.c
index b095bce7f238..c3ee5d9b336d 100644
--- a/drivers/infiniband/core/uverbs_std_types.c
+++ b/drivers/infiniband/core/uverbs_std_types.c
@@ -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,
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] infiniband: avoid uninitialized variable warning in create_udata
  2017-11-10 22:10 [PATCH] infiniband: avoid uninitialized variable warning in create_udata Arnd Bergmann
@ 2017-11-11  9:21 ` Leon Romanovsky
  2017-11-13 21:14   ` Doug Ledford
  0 siblings, 1 reply; 3+ messages in thread
From: Leon Romanovsky @ 2017-11-11  9:21 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Doug Ledford, Christoph Hellwig, Dan Carpenter, Matan Barak,
	Yishai Hadas, Sean Hefty, Dasaratharaman Chandramouli,
	linux-rdma, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 698 bytes --]

On Fri, Nov 10, 2017 at 11:10:31PM +0100, Arnd Bergmann wrote:
> 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.
>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Fixes: 12f727721eee ("IB/uverbs: clean up INIT_UDATA_BUF_OR_NULL usage")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/infiniband/core/uverbs_std_types.c | 21 ++++++++++-----------
>  1 file changed, 10 insertions(+), 11 deletions(-)
>

Thanks,
Reviewed-by: Leon Romanovsky <leonro@mellanox.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] infiniband: avoid uninitialized variable warning in create_udata
  2017-11-11  9:21 ` Leon Romanovsky
@ 2017-11-13 21:14   ` Doug Ledford
  0 siblings, 0 replies; 3+ messages in thread
From: Doug Ledford @ 2017-11-13 21:14 UTC (permalink / raw)
  To: Leon Romanovsky, Arnd Bergmann
  Cc: Christoph Hellwig, Dan Carpenter, Matan Barak, Yishai Hadas,
	Sean Hefty, Dasaratharaman Chandramouli, linux-rdma,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 982 bytes --]

On Sat, 2017-11-11 at 11:21 +0200, Leon Romanovsky wrote:
> On Fri, Nov 10, 2017 at 11:10:31PM +0100, Arnd Bergmann wrote:
> > 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.
> > 
> > Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Fixes: 12f727721eee ("IB/uverbs: clean up INIT_UDATA_BUF_OR_NULL usage")
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > ---
> >  drivers/infiniband/core/uverbs_std_types.c | 21 ++++++++++-----------
> >  1 file changed, 10 insertions(+), 11 deletions(-)
> > 
> 
> Thanks,
> Reviewed-by: Leon Romanovsky <leonro@mellanox.com>

Thanks, applied.

-- 
Doug Ledford <dledford@redhat.com>
    GPG KeyID: B826A3330E572FDD
    Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-13 21:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-10 22:10 [PATCH] infiniband: avoid uninitialized variable warning in create_udata Arnd Bergmann
2017-11-11  9:21 ` Leon Romanovsky
2017-11-13 21:14   ` Doug Ledford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).