Skip to contentSkip to conversation

habanalabs: fix incorrect check on failed workqueue create

PATCH In review Colin King 3 participants 6 messages Jul 30, 2020 – Aug 9, 2020

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 habanalabs: fix incorrect check on failed workqueue create

From: Colin Ian King <[email protected]>

The null check on a failed workqueue create is currently null checking hdev->cq_wq rather than the pointer hdev->cq_wq[i] and so the test will never be true on a failed workqueue create. Fix this by checking hdev->cq_wq[i].

Addresses-Coverity: ("Dereference before null check")

Fixes 5574cb2194b1 ("habanalabs: Assign each CQ with its own work queue")
---
 drivers/misc/habanalabs/common/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/habanalabs/common/device.c +1 -1
index be16b75bdfdb..35214a186913 100644
@@ -288,7 +288,7 @@ static int device_early_init(struct hl_device *hdev)
 	for (i = 0 ; i < hdev->asic_prop.completion_queues_count ; i++) {
 		snprintf(workq_name, 32, "hl-free-jobs-%u", i);
 		hdev->cq_wq[i] = create_singlethread_workqueue(workq_name);
-		if (hdev->cq_wq = NULL) {
+		if (hdev->cq_wq[i] = NULL) {
 			dev_err(hdev->dev, "Failed to allocate CQ workqueue\n");
 			rc = -ENOMEM;
 			goto free_cq_wq;
Signature · 1 line
2.27.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · Colin King

From: Colin Ian King <[email protected]>

The null check on a failed workqueue create is currently null checking hdev->cq_wq rather than the pointer hdev->cq_wq[i] and so the test will never be true on a failed workqueue create. Fix this by checking hdev->cq_wq[i].

Addresses-Coverity: ("Dereference before null check")

Fixes 5574cb2194b1 ("habanalabs: Assign each CQ with its own work queue")
---
 drivers/misc/habanalabs/common/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/habanalabs/common/device.c +1 -2
index be16b75bdfdb..35214a186913 100644
@@ -288,7 +288,7 @@ static int device_early_init(struct hl_device *hdev)
        for (i = 0 ; i < hdev->asic_prop.completion_queues_count ; i++) {
                snprintf(workq_name, 32, "hl-free-jobs-%u", i);
                hdev->cq_wq[i] = create_singlethread_workqueue(workq_name);
-               if (hdev->cq_wq = NULL) {
+               if (hdev->cq_wq[i] = NULL) {
                        dev_err(hdev->dev, "Failed to allocate CQ workqueue\n");
                        rc = -ENOMEM;
                        goto free_cq_wq;
--
Quoted 2 lines

2.27.0

This patch is:

Greg, can you please apply it directly to the char-misc-next branch ? I don't want to send a pull request for 1 patch.

Thanks,
Oded

#2 lore raw
Quoted 34 lines · Oded Gabbay
Quoted 29 lines · Colin King

From: Colin Ian King <[email protected]>

The null check on a failed workqueue create is currently null checking hdev->cq_wq rather than the pointer hdev->cq_wq[i] and so the test will never be true on a failed workqueue create. Fix this by checking hdev->cq_wq[i].

Addresses-Coverity: ("Dereference before null check")

Fixes 5574cb2194b1 ("habanalabs: Assign each CQ with its own work queue")
---
 drivers/misc/habanalabs/common/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/habanalabs/common/device.c +1 -2
index be16b75bdfdb..35214a186913 100644
@@ -288,7 +288,7 @@ static int device_early_init(struct hl_device *hdev)
        for (i = 0 ; i < hdev->asic_prop.completion_queues_count ; i++) {
                snprintf(workq_name, 32, "hl-free-jobs-%u", i);
                hdev->cq_wq[i] = create_singlethread_workqueue(workq_name);
-               if (hdev->cq_wq = NULL) {
+               if (hdev->cq_wq[i] = NULL) {
                        dev_err(hdev->dev, "Failed to allocate CQ workqueue\n");
                        rc = -ENOMEM;
                        goto free_cq_wq;
--
Quoted 2 lines

2.27.0

This patch is:

Quoted 4 lines

Greg, can you please apply it directly to the char-misc-next branch ? I don't want to send a pull request for 1 patch.

Already merged :)

#3 lore raw
Quoted 38 lines · Greg Kroah-Hartman
Quoted 36 lines · Oded Gabbay
Quoted 29 lines · Colin King

From: Colin Ian King <[email protected]>

The null check on a failed workqueue create is currently null checking hdev->cq_wq rather than the pointer hdev->cq_wq[i] and so the test will never be true on a failed workqueue create. Fix this by checking hdev->cq_wq[i].

Addresses-Coverity: ("Dereference before null check")

Fixes 5574cb2194b1 ("habanalabs: Assign each CQ with its own work queue")
---
 drivers/misc/habanalabs/common/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/habanalabs/common/device.c +1 -2
index be16b75bdfdb..35214a186913 100644
@@ -288,7 +288,7 @@ static int device_early_init(struct hl_device *hdev)
        for (i = 0 ; i < hdev->asic_prop.completion_queues_count ; i++) {
                snprintf(workq_name, 32, "hl-free-jobs-%u", i);
                hdev->cq_wq[i] = create_singlethread_workqueue(workq_name);
-               if (hdev->cq_wq = NULL) {
+               if (hdev->cq_wq[i] = NULL) {
                        dev_err(hdev->dev, "Failed to allocate CQ workqueue\n");
                        rc = -ENOMEM;
                        goto free_cq_wq;
--
Quoted 2 lines

2.27.0

This patch is:

Quoted 4 lines
Quoted 2 lines

Greg, can you please apply it directly to the char-misc-next branch ? I don't want to send a pull request for 1 patch.

Already merged :)

Hi Greg,
I can't find this patch in char-misc-next.
Can you please check if you applied it ?
If not, I'll apply it to my fixes tree and send it to you for -rc2

Thanks,
Oded

#4 lore raw
Quoted 40 lines · Oded Gabbay
Quoted 38 lines · Greg Kroah-Hartman
Quoted 36 lines · Oded Gabbay
Quoted 29 lines · Colin King

From: Colin Ian King <[email protected]>

The null check on a failed workqueue create is currently null checking hdev->cq_wq rather than the pointer hdev->cq_wq[i] and so the test will never be true on a failed workqueue create. Fix this by checking hdev->cq_wq[i].

Addresses-Coverity: ("Dereference before null check")

Fixes 5574cb2194b1 ("habanalabs: Assign each CQ with its own work queue")
---
 drivers/misc/habanalabs/common/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/habanalabs/common/device.c +1 -2
index be16b75bdfdb..35214a186913 100644
@@ -288,7 +288,7 @@ static int device_early_init(struct hl_device *hdev)
        for (i = 0 ; i < hdev->asic_prop.completion_queues_count ; i++) {
                snprintf(workq_name, 32, "hl-free-jobs-%u", i);
                hdev->cq_wq[i] = create_singlethread_workqueue(workq_name);
-               if (hdev->cq_wq = NULL) {
+               if (hdev->cq_wq[i] = NULL) {
                        dev_err(hdev->dev, "Failed to allocate CQ workqueue\n");
                        rc = -ENOMEM;
                        goto free_cq_wq;
--
Quoted 2 lines

2.27.0

This patch is:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Greg, can you please apply it directly to the char-misc-next branch ? I don't want to send a pull request for 1 patch.

Already merged :)

Hi Greg,
I can't find this patch in char-misc-next.
Can you please check if you applied it ?

Oops, you are right, I did not take it, my fault, sorry.

Quoted 1 line

If not, I'll apply it to my fixes tree and send it to you for -rc2

That would be great, thanks for following up on this.

greg k-h

#5 lore raw
Quoted 51 lines · Greg Kroah-Hartman
Quoted 40 lines · Oded Gabbay
Quoted 38 lines · Greg Kroah-Hartman
Quoted 36 lines · Oded Gabbay
Quoted 29 lines · Colin King

From: Colin Ian King <[email protected]>

The null check on a failed workqueue create is currently null checking hdev->cq_wq rather than the pointer hdev->cq_wq[i] and so the test will never be true on a failed workqueue create. Fix this by checking hdev->cq_wq[i].

Addresses-Coverity: ("Dereference before null check")

Fixes 5574cb2194b1 ("habanalabs: Assign each CQ with its own work queue")
---
 drivers/misc/habanalabs/common/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/habanalabs/common/device.c +1 -2
index be16b75bdfdb..35214a186913 100644
@@ -288,7 +288,7 @@ static int device_early_init(struct hl_device *hdev)
        for (i = 0 ; i < hdev->asic_prop.completion_queues_count ; i++) {
                snprintf(workq_name, 32, "hl-free-jobs-%u", i);
                hdev->cq_wq[i] = create_singlethread_workqueue(workq_name);
-               if (hdev->cq_wq = NULL) {
+               if (hdev->cq_wq[i] = NULL) {
                        dev_err(hdev->dev, "Failed to allocate CQ workqueue\n");
                        rc = -ENOMEM;
                        goto free_cq_wq;
--
Quoted 2 lines

2.27.0

This patch is:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Greg, can you please apply it directly to the char-misc-next branch ? I don't want to send a pull request for 1 patch.

Already merged :)

Hi Greg,
I can't find this patch in char-misc-next.
Can you please check if you applied it ?

Quoted 7 lines

Oops, you are right, I did not take it, my fault, sorry.

Quoted 1 line

If not, I'll apply it to my fixes tree and send it to you for -rc2

That would be great, thanks for following up on this.

greg k-h

Sure, np.
Thanks,
Oded