@@ -429,6 +429,9 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx,
429429 return 0 ;
430430
431431error_fail_copy_to_udata :
432+ if (hr_dev -> caps .flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB ||
433+ hr_dev -> caps .flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB )
434+ mutex_destroy (& context -> page_mutex );
432435 hns_roce_dealloc_uar_entry (context );
433436
434437error_fail_uar_entry :
@@ -445,6 +448,10 @@ static void hns_roce_dealloc_ucontext(struct ib_ucontext *ibcontext)
445448 struct hns_roce_ucontext * context = to_hr_ucontext (ibcontext );
446449 struct hns_roce_dev * hr_dev = to_hr_dev (ibcontext -> device );
447450
451+ if (hr_dev -> caps .flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB ||
452+ hr_dev -> caps .flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB )
453+ mutex_destroy (& context -> page_mutex );
454+
448455 hns_roce_dealloc_uar_entry (context );
449456
450457 ida_free (& hr_dev -> uar_ida .ida , (int )context -> uar .logic_idx );
@@ -933,6 +940,15 @@ static int hns_roce_init_hem(struct hns_roce_dev *hr_dev)
933940 return ret ;
934941}
935942
943+ static void hns_roce_teardown_hca (struct hns_roce_dev * hr_dev )
944+ {
945+ hns_roce_cleanup_bitmap (hr_dev );
946+
947+ if (hr_dev -> caps .flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB ||
948+ hr_dev -> caps .flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB )
949+ mutex_destroy (& hr_dev -> pgdir_mutex );
950+ }
951+
936952/**
937953 * hns_roce_setup_hca - setup host channel adapter
938954 * @hr_dev: pointer to hns roce device
@@ -981,6 +997,10 @@ static int hns_roce_setup_hca(struct hns_roce_dev *hr_dev)
981997
982998err_uar_table_free :
983999 ida_destroy (& hr_dev -> uar_ida .ida );
1000+ if (hr_dev -> caps .flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB ||
1001+ hr_dev -> caps .flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB )
1002+ mutex_destroy (& hr_dev -> pgdir_mutex );
1003+
9841004 return ret ;
9851005}
9861006
@@ -1126,7 +1146,7 @@ int hns_roce_init(struct hns_roce_dev *hr_dev)
11261146 hr_dev -> hw -> hw_exit (hr_dev );
11271147
11281148error_failed_engine_init :
1129- hns_roce_cleanup_bitmap (hr_dev );
1149+ hns_roce_teardown_hca (hr_dev );
11301150
11311151error_failed_setup_hca :
11321152 hns_roce_cleanup_hem (hr_dev );
@@ -1156,7 +1176,7 @@ void hns_roce_exit(struct hns_roce_dev *hr_dev)
11561176
11571177 if (hr_dev -> hw -> hw_exit )
11581178 hr_dev -> hw -> hw_exit (hr_dev );
1159- hns_roce_cleanup_bitmap (hr_dev );
1179+ hns_roce_teardown_hca (hr_dev );
11601180 hns_roce_cleanup_hem (hr_dev );
11611181
11621182 if (hr_dev -> cmd_mod )
0 commit comments