Skip to contentSkip to conversation

cxl: avoid returning uninitialized error code

PATCH In review Arnd Bergmann 2 participants 2 messages Feb 13, 2023 – Feb 14, 2023 CXL

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cxl: avoid returning uninitialized error code

From: Arnd Bergmann <[email protected]>

The new cxl_add_to_region() function returns an uninitialized value on success:

drivers/cxl/core/region.c:2628:6: error: variable 'rc' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]

        if (IS_ERR(cxlr)) {
            ^~~~~~~~~~~~
drivers/cxl/core/region.c:2654:9: note: uninitialized use occurs here
        return rc;

Simplify the logic to have the rc variable always initialized in the same place.

Fixes a32320b71f08 ("cxl/region: Add region autodiscovery")
---
 drivers/cxl/core/region.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/cxl/core/region.c +2 -3
index fe1d8392870e..f29028148806 100644
@@ -2625,10 +2625,9 @@ int cxl_add_to_region(struct cxl_port *root, struct cxl_endpoint_decoder *cxled)
 		cxlr = to_cxl_region(region_dev);
 	mutex_unlock(&cxlrd->range_lock);
 
-	if (IS_ERR(cxlr)) {
-		rc = PTR_ERR(cxlr);
+	rc = PTR_ERR_OR_ZERO(cxlr);
+	if (rc)
 		goto out;
-	}
 
 	attach_target(cxlr, cxled, -1, TASK_UNINTERRUPTIBLE);
 
Signature · 1 line
2.39.1
#1 lore raw
Quoted 11 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

The new cxl_add_to_region() function returns an uninitialized value on success:

drivers/cxl/core/region.c:2628:6: error: variable 'rc' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]

        if (IS_ERR(cxlr)) {
            ^~~~~~~~~~~~
drivers/cxl/core/region.c:2654:9: note: uninitialized use occurs here
        return rc;
Quoted 5 lines

Simplify the logic to have the rc variable always initialized in the same place.

Fixes a32320b71f08 ("cxl/region: Add region autodiscovery")

Looks good, thanks Arnd.