Skip to content

Commit a35cd64

Browse files
kwan-intcjgunthorpe
authored andcommitted
IB/qib: Call kobject_put() when kobject_init_and_add() fails
When kobject_init_and_add() returns an error in the function qib_create_port_files(), the function kobject_put() is not called for the corresponding kobject, which potentially leads to memory leak. This patch fixes the issue by calling kobject_put() even if kobject_init_and_add() fails. In addition, the ppd->diagc_kobj is released along with other kobjects when the sysfs is unregistered. Fixes: f931551 ("IB/qib: Add new qib driver for QLogic PCIe InfiniBand adapters") Link: https://lore.kernel.org/r/[email protected] Cc: <[email protected]> Suggested-by: Lin Yi <[email protected]> Reviewed-by: Mike Marciniszyn <[email protected]> Signed-off-by: Kaike Wan <[email protected]> Signed-off-by: Dennis Dalessandro <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent b9bbe6e commit a35cd64

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/infiniband/hw/qib/qib_sysfs.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ int qib_create_port_files(struct ib_device *ibdev, u8 port_num,
760760
qib_dev_err(dd,
761761
"Skipping linkcontrol sysfs info, (err %d) port %u\n",
762762
ret, port_num);
763-
goto bail;
763+
goto bail_link;
764764
}
765765
kobject_uevent(&ppd->pport_kobj, KOBJ_ADD);
766766

@@ -770,7 +770,7 @@ int qib_create_port_files(struct ib_device *ibdev, u8 port_num,
770770
qib_dev_err(dd,
771771
"Skipping sl2vl sysfs info, (err %d) port %u\n",
772772
ret, port_num);
773-
goto bail_link;
773+
goto bail_sl;
774774
}
775775
kobject_uevent(&ppd->sl2vl_kobj, KOBJ_ADD);
776776

@@ -780,7 +780,7 @@ int qib_create_port_files(struct ib_device *ibdev, u8 port_num,
780780
qib_dev_err(dd,
781781
"Skipping diag_counters sysfs info, (err %d) port %u\n",
782782
ret, port_num);
783-
goto bail_sl;
783+
goto bail_diagc;
784784
}
785785
kobject_uevent(&ppd->diagc_kobj, KOBJ_ADD);
786786

@@ -793,7 +793,7 @@ int qib_create_port_files(struct ib_device *ibdev, u8 port_num,
793793
qib_dev_err(dd,
794794
"Skipping Congestion Control sysfs info, (err %d) port %u\n",
795795
ret, port_num);
796-
goto bail_diagc;
796+
goto bail_cc;
797797
}
798798

799799
kobject_uevent(&ppd->pport_cc_kobj, KOBJ_ADD);
@@ -854,6 +854,7 @@ void qib_verbs_unregister_sysfs(struct qib_devdata *dd)
854854
&cc_table_bin_attr);
855855
kobject_put(&ppd->pport_cc_kobj);
856856
}
857+
kobject_put(&ppd->diagc_kobj);
857858
kobject_put(&ppd->sl2vl_kobj);
858859
kobject_put(&ppd->pport_kobj);
859860
}

0 commit comments

Comments
 (0)