<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/block/badblocks.c, branch v6.12.80</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.12.80</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.12.80'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2025-05-29T09:02:24+00:00</updated>
<entry>
<title>badblocks: Fix a nonsense WARN_ON() which checks whether a u64 variable &lt; 0</title>
<updated>2025-05-29T09:02:24+00:00</updated>
<author>
<name>Coly Li</name>
<email>colyli@kernel.org</email>
</author>
<published>2025-03-09T16:05:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=75ae2a35536111c557952f809323e5fe1674aa09'/>
<id>urn:sha1:75ae2a35536111c557952f809323e5fe1674aa09</id>
<content type='text'>
[ Upstream commit 7e76336e14de9a2b67af96012ddd46c5676cf340 ]

In _badblocks_check(), there are lines of code like this,
1246         sectors -= len;
[snipped]
1251         WARN_ON(sectors &lt; 0);

The WARN_ON() at line 1257 doesn't make sense because sectors is
unsigned long long type and never to be &lt;0.

Fix it by checking directly checking whether sectors is less than len.

Reported-by: Dan Carpenter &lt;dan.carpenter@linaro.org&gt;
Signed-off-by: Coly Li &lt;colyli@kernel.org&gt;
Reviewed-by: Yu Kuai &lt;yukuai3@huawei.com&gt;
Link: https://lore.kernel.org/r/20250309160556.42854-1-colyli@kernel.org
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>badblocks: avoid checking invalid range in badblocks_check()</title>
<updated>2023-12-24T01:38:08+00:00</updated>
<author>
<name>Coly Li</name>
<email>colyli@suse.de</email>
</author>
<published>2023-12-24T00:28:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=146e843f6b09271233c021b1677e561b7dc16303'/>
<id>urn:sha1:146e843f6b09271233c021b1677e561b7dc16303</id>
<content type='text'>
If prev_badblocks() returns '-1', it means no valid badblocks record
before the checking range. It doesn't make sense to check whether
the input checking range is overlapped with the non-existed invalid
front range.

This patch checkes whether 'prev &gt;= 0' is true before calling
overlap_front(), to void such invalid operations.

Fixes: 3ea3354cb9f0 ("badblocks: improve badblocks_check() for multiple ranges handling")
Reported-and-tested-by: Ira Weiny &lt;ira.weiny@intel.com&gt;
Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Link: https://lore.kernel.org/nvdimm/3035e75a-9be0-4bc3-8d4a-6e52c207f277@leemhuis.info/
Cc: Dan Williams &lt;dan.j.williams@intel.com&gt;
Cc: Geliang Tang &lt;geliang.tang@suse.com&gt;
Cc: Hannes Reinecke &lt;hare@suse.de&gt;
Cc: Jens Axboe &lt;axboe@kernel.dk&gt;
Cc: NeilBrown &lt;neilb@suse.de&gt;
Cc: Vishal L Verma &lt;vishal.l.verma@intel.com&gt;
Cc: Xiao Ni &lt;xni@redhat.com&gt;
Link: https://lore.kernel.org/r/20231224002820.20234-1-colyli@suse.de
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>badblocks: switch to the improved badblock handling code</title>
<updated>2023-09-26T06:44:33+00:00</updated>
<author>
<name>Coly Li</name>
<email>colyli@suse.de</email>
</author>
<published>2023-08-11T17:05:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=aa511ff8218b3fb328181fbaac48aa5e9c5c6d93'/>
<id>urn:sha1:aa511ff8218b3fb328181fbaac48aa5e9c5c6d93</id>
<content type='text'>
This patch removes old code of badblocks_set(), badblocks_clear() and
badblocks_check(), and make them as wrappers to call _badblocks_set(),
_badblocks_clear() and _badblocks_check().

By this change now the badblock handing switch to the improved algorithm
in  _badblocks_set(), _badblocks_clear() and _badblocks_check().

