Skip to content

Commit 77ad7ef

Browse files
Shrikanth Hegdemaddy-kerneldev
authored andcommitted
powerpc: eeh: use lock guard for mutex
use guard(mutex) for scope based resource management of mutex. This would make the code simpler and easier to maintain. More details on lock guards can be found at https://lore.kernel.org/all/[email protected]/T/#u Reviewed-by: Srikar Dronamraju <[email protected]> Signed-off-by: Shrikanth Hegde <[email protected]> Tested-by: Venkat Rao Bagalkote <[email protected]> Signed-off-by: Madhavan Srinivasan <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 7b7b08b commit 77ad7ef

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

arch/powerpc/kernel/eeh.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,16 +1208,16 @@ int eeh_dev_open(struct pci_dev *pdev)
12081208
struct eeh_dev *edev;
12091209
int ret = -ENODEV;
12101210

1211-
mutex_lock(&eeh_dev_mutex);
1211+
guard(mutex)(&eeh_dev_mutex);
12121212

12131213
/* No PCI device ? */
12141214
if (!pdev)
1215-
goto out;
1215+
return ret;
12161216

12171217
/* No EEH device or PE ? */
12181218
edev = pci_dev_to_eeh_dev(pdev);
12191219
if (!edev || !edev->pe)
1220-
goto out;
1220+
return ret;
12211221

12221222
/*
12231223
* The PE might have been put into frozen state, but we
@@ -1227,16 +1227,12 @@ int eeh_dev_open(struct pci_dev *pdev)
12271227
*/
12281228
ret = eeh_pe_change_owner(edev->pe);
12291229
if (ret)
1230-
goto out;
1230+
return ret;
12311231

12321232
/* Increase PE's pass through count */
12331233
atomic_inc(&edev->pe->pass_dev_cnt);
1234-
mutex_unlock(&eeh_dev_mutex);
12351234

12361235
return 0;
1237-
out:
1238-
mutex_unlock(&eeh_dev_mutex);
1239-
return ret;
12401236
}
12411237
EXPORT_SYMBOL_GPL(eeh_dev_open);
12421238

@@ -1252,22 +1248,20 @@ void eeh_dev_release(struct pci_dev *pdev)
12521248
{
12531249
struct eeh_dev *edev;
12541250

1255-
mutex_lock(&eeh_dev_mutex);
1251+
guard(mutex)(&eeh_dev_mutex);
12561252

12571253
/* No PCI device ? */
12581254
if (!pdev)
1259-
goto out;
1255+
return;
12601256

12611257
/* No EEH device ? */
12621258
edev = pci_dev_to_eeh_dev(pdev);
12631259
if (!edev || !edev->pe || !eeh_pe_passed(edev->pe))
1264-
goto out;
1260+
return;
12651261

12661262
/* Decrease PE's pass through count */
12671263
WARN_ON(atomic_dec_if_positive(&edev->pe->pass_dev_cnt) < 0);
12681264
eeh_pe_change_owner(edev->pe);
1269-
out:
1270-
mutex_unlock(&eeh_dev_mutex);
12711265
}
12721266
EXPORT_SYMBOL(eeh_dev_release);
12731267

0 commit comments

Comments
 (0)