lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 30 Dec 2021 11:28:28 +0900
From:   Damien Le Moal <damien.lemoal@...nsource.wdc.com>
To:     Christophe JAILLET <christophe.jaillet@...adoo.fr>,
        axboe@...nel.dk, chaitanya.kulkarni@....com, damien.lemoal@....com,
        ming.lei@...hat.com, Johannes.Thumshirn@....com,
        shinichiro.kawasaki@....com, jiangguoqing@...inos.cn
Cc:     linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
        kernel-janitors@...r.kernel.org
Subject: Re: [PATCH] null_blk: Use bitmap_zalloc() when applicable

On 12/24/21 06:55, Christophe JAILLET wrote:
> 'nq->tag_map' is a bitmap. So use bitmap_zalloc() to simplify code and
> improve the semantic.
> 
> Also change the corresponding kfree() into bitmap_free() to keep
> consistency.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@...adoo.fr>
> ---
>  drivers/block/null_blk/main.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
> index 6be6ccd4a28f..9e058e0aa668 100644
> --- a/drivers/block/null_blk/main.c
> +++ b/drivers/block/null_blk/main.c
> @@ -1661,7 +1661,7 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx,
>  
>  static void cleanup_queue(struct nullb_queue *nq)
>  {
> -	kfree(nq->tag_map);
> +	bitmap_free(nq->tag_map);
>  	kfree(nq->cmds);
>  }
>  
> @@ -1790,14 +1790,13 @@ static const struct block_device_operations null_rq_ops = {
>  static int setup_commands(struct nullb_queue *nq)
>  {
>  	struct nullb_cmd *cmd;
> -	int i, tag_size;
> +	int i;
>  
>  	nq->cmds = kcalloc(nq->queue_depth, sizeof(*cmd), GFP_KERNEL);
>  	if (!nq->cmds)
>  		return -ENOMEM;
>  
> -	tag_size = ALIGN(nq->queue_depth, BITS_PER_LONG) / BITS_PER_LONG;
> -	nq->tag_map = kcalloc(tag_size, sizeof(unsigned long), GFP_KERNEL);
> +	nq->tag_map = bitmap_zalloc(nq->queue_depth, GFP_KERNEL);
>  	if (!nq->tag_map) {
>  		kfree(nq->cmds);
>  		return -ENOMEM;

Before this patch, tag_size would always be a multiple of BITS_PER_LONG.
Using bitmap_zalloc(), that alignment goes away, but I think this is OK.

Reviewed-by: Damien Le Moal <damien.lemoal@...nsource.wdc.com>

-- 
Damien Le Moal
Western Digital Research

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