Skip to contentSkip to conversation

cxl/mem: Fix an error code in cxl_mem_mbox_get()

PATCH In review Dan Carpenter 2 participants 2 messages Feb 16, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cxl/mem: Fix an error code in cxl_mem_mbox_get()

Smatch complains that sometimes when we return success we are holding the mutex and sometimes we have released the mutex. It turns out that the bug is a missing error code if the mbox is not ready. It should return -EBUSY instead of success.

Fixes cc1967ac93ab ("cxl/mem: Find device capabilities")
---
 drivers/cxl/mem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/cxl/mem.c +2 -1
index 3bca8451348a..2ebc84e4d202 100644
@@ -383,8 +383,8 @@ static int __cxl_mem_mbox_send_cmd(struct cxl_mem *cxlm,
 static int cxl_mem_mbox_get(struct cxl_mem *cxlm)
 {
 	struct device *dev = &cxlm->pdev->dev;
-	int rc = -EBUSY;
 	u64 md_status;
+	int rc;
 
 	mutex_lock_io(&cxlm->mbox_mutex);
 
@@ -414,6 +414,7 @@ static int cxl_mem_mbox_get(struct cxl_mem *cxlm)
 	md_status = readq(cxlm->memdev_regs + CXLMDEV_STATUS_OFFSET);
 	if (!(md_status & CXLMDEV_MBOX_IF_READY && CXLMDEV_READY(md_status))) {
 		dev_err(dev, "mbox: reported doorbell ready, but not mbox ready\n");
+		rc = -EBUSY;
 		goto out;
 	}
 
Signature · 1 line
2.30.0
#1 lore raw
Quoted 27 lines · Dan Carpenter

Smatch complains that sometimes when we return success we are holding the mutex and sometimes we have released the mutex. It turns out that the bug is a missing error code if the mbox is not ready. It should return -EBUSY instead of success.

Fixes cc1967ac93ab ("cxl/mem: Find device capabilities")
---
 drivers/cxl/mem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/cxl/mem.c +1 -1
index 3bca8451348a..2ebc84e4d202 100644
@@ -383,8 +383,8 @@ static int __cxl_mem_mbox_send_cmd(struct cxl_mem *cxlm,
 static int cxl_mem_mbox_get(struct cxl_mem *cxlm)
 {
        struct device *dev = &cxlm->pdev->dev;
-       int rc = -EBUSY;
        u64 md_status;
+       int rc;
 
        mutex_lock_io(&cxlm->mbox_mutex);
 

drivers/cxl/mem.c static int cxl_mem_mbox_get(struct cxl_mem *cxlm) · line 418

Quoted 5 lines
drivers/cxl/mem.c +1 -0
@@ -414,6 +414,7 @@ static int cxl_mem_mbox_get(struct cxl_mem *cxlm)
        md_status = readq(cxlm->memdev_regs + CXLMDEV_STATUS_OFFSET);
        if (!(md_status & CXLMDEV_MBOX_IF_READY && CXLMDEV_READY(md_status))) {
                dev_err(dev, "mbox: reported doorbell ready, but not mbox ready\n");
+               rc = -EBUSY;
                goto out;

Hey, Smatch gave a more thorough report than Coverity:

http://lore.kernel.org/r/[email protected]