Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <zhengqixing@huawei.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Acked-by: Coly Li <colyli@kernel.org>
Acked-by: Ira Weiny <ira.weiny@intel.com>
Link: https://lore.kernel.org/r/20250227075507.151331-11-zhengqixing@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Zheng Qixing and committed by
Jens Axboe
c8775aef 5236f041

+49 -49
+20 -21
block/badblocks.c
··· 836 836 } 837 837 838 838 /* 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) 841 841 { 842 842 int len = 0, added = 0; 843 843 struct badblocks_context bad; ··· 847 847 848 848 if (bb->shift < 0) 849 849 /* badblocks are disabled */ 850 - return 1; 850 + return false; 851 851 852 852 if (sectors == 0) 853 853 /* Invalid sectors number */ 854 - return 1; 854 + return false; 855 855 856 856 if (bb->shift) { 857 857 /* round the start down, and the end up */ ··· 977 977 978 978 write_sequnlock_irqrestore(&bb->lock, flags); 979 979 980 - return sectors; 980 + return sectors == 0; 981 981 } 982 982 983 983 /* ··· 1048 1048 } 1049 1049 1050 1050 /* 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) 1052 1052 { 1053 1053 struct badblocks_context bad; 1054 1054 int prev = -1, hint = -1; 1055 1055 int len = 0, cleared = 0; 1056 - int rv = 0; 1057 1056 u64 *p; 1058 1057 1059 1058 if (bb->shift < 0) 1060 1059 /* badblocks are disabled */ 1061 - return 1; 1060 + return false; 1062 1061 1063 1062 if (sectors == 0) 1064 1063 /* Invalid sectors number */ 1065 - return 1; 1064 + return false; 1066 1065 1067 1066 if (bb->shift) { 1068 1067 sector_t target; ··· 1181 1182 write_sequnlock_irq(&bb->lock); 1182 1183 1183 1184 if (!cleared) 1184 - rv = 1; 1185 + return false; 1185 1186 1186 - return rv; 1187 + return true; 1187 1188 } 1188 1189 1189 1190 /* Do the exact work to check bad blocks range from the bad block table */ ··· 1337 1338 * decide how best to handle it. 1338 1339 * 1339 1340 * Return: 1340 - * 0: success 1341 - * other: failed to set badblocks (out of space). Parital setting will be 1341 + * true: success 1342 + * false: failed to set badblocks (out of space). Parital setting will be 1342 1343 * treated as failure. 1343 1344 */ 1344 - int badblocks_set(struct badblocks *bb, sector_t s, int sectors, 1345 - int acknowledged) 1345 + bool badblocks_set(struct badblocks *bb, sector_t s, int sectors, 1346 + int acknowledged) 1346 1347 { 1347 1348 return _badblocks_set(bb, s, sectors, acknowledged); 1348 1349 } ··· 1359 1360 * drop the remove request. 1360 1361 * 1361 1362 * Return: 1362 - * 0: success 1363 - * 1: failed to clear badblocks 1363 + * true: success 1364 + * false: failed to clear badblocks 1364 1365 */ 1365 - int badblocks_clear(struct badblocks *bb, sector_t s, int sectors) 1366 + bool badblocks_clear(struct badblocks *bb, sector_t s, int sectors) 1366 1367 { 1367 1368 return _badblocks_clear(bb, s, sectors); 1368 1369 } ··· 1484 1485 return -EINVAL; 1485 1486 } 1486 1487 1487 - if (badblocks_set(bb, sector, length, !unack)) 1488 + if (!badblocks_set(bb, sector, length, !unack)) 1488 1489 return -ENOSPC; 1489 - else 1490 - return len; 1490 + 1491 + return len; 1491 1492 } 1492 1493 EXPORT_SYMBOL_GPL(badblocks_store); 1493 1494
+7 -7
drivers/block/null_blk/main.c
··· 561 561 goto out; 562 562 /* enable badblocks */ 563 563 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)) { 571 570 ret = count; 571 + } 572 572 out: 573 573 kfree(orig); 574 574 return ret;
+18 -17
drivers/md/md.c
··· 1748 1748 count <<= sb->bblog_shift; 1749 1749 if (bb + 1 == 0) 1750 1750 break; 1751 - if (badblocks_set(&rdev->badblocks, sector, count, 1)) 1751 + if (!badblocks_set(&rdev->badblocks, sector, count, 1)) 1752 1752 return -EINVAL; 1753 1753 } 1754 1754 } else if (sb->bblog_offset != 0) ··· 9833 9833 int is_new) 9834 9834 { 9835 9835 struct mddev *mddev = rdev->mddev; 9836 - int rv; 9837 9836 9838 9837 /* 9839 9838 * Recording new badblocks for faulty rdev will force unnecessary ··· 9848 9849 s += rdev->new_data_offset; 9849 9850 else 9850 9851 s += rdev->data_offset; 9851 - rv = badblocks_set(&rdev->badblocks, s, sectors, 0); 9852 - if (rv == 0) { 9853 - /* Make sure they get written out promptly */ 9854 - if (test_bit(ExternalBbl, &rdev->flags)) 9855 - sysfs_notify_dirent_safe(rdev->sysfs_unack_badblocks); 9856 - sysfs_notify_dirent_safe(rdev->sysfs_state); 9857 - set_mask_bits(&mddev->sb_flags, 0, 9858 - BIT(MD_SB_CHANGE_CLEAN) | BIT(MD_SB_CHANGE_PENDING)); 9859 - md_wakeup_thread(rdev->mddev->thread); 9860 - return 1; 9861 - } else 9852 + 9853 + if (!badblocks_set(&rdev->badblocks, s, sectors, 0)) 9862 9854 return 0; 9855 + 9856 + /* Make sure they get written out promptly */ 9857 + if (test_bit(ExternalBbl, &rdev->flags)) 9858 + sysfs_notify_dirent_safe(rdev->sysfs_unack_badblocks); 9859 + sysfs_notify_dirent_safe(rdev->sysfs_state); 9860 + set_mask_bits(&mddev->sb_flags, 0, 9861 + BIT(MD_SB_CHANGE_CLEAN) | BIT(MD_SB_CHANGE_PENDING)); 9862 + md_wakeup_thread(rdev->mddev->thread); 9863 + return 1; 9863 9864 } 9864 9865 EXPORT_SYMBOL_GPL(rdev_set_badblocks); 9865 9866 9866 9867 int rdev_clear_badblocks(struct md_rdev *rdev, sector_t s, int sectors, 9867 9868 int is_new) 9868 9869 { 9869 - int rv; 9870 9870 if (is_new) 9871 9871 s += rdev->new_data_offset; 9872 9872 else 9873 9873 s += rdev->data_offset; 9874 - rv = badblocks_clear(&rdev->badblocks, s, sectors); 9875 - if ((rv == 0) && test_bit(ExternalBbl, &rdev->flags)) 9874 + 9875 + if (!badblocks_clear(&rdev->badblocks, s, sectors)) 9876 + return 0; 9877 + 9878 + if (test_bit(ExternalBbl, &rdev->flags)) 9876 9879 sysfs_notify_dirent_safe(rdev->sysfs_badblocks); 9877 - return rv; 9880 + return 1; 9878 9881 } 9879 9882 EXPORT_SYMBOL_GPL(rdev_clear_badblocks); 9880 9883
+1 -1
drivers/nvdimm/badrange.c
··· 167 167 dev_dbg(bb->dev, "Found a bad range (0x%llx, 0x%llx)\n", 168 168 (u64) s * 512, (u64) num * 512); 169 169 /* 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)) 171 171 dev_info_once(bb->dev, "%s: failed for sector %llx\n", 172 172 __func__, (u64) s); 173 173 }
+3 -3
include/linux/badblocks.h
··· 50 50 51 51 int badblocks_check(struct badblocks *bb, sector_t s, int sectors, 52 52 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); 56 56 void ack_all_badblocks(struct badblocks *bb); 57 57 ssize_t badblocks_show(struct badblocks *bb, char *page, int unack); 58 58 ssize_t badblocks_store(struct badblocks *bb, const char *page, size_t len,