Skip to content

Commit c8775ae

Browse files
Zheng Qixingaxboe
authored andcommitted
badblocks: return boolean from badblocks_set() and badblocks_clear()
Change the return type of badblocks_set() and badblocks_clear() from int to bool, indicating success or failure. Specifically: - _badblocks_set() and _badblocks_clear() functions now return true for success and false for failure. - All calls to these functions are updated to handle the new boolean return type. - This change improves code clarity and ensures a more consistent handling of success and failure states. Signed-off-by: Zheng Qixing <[email protected]> Reviewed-by: Yu Kuai <[email protected]> Acked-by: Coly Li <[email protected]> Acked-by: Ira Weiny <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 5236f04 commit c8775ae

File tree

5 files changed

+49
-49
lines changed

5 files changed

+49
-49
lines changed

block/badblocks.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,8 @@ static bool try_adjacent_combine(struct badblocks *bb, int prev)
836836
}
837837

838838
/* Do exact work to set bad block range into the bad block table */
839-
static int _badblocks_set(struct badblocks *bb, sector_t s, int sectors,
840-
int acknowledged)
839+
static bool _badblocks_set(struct badblocks *bb, sector_t s, int sectors,
840+
int acknowledged)
841841
{
842842
int len = 0, added = 0;
843843
struct badblocks_context bad;
@@ -847,11 +847,11 @@ static int _badblocks_set(struct badblocks *bb, sector_t s, int sectors,
847847

848848
if (bb->shift < 0)
849849
/* badblocks are disabled */
850-
return 1;
850+
return false;
851851

852852
if (sectors == 0)
853853
/* Invalid sectors number */
854-
return 1;
854+
return false;
855855

856856
if (bb->shift) {
857857
/* round the start down, and the end up */
@@ -977,7 +977,7 @@ static int _badblocks_set(struct badblocks *bb, sector_t s, int sectors,
977977

978978
write_sequnlock_irqrestore(&bb->lock, flags);
979979

980-
return sectors;
980+
return sectors == 0;
981981
}
982982

983983
/*
@@ -1048,21 +1048,20 @@ static int front_splitting_clear(struct badblocks *bb, int prev,
10481048
}
10491049

10501050
/* Do the exact work to clear bad block range from the bad block table */
1051-
static int _badblocks_clear(struct badblocks *bb, sector_t s, int sectors)
1051+
static bool _badblocks_clear(struct badblocks *bb, sector_t s, int sectors)
10521052
{
10531053
struct badblocks_context bad;
10541054
int prev = -1, hint = -1;
10551055
int len = 0, cleared = 0;
1056-
int rv = 0;
10571056
u64 *p;
10581057

10591058
if (bb->shift < 0)
10601059
/* badblocks are disabled */
1061-
return 1;
1060+
return false;
10621061

10631062
if (sectors == 0)
10641063
/* Invalid sectors number */
1065-
return 1;
1064+
return false;
10661065

10671066
if (bb->shift) {
10681067
sector_t target;
@@ -1182,9 +1181,9 @@ static int _badblocks_clear(struct badblocks *bb, sector_t s, int sectors)
11821181
write_sequnlock_irq(&bb->lock);
11831182

11841183
if (!cleared)
1185-
rv = 1;
1184+
return false;
11861185

1187-
return rv;
1186+
return true;
11881187
}
11891188

11901189
/* Do the exact work to check bad blocks range from the bad block table */
@@ -1338,12 +1337,12 @@ EXPORT_SYMBOL_GPL(badblocks_check);
13381337
* decide how best to handle it.
13391338
*
13401339
* Return:
1341-
* 0: success
1342-
* other: failed to set badblocks (out of space). Parital setting will be
1340+
* true: success
1341+
* false: failed to set badblocks (out of space). Parital setting will be
13431342
* treated as failure.
13441343
*/
1345-
int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
1346-
int acknowledged)
1344+
bool badblocks_set(struct badblocks *bb, sector_t s, int sectors,
1345+
int acknowledged)
13471346
{
13481347
return _badblocks_set(bb, s, sectors, acknowledged);
13491348
}
@@ -1360,10 +1359,10 @@ EXPORT_SYMBOL_GPL(badblocks_set);
13601359
* drop the remove request.
13611360
*
13621361
* Return:
1363-
* 0: success
1364-
* 1: failed to clear badblocks
1362+
* true: success
1363+
* false: failed to clear badblocks
13651364
*/
1366-
int badblocks_clear(struct badblocks *bb, sector_t s, int sectors)
1365+
bool badblocks_clear(struct badblocks *bb, sector_t s, int sectors)
13671366
{
13681367
return _badblocks_clear(bb, s, sectors);
13691368
}
@@ -1485,10 +1484,10 @@ ssize_t badblocks_store(struct badblocks *bb, const char *page, size_t len,
14851484
return -EINVAL;
14861485
}
14871486

1488-
if (badblocks_set(bb, sector, length, !unack))
1487+
if (!badblocks_set(bb, sector, length, !unack))
14891488
return -ENOSPC;
1490-
else
1491-
return len;
1489+
1490+
return len;
14921491
}
14931492
EXPORT_SYMBOL_GPL(badblocks_store);
14941493

drivers/block/null_blk/main.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -561,14 +561,14 @@ static ssize_t nullb_device_badblocks_store(struct config_item *item,
561561
goto out;
562562
/* enable badblocks */
563563
cmpxchg(&t_dev->badblocks.shift, -1, 0);
564-
if (buf[0] == '+')
565-
ret = badblocks_set(&t_dev->badblocks, start,
566-
end - start + 1, 1);
567-
else
568-
ret = badblocks_clear(&t_dev->badblocks, start,
569-
end - start + 1);
570-
if (ret == 0)
564+
if (buf[0] == '+') {
565+
if (badblocks_set(&t_dev->badblocks, start,
566+
end - start + 1, 1))
567+
ret = count;
568+
} else if (badblocks_clear(&t_dev->badblocks, start,
569+
end - start + 1)) {
571570
ret = count;
571+
}
572572
out:
573573
kfree(orig);
574574
return ret;

drivers/md/md.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
17481748
count <<= sb->bblog_shift;
17491749
if (bb + 1 == 0)
17501750
break;
1751-
if (badblocks_set(&rdev->badblocks, sector, count, 1))
1751+
if (!badblocks_set(&rdev->badblocks, sector, count, 1))
17521752
return -EINVAL;
17531753
}
17541754
} else if (sb->bblog_offset != 0)
@@ -9833,7 +9833,6 @@ int rdev_set_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
98339833
int is_new)
98349834
{
98359835
struct mddev *mddev = rdev->mddev;
9836-
int rv;
98379836

98389837
/*
98399838
* Recording new badblocks for faulty rdev will force unnecessary
@@ -9849,33 +9848,35 @@ int rdev_set_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
98499848
s += rdev->new_data_offset;
98509849
else
98519850
s += rdev->data_offset;
9852-
rv = badblocks_set(&rdev->badblocks, s, sectors, 0);
9853-
if (rv == 0) {
9854-
/* Make sure they get written out promptly */
9855-
if (test_bit(ExternalBbl, &rdev->flags))
9856-
sysfs_notify_dirent_safe(rdev->sysfs_unack_badblocks);
9857-
sysfs_notify_dirent_safe(rdev->sysfs_state);
9858-
set_mask_bits(&mddev->sb_flags, 0,
9859-
BIT(MD_SB_CHANGE_CLEAN) | BIT(MD_SB_CHANGE_PENDING));
9860-
md_wakeup_thread(rdev->mddev->thread);
9861-
return 1;
9862-
} else
9851+
9852+
if (!badblocks_set(&rdev->badblocks, s, sectors, 0))
98639853
return 0;
9854+
9855+
/* Make sure they get written out promptly */
9856+
if (test_bit(ExternalBbl, &rdev->flags))
9857+
sysfs_notify_dirent_safe(rdev->sysfs_unack_badblocks);
9858+
sysfs_notify_dirent_safe(rdev->sysfs_state);
9859+
set_mask_bits(&mddev->sb_flags, 0,
9860+
BIT(MD_SB_CHANGE_CLEAN) | BIT(MD_SB_CHANGE_PENDING));
9861+
md_wakeup_thread(rdev->mddev->thread);
9862+
return 1;
98649863
}
98659864
EXPORT_SYMBOL_GPL(rdev_set_badblocks);
98669865