This patch only contains the changes of old code deletion, new added
code for the improved algorithms are in previous patches.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Cc: Dan Williams &lt;dan.j.williams@intel.com&gt;
Cc: Geliang Tang &lt;geliang.tang@suse.com&gt;
Cc: Hannes Reinecke &lt;hare@suse.de&gt;
Cc: Jens Axboe &lt;axboe@kernel.dk&gt;
Cc: NeilBrown &lt;neilb@suse.de&gt;
Cc: Vishal L Verma &lt;vishal.l.verma@intel.com&gt;
Cc: Xiao Ni &lt;xni@redhat.com&gt;
Reviewed-by: Xiao Ni &lt;xni@redhat.com&gt;
Acked-by: Geliang Tang &lt;geliang.tang@suse.com&gt;
Link: https://lore.kernel.org/r/20230811170513.2300-7-colyli@suse.de
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>badblocks: improve badblocks_check() for multiple ranges handling</title>
<updated>2023-09-26T06:44:33+00:00</updated>
<author>
<name>Coly Li</name>
<email>colyli@suse.de</email>
</author>
<published>2023-08-11T17:05:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=3ea3354cb9f03e34ee3fab98f127ab8da4131eee'/>
<id>urn:sha1:3ea3354cb9f03e34ee3fab98f127ab8da4131eee</id>
<content type='text'>
This patch rewrites badblocks_check() with similar coding style as
_badblocks_set() and _badblocks_clear(). The only difference is bad
blocks checking may handle multiple ranges in bad tables now.

If a checking range covers multiple bad blocks range in bad block table,
like the following condition (C is the checking range, E1, E2, E3 are
three bad block ranges in bad block table),
  +------------------------------------+
  |                C                   |
  +------------------------------------+
    +----+      +----+      +----+
    | E1 |      | E2 |      | E3 |
    +----+      +----+      +----+
The improved badblocks_check() algorithm will divide checking range C
into multiple parts, and handle them in 7 runs of a while-loop,
  +--+ +----+ +----+ +----+ +----+ +----+ +----+
  |C1| | C2 | | C3 | | C4 | | C5 | | C6 | | C7 |
  +--+ +----+ +----+ +----+ +----+ +----+ +----+
       +----+        +----+        +----+
       | E1 |        | E2 |        | E3 |
       +----+        +----+        +----+
And the start LBA and length of range E1 will be set as first_bad and
bad_sectors for the caller.

The return value rule is consistent for multiple ranges. For example if
there are following bad block ranges in bad block table,
   Index No.     Start        Len         Ack
       0          400          20          1
       1          500          50          1
       2          650          20          0
the return value, first_bad, bad_sectors by calling badblocks_set() with
different checking range can be the following values,
    Checking Start, Len     Return Value   first_bad    bad_sectors
               100, 100          0           N/A           N/A
               100, 310          1           400           10
               100, 440          1           400           10
               100, 540          1           400           10
               100, 600         -1           400           10
               100, 800         -1           400           10

In order to make code review easier, this patch names the improved bad
block range checking routine as _badblocks_check() and does not change
existing badblock_check() code yet. Later patch will delete old code of
badblocks_check() and make it as a wrapper to call _badblocks_check().
Then the new added code won't mess up with the old deleted code, it will
be more clear and easier for code review.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Cc: Dan Williams &lt;dan.j.williams@intel.com&gt;
Cc: Geliang Tang &lt;geliang.tang@suse.com&gt;
Cc: Hannes Reinecke &lt;hare@suse.de&gt;
Cc: Jens Axboe &lt;axboe@kernel.dk&gt;
Cc: NeilBrown &lt;neilb@suse.de&gt;
Cc: Vishal L Verma &lt;vishal.l.verma@intel.com&gt;
Cc: Xiao Ni &lt;xni@redhat.com&gt;
Reviewed-by: Xiao Ni &lt;xni@redhat.com&gt;
Acked-by: Geliang Tang &lt;geliang.tang@suse.com&gt;
Link: https://lore.kernel.org/r/20230811170513.2300-6-colyli@suse.de
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>badblocks: improve badblocks_clear() for multiple ranges handling</title>
<updated>2023-09-26T06:44:33+00:00</updated>
<author>
<name>Coly Li</name>
<email>colyli@suse.de</email>
</author>
<published>2023-08-11T17:05:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=db448eb6862979aad2468ecf957a20ef98b82f29'/>
<id>urn:sha1:db448eb6862979aad2468ecf957a20ef98b82f29</id>
<content type='text'>
With the fundamental ideas and helper routines from badblocks_set()
improvement, clearing bad block for multiple ranges is much simpler.

