Re: [PATCH] btrfs: Replace kmalloc with kzalloc in the error message

From: Joe Perches
Date: Thu May 28 2020 - 22:04:04 EST


On Fri, 2020-05-29 at 09:00 +0800, Yi Wang wrote:
> From: Liao Pingfang <liao.pingfang@xxxxxxxxxx>
>
> Use kzalloc instead of kmalloc in the error message according to
> the previous kzalloc() call.
[]
> diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
[]
> @@ -632,7 +632,7 @@ static int btrfsic_process_superblock(struct btrfsic_state *state,
>
> selected_super = kzalloc(sizeof(*selected_super), GFP_NOFS);
> if (NULL == selected_super) {
> - pr_info("btrfsic: error, kmalloc failed!\n");
> + pr_info("btrfsic: error, kzalloc failed!\n");

As there is a dump_stack() done on memory allocation
failures, these messages might as well be deleted instead.

> return -ENOMEM;
> }
>
> @@ -795,7 +795,7 @@ static int btrfsic_process_superblock_dev_mirror(
> if (NULL == superblock_tmp) {
> superblock_tmp = btrfsic_block_alloc();
> if (NULL == superblock_tmp) {
> - pr_info("btrfsic: error, kmalloc failed!\n");
> + pr_info("btrfsic: error, kzalloc failed!\n");

If these are really desired, it'd be likely be better
to describe the function that failed instead of whatever
internal memory allocation the function used.

Another option would be to add __GFP_NOWARN to the
allocation internal to btrfsic_block_alloc and then
change this to something like

pr_info("btrfsic: error, btrfsic_block_alloc failed!\n"); }

or move this reporting into the btrfsic_block_alloc
function and remove the messages after each failure.

etc...