Skip to content

Commit 8eb8af4

Browse files
committed
fsverity: use WARN_ON_ONCE instead of WARN_ON
As per Linus's suggestion (https://lore.kernel.org/r/CAHk-=whefxRGyNGzCzG6BVeM=5vnvgb-XhSeFJVxJyAxAF8XRA@mail.gmail.com), use WARN_ON_ONCE instead of WARN_ON. This barely adds any extra overhead, and it makes it so that if any of these ever becomes reachable (they shouldn't, but that's the point), the logs can't be flooded. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Chaitanya Kulkarni <[email protected]> Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Eric Biggers <[email protected]>
1 parent 1238c8b commit 8eb8af4

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

fs/verity/enable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static int build_merkle_tree(struct file *filp,
165165
}
166166
}
167167
/* The root hash was filled by the last call to hash_one_block(). */
168-
if (WARN_ON(buffers[num_levels].filled != params->digest_size)) {
168+
if (WARN_ON_ONCE(buffers[num_levels].filled != params->digest_size)) {
169169
err = -EINVAL;
170170
goto out;
171171
}
@@ -277,7 +277,7 @@ static int enable_verity(struct file *filp,
277277
fsverity_err(inode, "%ps() failed with err %d",
278278
vops->end_enable_verity, err);
279279
fsverity_free_info(vi);
280-
} else if (WARN_ON(!IS_VERITY(inode))) {
280+
} else if (WARN_ON_ONCE(!IS_VERITY(inode))) {
281281
err = -EINVAL;
282282
fsverity_free_info(vi);
283283
} else {

fs/verity/hash_algs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ struct fsverity_hash_alg *fsverity_get_hash_alg(const struct inode *inode,
8484
}
8585

8686
err = -EINVAL;
87-
if (WARN_ON(alg->digest_size != crypto_ahash_digestsize(tfm)))
87+
if (WARN_ON_ONCE(alg->digest_size != crypto_ahash_digestsize(tfm)))
8888
goto err_free_tfm;
89-
if (WARN_ON(alg->block_size != crypto_ahash_blocksize(tfm)))
89+
if (WARN_ON_ONCE(alg->block_size != crypto_ahash_blocksize(tfm)))
9090
goto err_free_tfm;
9191

9292
err = mempool_init_kmalloc_pool(&alg->req_pool, 1,

fs/verity/open.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int fsverity_init_merkle_tree_params(struct merkle_tree_params *params,
8383
params->log_blocks_per_page = PAGE_SHIFT - log_blocksize;
8484
params->blocks_per_page = 1 << params->log_blocks_per_page;
8585

86-
if (WARN_ON(!is_power_of_2(params->digest_size))) {
86+
if (WARN_ON_ONCE(!is_power_of_2(params->digest_size))) {
8787
err = -EINVAL;
8888
goto out_err;
8989
}

include/linux/fsverity.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,18 +233,18 @@ static inline int fsverity_ioctl_read_metadata(struct file *filp,
233233
static inline bool fsverity_verify_blocks(struct folio *folio, size_t len,
234234
size_t offset)
235235
{
236-
WARN_ON(1);
236+
WARN_ON_ONCE(1);
237237
return false;
238238
}
239239

240240
static inline void fsverity_verify_bio(struct bio *bio)
241241
{
242-
WARN_ON(1);
242+
WARN_ON_ONCE(1);
243243
}
244244

245245
static inline void fsverity_enqueue_verify_work(struct work_struct *work)
246246
{
247-
WARN_ON(1);
247+
WARN_ON_ONCE(1);
248248
}
249249

250250
#endif /* !CONFIG_FS_VERITY */

0 commit comments

Comments
 (0)