With a similar idea from badblocks_set() improvement, this patch
simplifies bad block range clearing into 5 situations. No matter how
complicated the clearing condition is, we just look at the head part
of clearing range with relative already set bad block range from the
bad block table. The rested part will be handled in next run of the
while-loop.

Based on existing helpers added from badblocks_set(), this patch adds
two more helpers,
- front_clear()
  Clear the bad block range from bad block table which is front
  overlapped with the clearing range.
- front_splitting_clear()
  Handle the condition that the clearing range hits middle of an
  already set bad block range from bad block table.

Similar as badblocks_set(), the first part of clearing range is handled
with relative bad block range which is find by prev_badblocks(). In most
cases a valid hint is provided to prev_badblocks() to avoid unnecessary
bad block table iteration.

This patch also explains the detail algorithm code comments at beginning
of badblocks.c, including which five simplified situations are
categrized and how all the bad block range clearing conditions are
handled by these five situations.

Again, in order to make the code review easier and avoid the code
changes mixed together, this patch does not modify badblock_clear() and
implement another routine called _badblock_clear() for the improvement.
Later patch will delete current code of badblock_clear() and make it as
a wrapper to _badblock_clear(), so the code change can be much clear for
review.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Cc: Dan Williams &lt;dan.j.williams@intel.com&gt;
Cc: Geliang Tang &lt;geliang.tang@suse.com&gt;
Cc: Hannes Reinecke &lt;hare@suse.de&gt;
Cc: Jens Axboe &lt;axboe@kernel.dk&gt;
Cc: NeilBrown &lt;neilb@suse.de&gt;
Cc: Vishal L Verma &lt;vishal.l.verma@intel.com&gt;
Cc: Xiao Ni &lt;xni@redhat.com&gt;
Reviewed-by: Xiao Ni &lt;xni@redhat.com&gt;
Acked-by: Geliang Tang &lt;geliang.tang@suse.com&gt;
Link: https://lore.kernel.org/r/20230811170513.2300-5-colyli@suse.de
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>badblocks: improve badblocks_set() for multiple ranges handling</title>
<updated>2023-09-26T06:44:33+00:00</updated>
<author>
<name>Coly Li</name>
<email>colyli@suse.de</email>
</author>
<published>2023-08-11T17:05:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=1726c774678331b4af5e78db87e10ff5da448456'/>
<id>urn:sha1:1726c774678331b4af5e78db87e10ff5da448456</id>
<content type='text'>
Recently I received a bug report that current badblocks code does not
properly handle multiple ranges. For example,
        badblocks_set(bb, 32, 1, true);
        badblocks_set(bb, 34, 1, true);
        badblocks_set(bb, 36, 1, true);
        badblocks_set(bb, 32, 12, true);
Then indeed badblocks_show() reports,
        32 3
        36 1
But the expected bad blocks table should be,
        32 12
Obviously only the first 2 ranges are merged and badblocks_set() returns
and ignores the rest setting range.

This behavior is improper, if the caller of badblocks_set() wants to set
a range of blocks into bad blocks table, all of the blocks in the range
should be handled even the previous part encountering failure.

The desired way to set bad blocks range by badblocks_set() is,
- Set as many as blocks in the setting range into bad blocks table.
- Merge the bad blocks ranges and occupy as less as slots in the bad
  blocks table.
- Fast.

