Skip to contentSkip to conversation

cxl/core: Avoid using dev uninitialized in devm_cxl_add_decoder()

PATCH New Nathan Chancellor 1 participant 1 message Aug 25, 2021 CXL

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cxl/core: Avoid using dev uninitialized in devm_cxl_add_decoder()

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")
---
 drivers/cxl/core/bus.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/cxl/core/bus.c +3 -5
index 1320a996220a..f4d5319e29e3 100644
@@ -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

Signature · 1 line
2.33.0