@@ -43,8 +43,6 @@ static void __synchronize_hardirq(struct irq_desc *desc, bool sync_chip)
43
43
bool inprogress ;
44
44
45
45
do {
46
- unsigned long flags ;
47
-
48
46
/*
49
47
* Wait until we're out of the critical section. This might
50
48
* give the wrong answer due to the lack of memory barriers.
@@ -53,7 +51,7 @@ static void __synchronize_hardirq(struct irq_desc *desc, bool sync_chip)
53
51
cpu_relax ();
54
52
55
53
/* Ok, that indicated we're done: double-check carefully. */
56
- raw_spin_lock_irqsave ( & desc -> lock , flags );
54
+ guard ( raw_spinlock_irqsave )( & desc -> lock );
57
55
inprogress = irqd_irq_inprogress (& desc -> irq_data );
58
56
59
57
/*
@@ -69,8 +67,6 @@ static void __synchronize_hardirq(struct irq_desc *desc, bool sync_chip)
69
67
__irq_get_irqchip_state (irqd , IRQCHIP_STATE_ACTIVE ,
70
68
& inprogress );
71
69
}
72
- raw_spin_unlock_irqrestore (& desc -> lock , flags );
73
-
74
70
/* Oops, that failed? */
75
71
} while (inprogress );
76
72
}
@@ -458,16 +454,12 @@ static int __irq_set_affinity(unsigned int irq, const struct cpumask *mask,
458
454
bool force )
459
455
{
460
456
struct irq_desc * desc = irq_to_desc (irq );
461
- unsigned long flags ;
462
- int ret ;
463
457
464
458
if (!desc )
465
459
return - EINVAL ;
466
460
467
- raw_spin_lock_irqsave (& desc -> lock , flags );
468
- ret = irq_set_affinity_locked (irq_desc_get_irq_data (desc ), mask , force );
469
- raw_spin_unlock_irqrestore (& desc -> lock , flags );
470
- return ret ;
461
+ guard (raw_spinlock_irqsave )(& desc -> lock );
462
+ return irq_set_affinity_locked (irq_desc_get_irq_data (desc ), mask , force );
471
463
}
472
464
473
465
/**
@@ -522,17 +514,16 @@ static void irq_affinity_notify(struct work_struct *work)
522
514
container_of (work , struct irq_affinity_notify , work );
523
515
struct irq_desc * desc = irq_to_desc (notify -> irq );
524
516
cpumask_var_t cpumask ;
525
- unsigned long flags ;
526
517
527
518
if (!desc || !alloc_cpumask_var (& cpumask , GFP_KERNEL ))
528
519
goto out ;
529
520
530
- raw_spin_lock_irqsave ( & desc -> lock , flags );
531
- if (irq_move_pending (& desc -> irq_data ))
532
- irq_get_pending (cpumask , desc );
533
- else
534
- cpumask_copy (cpumask , desc -> irq_common_data .affinity );
535
- raw_spin_unlock_irqrestore ( & desc -> lock , flags );
521
+ scoped_guard ( raw_spinlock_irqsave , & desc -> lock ) {
522
+ if (irq_move_pending (& desc -> irq_data ))
523
+ irq_get_pending (cpumask , desc );
524
+ else
525
+ cpumask_copy (cpumask , desc -> irq_common_data .affinity );
526
+ }
536
527
537
528
notify -> notify (notify , cpumask );
538
529
@@ -556,7 +547,6 @@ int irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *noti
556
547
{
557
548
struct irq_desc * desc = irq_to_desc (irq );
558
549
struct irq_affinity_notify * old_notify ;
559
- unsigned long flags ;
560
550
561
551
/* The release function is promised process context */
562
552
might_sleep ();
@@ -571,10 +561,10 @@ int irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *noti
571
561
INIT_WORK (& notify -> work , irq_affinity_notify );
572
562
}
573
563
574
- raw_spin_lock_irqsave ( & desc -> lock , flags );
575
- old_notify = desc -> affinity_notify ;
576
- desc -> affinity_notify = notify ;
577
- raw_spin_unlock_irqrestore ( & desc -> lock , flags );
564
+ scoped_guard ( raw_spinlock_irqsave , & desc -> lock ) {
565
+ old_notify = desc -> affinity_notify ;
566
+ desc -> affinity_notify = notify ;
567
+ }
578
568
579
569
if (old_notify ) {
580
570
if (cancel_work_sync (& old_notify -> work )) {
@@ -595,15 +585,16 @@ EXPORT_SYMBOL_GPL(irq_set_affinity_notifier);
595
585
int irq_setup_affinity (struct irq_desc * desc )
596
586
{
597
587
struct cpumask * set = irq_default_affinity ;
598
- int ret , node = irq_desc_get_node (desc );
588
+ int node = irq_desc_get_node (desc );
589
+
599
590
static DEFINE_RAW_SPINLOCK (mask_lock );
600
591
static struct cpumask mask ;
601
592
602
593
/* Excludes PER_CPU and NO_BALANCE interrupts */
603
594
if (!__irq_can_set_affinity (desc ))
604
595
return 0 ;
605
596
606
- raw_spin_lock (& mask_lock );
597
+ guard ( raw_spinlock ) (& mask_lock );
607
598
/*
608
599
* Preserve the managed affinity setting and a userspace affinity
609
600
* setup, but make sure that one of the targets is online.
@@ -628,9 +619,7 @@ int irq_setup_affinity(struct irq_desc *desc)
628
619
if (cpumask_intersects (& mask , nodemask ))
629
620
cpumask_and (& mask , & mask , nodemask );
630
621
}
631
- ret = irq_do_set_affinity (& desc -> irq_data , & mask , false);
632
- raw_spin_unlock (& mask_lock );
633
- return ret ;
622
+ return irq_do_set_affinity (& desc -> irq_data , & mask , false);
634
623
}
635
624
#else
636
625
/* Wrapper for ALPHA specific affinity selector magic */
@@ -1072,19 +1061,19 @@ static void irq_thread_check_affinity(struct irq_desc *desc, struct irqaction *a
1072
1061
return ;
1073
1062
}
1074
1063
1075
- raw_spin_lock_irq ( & desc -> lock );
1076
- /*
1077
- * This code is triggered unconditionally. Check the affinity
1078
- * mask pointer. For CPU_MASK_OFFSTACK=n this is optimized out.
1079
- */
1080
- if (cpumask_available (desc -> irq_common_data .affinity )) {
1081
- const struct cpumask * m ;
1064
+ scoped_guard ( raw_spinlock_irq , & desc -> lock ) {
1065
+ /*
1066
+ * This code is triggered unconditionally. Check the affinity
1067
+ * mask pointer. For CPU_MASK_OFFSTACK=n this is optimized out.
1068
+ */
1069
+ if (cpumask_available (desc -> irq_common_data .affinity )) {
1070
+ const struct cpumask * m ;
1082
1071
1083
- m = irq_data_get_effective_affinity_mask (& desc -> irq_data );
1084
- cpumask_copy (mask , m );
1085
- valid = true;
1072
+ m = irq_data_get_effective_affinity_mask (& desc -> irq_data );
1073
+ cpumask_copy (mask , m );
1074
+ valid = true;
1075
+ }
1086
1076
}
1087
- raw_spin_unlock_irq (& desc -> lock );
1088
1077
1089
1078
if (valid )
1090
1079
set_cpus_allowed_ptr (current , mask );
@@ -1252,9 +1241,8 @@ static void irq_wake_secondary(struct irq_desc *desc, struct irqaction *action)
1252
1241
if (WARN_ON_ONCE (!secondary ))
1253
1242
return ;
1254
1243
1255
- raw_spin_lock_irq (& desc -> lock );
1244
+ guard ( raw_spinlock_irq ) (& desc -> lock );
1256
1245
__irq_wake_thread (desc , secondary );
1257
- raw_spin_unlock_irq (& desc -> lock );
1258
1246
}
1259
1247
1260
1248
/*
@@ -1335,20 +1323,18 @@ void irq_wake_thread(unsigned int irq, void *dev_id)
1335
1323
{
1336
1324
struct irq_desc * desc = irq_to_desc (irq );
1337
1325
struct irqaction * action ;
1338
- unsigned long flags ;
1339
1326
1340
1327
if (!desc || WARN_ON (irq_settings_is_per_cpu_devid (desc )))
1341
1328
return ;
1342
1329
1343
- raw_spin_lock_irqsave ( & desc -> lock , flags );
1330
+ guard ( raw_spinlock_irqsave )( & desc -> lock );
1344
1331
for_each_action_of_desc (desc , action ) {
1345
1332
if (action -> dev_id == dev_id ) {
1346
1333
if (action -> thread )
1347
1334
__irq_wake_thread (desc , action );
1348
1335
break ;
1349
1336
}
1350
1337
}
1351
- raw_spin_unlock_irqrestore (& desc -> lock , flags );
1352
1338
}
1353
1339
EXPORT_SYMBOL_GPL (irq_wake_thread );
1354
1340
@@ -1979,9 +1965,8 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id)
1979
1965
* There is no interrupt on the fly anymore. Deactivate it
1980
1966
* completely.
1981
1967
*/
1982
- raw_spin_lock_irqsave (& desc -> lock , flags );
1983
- irq_domain_deactivate_irq (& desc -> irq_data );
1984
- raw_spin_unlock_irqrestore (& desc -> lock , flags );
1968
+ scoped_guard (raw_spinlock_irqsave , & desc -> lock )
1969
+ irq_domain_deactivate_irq (& desc -> irq_data );
1985
1970
1986
1971
irq_release_resources (desc );
1987
1972
chip_bus_sync_unlock (desc );
@@ -2066,8 +2051,6 @@ static const void *__cleanup_nmi(unsigned int irq, struct irq_desc *desc)
2066
2051
const void * free_nmi (unsigned int irq , void * dev_id )
2067
2052
{
2068
2053
struct irq_desc * desc = irq_to_desc (irq );
2069
- unsigned long flags ;
2070
- const void * devname ;
2071
2054
2072
2055
if (!desc || WARN_ON (!irq_is_nmi (desc )))
2073
2056
return NULL ;
@@ -2079,14 +2062,9 @@ const void *free_nmi(unsigned int irq, void *dev_id)
2079
2062
if (WARN_ON (desc -> depth == 0 ))
2080
2063
disable_nmi_nosync (irq );
2081
2064
2082
- raw_spin_lock_irqsave (& desc -> lock , flags );
2083
-
2065
+ guard (raw_spinlock_irqsave )(& desc -> lock );
2084
2066
irq_nmi_teardown (desc );
2085
- devname = __cleanup_nmi (irq , desc );
2086
-
2087
- raw_spin_unlock_irqrestore (& desc -> lock , flags );
2088
-
2089
- return devname ;
2067
+ return __cleanup_nmi (irq , desc );
2090
2068
}
2091
2069
2092
2070
/**
@@ -2290,7 +2268,6 @@ int request_nmi(unsigned int irq, irq_handler_t handler,
2290
2268
{
2291
2269
struct irqaction * action ;
2292
2270
struct irq_desc * desc ;
2293
- unsigned long flags ;
2294
2271
int retval ;
2295
2272
2296
2273
if (irq == IRQ_NOTCONNECTED )
@@ -2332,21 +2309,17 @@ int request_nmi(unsigned int irq, irq_handler_t handler,
2332
2309
if (retval )
2333
2310
goto err_irq_setup ;
2334
2311
2335
- raw_spin_lock_irqsave ( & desc -> lock , flags );
2336
-
2337
- /* Setup NMI state */
2338
- desc -> istate |= IRQS_NMI ;
2339
- retval = irq_nmi_setup ( desc );
2340
- if ( retval ) {
2341
- __cleanup_nmi ( irq , desc ) ;
2342
- raw_spin_unlock_irqrestore ( & desc -> lock , flags );
2343
- return - EINVAL ;
2312
+ scoped_guard ( raw_spinlock_irqsave , & desc -> lock ) {
2313
+ /* Setup NMI state */
2314
+ desc -> istate |= IRQS_NMI ;
2315
+ retval = irq_nmi_setup ( desc ) ;
2316
+ if ( retval ) {
2317
+ __cleanup_nmi ( irq , desc );
2318
+ return - EINVAL ;
2319
+ }
2320
+ return 0 ;
2344
2321
}
2345
2322
2346
- raw_spin_unlock_irqrestore (& desc -> lock , flags );
2347
-
2348
- return 0 ;
2349
-
2350
2323
err_irq_setup :
2351
2324
irq_chip_pm_put (& desc -> irq_data );
2352
2325
err_out :
@@ -2445,43 +2418,34 @@ static struct irqaction *__free_percpu_irq(unsigned int irq, void __percpu *dev_
2445
2418
{
2446
2419
struct irq_desc * desc = irq_to_desc (irq );
2447
2420
struct irqaction * action ;
2448
- unsigned long flags ;
2449
2421
2450
2422
WARN (in_interrupt (), "Trying to free IRQ %d from IRQ context!\n" , irq );
2451
2423
2452
2424
if (!desc )
2453
2425
return NULL ;
2454
2426
2455
- raw_spin_lock_irqsave (& desc -> lock , flags );
2427
+ scoped_guard (raw_spinlock_irqsave , & desc -> lock ) {
2428
+ action = desc -> action ;
2429
+ if (!action || action -> percpu_dev_id != dev_id ) {
2430
+ WARN (1 , "Trying to free already-free IRQ %d\n" , irq );
2431
+ return NULL ;
2432
+ }
2456
2433
2457
- action = desc -> action ;
2458
- if (! action || action -> percpu_dev_id != dev_id ) {
2459
- WARN ( 1 , "Trying to free already-free IRQ %d\n" , irq );
2460
- goto bad ;
2461
- }
2434
+ if (! cpumask_empty ( desc -> percpu_enabled )) {
2435
+ WARN ( 1 , "percpu IRQ %d still enabled on CPU%d!\n" ,
2436
+ irq , cpumask_first ( desc -> percpu_enabled ) );
2437
+ return NULL ;
2438
+ }
2462
2439
2463
- if (!cpumask_empty (desc -> percpu_enabled )) {
2464
- WARN (1 , "percpu IRQ %d still enabled on CPU%d!\n" ,
2465
- irq , cpumask_first (desc -> percpu_enabled ));
2466
- goto bad ;
2440
+ /* Found it - now remove it from the list of entries: */
2441
+ desc -> action = NULL ;
2442
+ desc -> istate &= ~IRQS_NMI ;
2467
2443
}
2468
2444
2469
- /* Found it - now remove it from the list of entries: */
2470
- desc -> action = NULL ;
2471
-
2472
- desc -> istate &= ~IRQS_NMI ;
2473
-
2474
- raw_spin_unlock_irqrestore (& desc -> lock , flags );
2475
-
2476
2445
unregister_handler_proc (irq , action );
2477
-
2478
2446
irq_chip_pm_put (& desc -> irq_data );
2479
2447
module_put (desc -> owner );
2480
2448
return action ;
2481
-
2482
- bad :
2483
- raw_spin_unlock_irqrestore (& desc -> lock , flags );
2484
- return NULL ;
2485
2449
}
2486
2450
2487
2451
/**
@@ -2651,7 +2615,6 @@ int request_percpu_nmi(unsigned int irq, irq_handler_t handler,
2651
2615
{
2652
2616
struct irqaction * action ;
2653
2617
struct irq_desc * desc ;
2654
- unsigned long flags ;
2655
2618
int retval ;
2656
2619
2657
2620
if (!handler )
@@ -2687,10 +2650,8 @@ int request_percpu_nmi(unsigned int irq, irq_handler_t handler,
2687
2650
if (retval )
2688
2651
goto err_irq_setup ;
2689
2652
2690
- raw_spin_lock_irqsave ( & desc -> lock , flags );
2653
+ guard ( raw_spinlock_irqsave )( & desc -> lock );
2691
2654
desc -> istate |= IRQS_NMI ;
2692
- raw_spin_unlock_irqrestore (& desc -> lock , flags );
2693
-
2694
2655
return 0 ;
2695
2656
2696
2657
err_irq_setup :
0 commit comments