98679866
int rdev_clear_badblocks(struct md_rdev *rdev, sector_t s, int sectors,
98689867
int is_new)
98699868
{
9870-
int rv;
98719869
if (is_new)
98729870
s += rdev->new_data_offset;
98739871
else
98749872
s += rdev->data_offset;
9875-
rv = badblocks_clear(&rdev->badblocks, s, sectors);
9876-
if ((rv == 0) && test_bit(ExternalBbl, &rdev->flags))
9873+
9874+
if (!badblocks_clear(&rdev->badblocks, s, sectors))
9875+
return 0;
9876+
9877+
if (test_bit(ExternalBbl, &rdev->flags))
98779878
sysfs_notify_dirent_safe(rdev->sysfs_badblocks);
9878-
return rv;
9879+
return 1;
98799880
}
98809881
EXPORT_SYMBOL_GPL(rdev_clear_badblocks);
98819882

drivers/nvdimm/badrange.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static void set_badblock(struct badblocks *bb, sector_t s, int num)
167167
dev_dbg(bb->dev, "Found a bad range (0x%llx, 0x%llx)\n",
168168
(u64) s * 512, (u64) num * 512);
169169
/* this isn't an error as the hardware will still throw an exception */
170-
if (badblocks_set(bb, s, num, 1))
170+
if (!badblocks_set(bb, s, num, 1))
171171
dev_info_once(bb->dev, "%s: failed for sector %llx\n",
172172
__func__, (u64) s);
173173
}

include/linux/badblocks.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ struct badblocks_context {
5050

5151
int badblocks_check(struct badblocks *bb, sector_t s, int sectors,
5252
sector_t *first_bad, int *bad_sectors);
53-
int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
54-
int acknowledged);
55-
int badblocks_clear(struct badblocks *bb, sector_t s, int sectors);
53+
bool badblocks_set(struct badblocks *bb, sector_t s, int sectors,
54+
int acknowledged);
55+
bool badblocks_clear(struct badblocks *bb, sector_t s, int sectors);
5656
void ack_all_badblocks(struct badblocks *bb);
5757
ssize_t badblocks_show(struct badblocks *bb, char *page, int unack);
5858
ssize_t badblocks_store(struct badblocks *bb, const char *page, size_t len,

0 commit comments

Comments
 (0)