[PATCH 4/9] RDMA/hfi2: Remove redundant NULL checks in create_workqueues()

Dennis Dalessandro <[email protected]> Mon, 03 Aug 2026 12:11:12 -0400
Newsgroups org.kernel.vger.linux-rdma
Message-ID <178577347228.1793053.7899266546478488225.stgit@awdrv-04>
Since create_workqueues() operates on freshly allocated data, the wq
pointers will naturally be NULL. Redundant NULL checks in creation and
destruction can be omitted. This follows the pattern of hfi1 fix
22113f3f55a1 ("RDMA/hfi1: Remove redundant NULL checks in
create_workqueues()").

Assisted-by: Claude:claude-sonnet-4-5
Signed-off-by: Dennis Dalessandro <[email protected]>
---
 drivers/infiniband/hw/hfi2/init.c |   52 +++++++++++++++----------------------
 1 file changed, 21 insertions(+), 31 deletions(-)

diff --git a/drivers/infiniband/hw/hfi2/init.c b/drivers/infiniband/hw/hfi2/init.c
index 92cf9c55df0e..ac5004cabd09 100644
--- a/drivers/infiniband/hw/hfi2/init.c
+++ b/drivers/infiniband/hw/hfi2/init.c
@@ -1468,32 +1468,28 @@ static int create_workqueues(struct hfi2_devdata *dd)
 	int pidx;
 	struct hfi2_pportdata *ppd;
 
-	if (!dd->hfi2_wq) {
-		dd->hfi2_wq = alloc_workqueue(
-			"hfi%d",
-			WQ_SYSFS | WQ_HIGHPRI | WQ_CPU_INTENSIVE |
-				WQ_MEM_RECLAIM | WQ_PERCPU,
-			HFI2_MAX_ACTIVE_GEN_WQ_ENTRIES, dd->unit);
-		if (!dd->hfi2_wq)
-			goto wq_error;
-	}
+	dd->hfi2_wq = alloc_workqueue("hfi%d",
+				      WQ_SYSFS | WQ_HIGHPRI | WQ_CPU_INTENSIVE |
+					      WQ_MEM_RECLAIM | WQ_PERCPU,
+				      HFI2_MAX_ACTIVE_GEN_WQ_ENTRIES, dd->unit);
+	if (!dd->hfi2_wq)
+		goto wq_error;
+
 	for (pidx = 0; pidx < dd->num_pports; ++pidx) {
 		ppd = dd->pport + pidx;
+		/*
+		 * Make the link workqueue single-threaded to enforce
+		 * serialization.
+		 */
+		ppd->link_wq =
+			alloc_workqueue("hfi_link_%d_%d",
+					WQ_SYSFS | WQ_MEM_RECLAIM | WQ_UNBOUND,
+					1, /* max_active */
+					dd->unit, pidx);
 		if (!ppd->link_wq) {
-			/*
-			 * Make the link workqueue single-threaded to enforce
-			 * serialization.
-			 */
-			ppd->link_wq = alloc_workqueue(
-				"hfi_link_%d_%d",
-				WQ_SYSFS | WQ_MEM_RECLAIM | WQ_UNBOUND,
-				1, /* max_active */
-				dd->unit, pidx);
-			if (!ppd->link_wq) {
-				pr_err("alloc_workqueue failed for port %d\n",
-				       pidx + 1);
-				goto wq_error;
-			}
+			pr_err("alloc_workqueue failed for port %d\n",
+			       pidx + 1);
+			goto wq_error;
 		}
 	}
 	return 0;
@@ -1515,15 +1511,9 @@ static void destroy_workqueues(struct hfi2_devdata *dd)
 	for (pidx = 0; pidx < dd->num_pports; ++pidx) {
 		ppd = dd->pport + pidx;
 
-		if (ppd->link_wq) {
-			destroy_workqueue(ppd->link_wq);
-			ppd->link_wq = NULL;
-		}
-	}
-	if (dd->hfi2_wq) {
-		destroy_workqueue(dd->hfi2_wq);
-		dd->hfi2_wq = NULL;
+		destroy_workqueue(ppd->link_wq);
 	}
+	destroy_workqueue(dd->hfi2_wq);
 }
 
 /**