[PATCH 06/12] btrfs: change lockdep class size check using ks->names

From: Namhyung Kim
Date: Tue Feb 08 2022 - 17:34:14 EST


With upcoming lock tracepoints config, it'd allow some lockdep
annotation code without enabling CONFIG_LOCKDEP actually. In that
config, size of the struct lock_class_key would be 0.

But it'd cause divide-by-zero in btrfs_set_buffer_lockdep_class() due
to ARRAY_SIZE macro. Let's change it to use ks->names[] instead. It
should have the same size as with ks->keys[].

Cc: Chris Mason <clm@xxxxxx>
Cc: Josef Bacik <josef@xxxxxxxxxxxxxx>
Cc: linux-btrfs@xxxxxxxxxxxxxxx
Acked-by: David Sterba <dsterba@xxxxxxxx>
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
fs/btrfs/disk-io.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 87a5addbedf6..be41e35bee92 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -190,7 +190,7 @@ void btrfs_set_buffer_lockdep_class(u64 objectid, struct extent_buffer *eb,
{
struct btrfs_lockdep_keyset *ks;

- BUG_ON(level >= ARRAY_SIZE(ks->keys));
+ BUG_ON(level >= ARRAY_SIZE(ks->names));

/* find the matching keyset, id 0 is the default entry */
for (ks = btrfs_lockdep_keysets; ks->id; ks++)
--
2.35.0.263.gb82422642f-goog