Indeed the above proposal is complicated, especially with the following
restrictions,
- The setting bad blocks range can be acknowledged or not acknowledged.
- The bad blocks table size is limited.
- Memory allocation should be avoided.

The basic idea of the patch is to categorize all possible bad blocks
range setting combinations into much less simplified and more less
special conditions. Inside badblocks_set() there is an implicit loop
composed by jumping between labels 're_insert' and 'update_sectors'. No
matter how large the setting bad blocks range is, in every loop just a
minimized range from the head is handled by a pre-defined behavior from
one of the categorized conditions. The logic is simple and code flow is
manageable.

The different relative layout between the setting range and existing bad
block range are checked and handled (merge, combine, overwrite, insert)
by the helpers in previous patch. This patch is to make all the helpers
work together with the above idea.

This patch only has the algorithm improvement for badblocks_set(). There
are following patches contain improvement for badblocks_clear() and
badblocks_check(). But the algorithm in badblocks_set() is fundamental
and typical, other improvement in clear and check routines are based on
all the helpers and ideas in this patch.

In order to make the change to be more clear for code review, this patch
does not directly modify existing badblocks_set(), and just add a new
one named _badblocks_set(). Later patch will remove current existing
badblocks_set() code and make it as a wrapper of _badblocks_set(). So
the new added change won't be mixed with deleted code, the code review
can be easier.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Cc: Dan Williams &lt;dan.j.williams@intel.com&gt;
Cc: Geliang Tang &lt;geliang.tang@suse.com&gt;
Cc: Hannes Reinecke &lt;hare@suse.de&gt;
Cc: Jens Axboe &lt;axboe@kernel.dk&gt;
Cc: NeilBrown &lt;neilb@suse.de&gt;
Cc: Vishal L Verma &lt;vishal.l.verma@intel.com&gt;
Cc: Wols Lists &lt;antlists@youngman.org.uk&gt;
Cc: Xiao Ni &lt;xni@redhat.com&gt;
Reviewed-by: Xiao Ni &lt;xni@redhat.com&gt;
Acked-by: Geliang Tang &lt;geliang.tang@suse.com&gt;
Link: https://lore.kernel.org/r/20230811170513.2300-4-colyli@suse.de
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>badblocks: add helper routines for badblock ranges handling</title>
<updated>2023-09-26T06:44:33+00:00</updated>
<author>
<name>Coly Li</name>
<email>colyli@suse.de</email>
</author>
<published>2023-08-11T17:05:08+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=c3c6a86e9efc5da5964260c322fe07feca6df782'/>
<id>urn:sha1:c3c6a86e9efc5da5964260c322fe07feca6df782</id>
<content type='text'>
This patch adds several helper routines to improve badblock ranges
handling. These helper routines will be used later in the improved
version of badblocks_set()/badblocks_clear()/badblocks_check().

- Helpers prev_by_hint() and prev_badblocks() are used to find the bad
  range from bad table which the searching range starts at or after.

- The following helpers are to decide the relative layout between the
  manipulating range and existing bad block range from bad table.
  - can_merge_behind()
    Return 'true' if the manipulating range can backward merge with the
    bad block range.
  - can_merge_front()
    Return 'true' if the manipulating range can forward merge with the
    bad block range.
  - can_combine_front()
    Return 'true' if two adjacent bad block ranges before the
    manipulating range can be merged.
  - overlap_front()
    Return 'true' if the manipulating range exactly overlaps with the
    bad block range in front of its range.
  - overlap_behind()
    Return 'true' if the manipulating range exactly overlaps with the
    bad block range behind its range.
  - can_front_overwrite()
    Return 'true' if the manipulating range can forward overwrite the
    bad block range in front of its range.

