All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Alison Schofield <alison.schofield@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Ira Weiny <ira.weiny@intel.com>,
	Ben Widawsky <ben.widawsky@intel.com>,
	Dan Williams <dan.j.williams@intel.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>,
	linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org,
	clang-built-linux@googlegroups.com, llvm@lists.linux.dev,
	Nathan Chancellor <nathan@kernel.org>
Subject: [PATCH] cxl/core: Avoid using dev uninitialized in devm_cxl_add_decoder()
Date: Wed, 25 Aug 2021 10:33:01 -0700	[thread overview]
Message-ID: <20210825173301.358381-1-nathan@kernel.org> (raw)

Clang warns:

drivers/cxl/core/bus.c:527:6: warning: variable 'dev' is used
uninitialized whenever 'if' condition is true
[-Wsometimes-uninitialized]
        if (rc)
            ^~
drivers/cxl/core/bus.c:541:13: note: uninitialized use occurs here
        put_device(dev);
                   ^~~
drivers/cxl/core/bus.c:527:2: note: remove the 'if' if its condition is
always false
        if (rc)
        ^~~~~~~
drivers/cxl/core/bus.c:507:6: warning: variable 'dev' is used
uninitialized whenever 'if' condition is true
[-Wsometimes-uninitialized]
        if (cxld->interleave_ways < 1) {
            ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/cxl/core/bus.c:541:13: note: uninitialized use occurs here
        put_device(dev);
                   ^~~
drivers/cxl/core/bus.c:507:2: note: remove the 'if' if its condition is
always false
        if (cxld->interleave_ways < 1) {
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/cxl/core/bus.c:498:20: note: initialize the variable 'dev' to
silence this warning
        struct device *dev;
                          ^
                           = NULL
2 warnings generated.

Return the error code directly rather than attempting to call
device_put() with an uninitialized pointer.

Fixes: b7ca54b62551 ("cxl/core: Split decoder setup into alloc + add")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 drivers/cxl/core/bus.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/cxl/core/bus.c b/drivers/cxl/core/bus.c
index 1320a996220a..f4d5319e29e3 100644
--- a/drivers/cxl/core/bus.c
+++ b/drivers/cxl/core/bus.c
@@ -504,10 +504,8 @@ int devm_cxl_add_decoder(struct device *host, struct cxl_decoder *cxld,
 	if (IS_ERR(cxld))
 		return PTR_ERR(cxld);
 
-	if (cxld->interleave_ways < 1) {
-		rc = -EINVAL;
-		goto err;
-	}
+	if (cxld->interleave_ways < 1)
+		return -EINVAL;
 
 	device_lock(&port->dev);
 	if (list_empty(&port->dports))
@@ -525,7 +523,7 @@ int devm_cxl_add_decoder(struct device *host, struct cxl_decoder *cxld,
 	}
 	device_unlock(&port->dev);
 	if (rc)
-		goto err;
+		return rc;
 
 	dev = &cxld->dev;
 	rc = dev_set_name(dev, "decoder%d.%d", port->id, cxld->id);

base-commit: 036a16a39e2fab9bf7279201d04cf7e90993521f
-- 
2.33.0


                 reply	other threads:[~2021-08-25 17:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210825173301.358381-1-nathan@kernel.org \
    --to=nathan@kernel.org \
    --cc=alison.schofield@intel.com \
    --cc=ben.widawsky@intel.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=dan.j.williams@intel.com \
    --cc=ira.weiny@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=ndesaulniers@google.com \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.