[DRBD-user] [PATCH] tree wide: Use kvfree() than conditional kfree()/vfree()

Lars Ellenberg lars.ellenberg at linbit.com
Tue Nov 10 14:34:00 CET 2015

Note: "permalinks" may not be as permanent as we would like,
direct links of old sources may well be a few messages off.


On Mon, Nov 09, 2015 at 08:56:10PM +0900, Tetsuo Handa wrote:
> There are many locations that do
> 
>   if (memory_was_allocated_by_vmalloc)
>     vfree(ptr);
>   else
>     kfree(ptr);
> 
> but kvfree() can handle both kmalloc()ed memory and vmalloc()ed memory
> using is_vmalloc_addr(). Unless callers have special reasons, we can
> replace this branch with kvfree(). Please check and reply if you found
> problems.

For the DRBD part:

>  drivers/block/drbd/drbd_bitmap.c                   | 26 +++++------------
>  drivers/block/drbd/drbd_int.h                      |  3 --

> diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
> index 9462d27..2daaafb 100644
> --- a/drivers/block/drbd/drbd_bitmap.c
> +++ b/drivers/block/drbd/drbd_bitmap.c
> @@ -364,12 +364,9 @@ static void bm_free_pages(struct page **pages, unsigned long number)
>  	}
>  }
>  
> -static void bm_vk_free(void *ptr, int v)
> +static inline void bm_vk_free(void *ptr)

Maybe drop this inline completely ...

>  {
> -	if (v)
> -		vfree(ptr);
> -	else
> -		kfree(ptr);
> +	kvfree(ptr);
>  }

... and just call kvfree() directly below?

> -				bm_vk_free(new_pages, vmalloced);
> +				bm_vk_free(new_pages);

  +				kvfree(new_pages);
  ...


Other than that: looks good and harmless enough.
Thanks,

	Lars




More information about the drbd-user mailing list