- The following helpers are to add the manipulating range into the bad
  block table. Different routine is called with the specific relative
  layout between the manipulating range and other bad block range in the
  bad block table.
  - behind_merge()
    Merge the manipulating range with the bad block range behind its
    range, and return the number of merged length in unit of sector.
  - front_merge()
    Merge the manipulating range with the bad block range in front of
    its range, and return the number of merged length in unit of sector.
  - front_combine()
    Combine the two adjacent bad block ranges before the manipulating
    range into a larger one.
  - front_overwrite()
    Overwrite partial of whole bad block range which is in front of the
    manipulating range. The overwrite may split existing bad block range
    and generate more bad block ranges into the bad block table.
  - insert_at()
    Insert the manipulating range at a specific location in the bad
    block table.

All the above helpers are used in later patches to improve the bad block
ranges handling for badblocks_set()/badblocks_clear()/badblocks_check().

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Cc: Dan Williams &lt;dan.j.williams@intel.com&gt;
Cc: Geliang Tang &lt;geliang.tang@suse.com&gt;
Cc: Hannes Reinecke &lt;hare@suse.de&gt;
Cc: Jens Axboe &lt;axboe@kernel.dk&gt;
Cc: NeilBrown &lt;neilb@suse.de&gt;
Cc: Vishal L Verma &lt;vishal.l.verma@intel.com&gt;
Cc: Xiao Ni &lt;xni@redhat.com&gt;
Reviewed-by: Xiao Ni &lt;xni@redhat.com&gt;
Acked-by: Geliang Tang &lt;geliang.tang@suse.com&gt;
Link: https://lore.kernel.org/r/20230811170513.2300-3-colyli@suse.de
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>block/badblocks: Remove redundant assignments</title>
<updated>2022-04-23T13:15:26+00:00</updated>
<author>
<name>Michal Orzel</name>
<email>michalorzel.eng@gmail.com</email>
</author>
<published>2022-04-23T11:38:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=3de2e5f28cb133f1d9c1b2403079722d0e7b671e'/>
<id>urn:sha1:3de2e5f28cb133f1d9c1b2403079722d0e7b671e</id>
<content type='text'>
Get rid of redundant assignments to a variable sectors from functions
badblocks_check and badblocks_clear. This variable, that is a function
parameter, is being assigned a value that is never read until the end of
function.

Reported by clang-tidy [deadcode.DeadStores]

Signed-off-by: Michal Orzel &lt;michalorzel.eng@gmail.com&gt;
Link: https://lore.kernel.org/r/20220423113811.13335-1-michalorzel.eng@gmail.com
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>treewide: Use fallthrough pseudo-keyword</title>
<updated>2020-08-23T22:36:59+00:00</updated>
<author>
<name>Gustavo A. R. Silva</name>
<email>gustavoars@kernel.org</email>
</author>
<published>2020-08-23T22:36:59+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=df561f6688fef775baa341a0f5d960becd248b11'/>
<id>urn:sha1:df561f6688fef775baa341a0f5d960becd248b11</id>
<content type='text'>
Replace the existing /* fall through */ comments and its variants with
the new pseudo-keyword macro fallthrough[1]. Also, remove unnecessary
fall-through markings when it is the case.

[1] https://www.kernel.org/doc/html/v5.7/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

Signed-off-by: Gustavo A. R. Silva &lt;gustavoars@kernel.org&gt;
</content>
</entry>
<entry>
<title>block: switch all files cleared marked as GPLv2 to SPDX tags</title>
<updated>2019-04-30T22:11:57+00:00</updated>
<author>
<name>Christoph Hellwig</name>
<email>hch@lst.de</email>
</author>
<published>2019-04-30T18:42:39+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=8c16567d867ed3185a67d8560e051090486d3ff1'/>
<id>urn:sha1:8c16567d867ed3185a67d8560e051090486d3ff1</id>
<content type='text'>
All these files have some form of the usual GPLv2 boilerplate.  Switch
them to use SPDX tags instead.

Reviewed-by: Chaitanya Kulkarni &lt;chaitanya.kulkarni@wdc.com&gt;
Signed-off-by: Christoph Hellwig &lt;hch@lst.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
</feed>
