Skip to content

Commit 63b1db3

Browse files
ricardokojokawasaki
authored andcommitted
nullblk: zoned: use lock guards
Use guard() and scoped_guard() for handling spin locks instead of manually locking and unlocking. This prevents forgotten locks due to early exits. Signed-off-by: Ricardo H H Kojo <[email protected]> Co-developed-by: Ellian Carlos <[email protected]> Signed-off-by: Ellian Carlos <[email protected]> Co-developed-by: Gabriel B L de Oliveira <[email protected]> Signed-off-by: Gabriel B L de Oliveira <[email protected]>
1 parent 3933701 commit 63b1db3

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

drivers/block/null_blk/zoned.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,12 @@ static blk_status_t null_open_zone(struct nullb_device *dev,
471471
}
472472

473473
if (dev->need_zone_res_mgmt) {
474-
spin_lock(&dev->zone_res_lock);
474+
guard(spinlock)(&dev->zone_res_lock);
475475

476476
switch (zone->cond) {
477477
case BLK_ZONE_COND_EMPTY:
478478
ret = null_check_zone_resources(dev, zone);
479479
if (ret != BLK_STS_OK) {
480-
spin_unlock(&dev->zone_res_lock);
481480
return ret;
482481
}
483482
break;
@@ -487,7 +486,6 @@ static blk_status_t null_open_zone(struct nullb_device *dev,
487486
case BLK_ZONE_COND_CLOSED:
488487
ret = null_check_zone_resources(dev, zone);
489488
if (ret != BLK_STS_OK) {
490-
spin_unlock(&dev->zone_res_lock);
491489
return ret;
492490
}
493491
dev->nr_zones_closed--;
@@ -497,8 +495,6 @@ static blk_status_t null_open_zone(struct nullb_device *dev,
497495
}
498496

499497
dev->nr_zones_exp_open++;
500-
501-
spin_unlock(&dev->zone_res_lock);
502498
}
503499

504500
zone->cond = BLK_ZONE_COND_EXP_OPEN;
@@ -526,7 +522,7 @@ static blk_status_t null_close_zone(struct nullb_device *dev,
526522
}
527523

528524
if (dev->need_zone_res_mgmt) {
529-
spin_lock(&dev->zone_res_lock);
525+
guard(spinlock)(&dev->zone_res_lock);
530526

531527
switch (zone->cond) {
532528
case BLK_ZONE_COND_IMP_OPEN:
@@ -542,7 +538,6 @@ static blk_status_t null_close_zone(struct nullb_device *dev,
542538
if (zone->wp > zone->start)
543539
dev->nr_zones_closed++;
544540

545-
spin_unlock(&dev->zone_res_lock);
546541
}
547542

548543
if (zone->wp == zone->start)
@@ -562,17 +557,15 @@ static blk_status_t null_finish_zone(struct nullb_device *dev,
562557
return BLK_STS_IOERR;
563558

564559
if (dev->need_zone_res_mgmt) {
565-
spin_lock(&dev->zone_res_lock);
560+
guard(spinlock)(&dev->zone_res_lock);
566561

567562
switch (zone->cond) {
568563
case BLK_ZONE_COND_FULL:
569564
/* Finish operation on full is not an error */
570-
spin_unlock(&dev->zone_res_lock);
571565
return BLK_STS_OK;
572566
case BLK_ZONE_COND_EMPTY:
573567
ret = null_check_zone_resources(dev, zone);
574568
if (ret != BLK_STS_OK) {
575-
spin_unlock(&dev->zone_res_lock);
576569
return ret;
577570
}
578571
break;
@@ -585,13 +578,11 @@ static blk_status_t null_finish_zone(struct nullb_device *dev,
585578
case BLK_ZONE_COND_CLOSED:
586579
ret = null_check_zone_resources(dev, zone);
587580
if (ret != BLK_STS_OK) {
588-
spin_unlock(&dev->zone_res_lock);
589581
return ret;
590582
}
591583
dev->nr_zones_closed--;
592584
break;
593585
default:
594-
spin_unlock(&dev->zone_res_lock);
595586
return BLK_STS_IOERR;
596587
}
597588

@@ -611,7 +602,7 @@ static blk_status_t null_reset_zone(struct nullb_device *dev,
611602
return BLK_STS_IOERR;
612603

613604
if (dev->need_zone_res_mgmt) {
614-
spin_lock(&dev->zone_res_lock);
605+
guard(spinlock)(&dev->zone_res_lock);
615606

616607
switch (zone->cond) {
617608
case BLK_ZONE_COND_IMP_OPEN:
@@ -627,11 +618,9 @@ static blk_status_t null_reset_zone(struct nullb_device *dev,
627618
case BLK_ZONE_COND_FULL:
628619
break;
629620
default:
630-
spin_unlock(&dev->zone_res_lock);
631621
return BLK_STS_IOERR;
632622
}
633623

634-
spin_unlock(&dev->zone_res_lock);
635624
}
636625

637626
zone->cond = BLK_ZONE_COND_EMPTY;

0 commit comments

Comments
 (0)