linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: mc: mc-entity.c: Use bitmap_zalloc() when applicable
@ 2021-12-01 22:19 Christophe JAILLET
  2021-12-02 12:38 ` Kieran Bingham
  2021-12-03  2:51 ` Laurent Pinchart
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2021-12-01 22:19 UTC (permalink / raw)
  To: sakari.ailus, laurent.pinchart, mchehab
  Cc: linux-media, linux-kernel, kernel-janitors, Christophe JAILLET

'ent_enum->bmap' is a bitmap. So use 'bitmap_zalloc()' to simplify
code, improve the semantic and avoid some open-coded arithmetic in
allocator arguments.

Also change the corresponding 'kfree()' into 'bitmap_free()' to keep
consistency.

While at it, remove a useless 'bitmap_zero()'.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/media/mc/mc-entity.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
index c02340698ad6..b411f9796191 100644
--- a/drivers/media/mc/mc-entity.c
+++ b/drivers/media/mc/mc-entity.c
@@ -48,12 +48,10 @@ __must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum,
 					  int idx_max)
 {
 	idx_max = ALIGN(idx_max, BITS_PER_LONG);
-	ent_enum->bmap = kcalloc(idx_max / BITS_PER_LONG, sizeof(long),
-				 GFP_KERNEL);
+	ent_enum->bmap = bitmap_zalloc(idx_max, GFP_KERNEL);
 	if (!ent_enum->bmap)
 		return -ENOMEM;
 
-	bitmap_zero(ent_enum->bmap, idx_max);
 	ent_enum->idx_max = idx_max;
 
 	return 0;
@@ -62,7 +60,7 @@ EXPORT_SYMBOL_GPL(__media_entity_enum_init);
 
 void media_entity_enum_cleanup(struct media_entity_enum *ent_enum)
 {
-	kfree(ent_enum->bmap);
+	bitmap_free(ent_enum->bmap);
 }
 EXPORT_SYMBOL_GPL(media_entity_enum_cleanup);
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] media: mc: mc-entity.c: Use bitmap_zalloc() when applicable
  2021-12-01 22:19 [PATCH] media: mc: mc-entity.c: Use bitmap_zalloc() when applicable Christophe JAILLET
@ 2021-12-02 12:38 ` Kieran Bingham
  2021-12-03  2:51 ` Laurent Pinchart
  1 sibling, 0 replies; 3+ messages in thread
From: Kieran Bingham @ 2021-12-02 12:38 UTC (permalink / raw)
  To: Christophe JAILLET, laurent.pinchart, mchehab, sakari.ailus
  Cc: linux-media, linux-kernel, kernel-janitors, Christophe JAILLET

Quoting Christophe JAILLET (2021-12-01 22:19:40)
> 'ent_enum->bmap' is a bitmap. So use 'bitmap_zalloc()' to simplify
> code, improve the semantic and avoid some open-coded arithmetic in
> allocator arguments.
> 
> Also change the corresponding 'kfree()' into 'bitmap_free()' to keep
> consistency.
> 
> While at it, remove a useless 'bitmap_zero()'.

Ah, yes kcalloc zeros memory, so it is doing a redundant clear as well.
Changing to bitmap_zalloc looks a lot better though.

Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>

> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/media/mc/mc-entity.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
> index c02340698ad6..b411f9796191 100644
> --- a/drivers/media/mc/mc-entity.c
> +++ b/drivers/media/mc/mc-entity.c
> @@ -48,12 +48,10 @@ __must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum,
>                                           int idx_max)
>  {
>         idx_max = ALIGN(idx_max, BITS_PER_LONG);
> -       ent_enum->bmap = kcalloc(idx_max / BITS_PER_LONG, sizeof(long),
> -                                GFP_KERNEL);
> +       ent_enum->bmap = bitmap_zalloc(idx_max, GFP_KERNEL);
>         if (!ent_enum->bmap)
>                 return -ENOMEM;
>  
> -       bitmap_zero(ent_enum->bmap, idx_max);
>         ent_enum->idx_max = idx_max;
>  
>         return 0;
> @@ -62,7 +60,7 @@ EXPORT_SYMBOL_GPL(__media_entity_enum_init);
>  
>  void media_entity_enum_cleanup(struct media_entity_enum *ent_enum)
>  {
> -       kfree(ent_enum->bmap);
> +       bitmap_free(ent_enum->bmap);
>  }
>  EXPORT_SYMBOL_GPL(media_entity_enum_cleanup);
>  
> -- 
> 2.30.2
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] media: mc: mc-entity.c: Use bitmap_zalloc() when applicable
  2021-12-01 22:19 [PATCH] media: mc: mc-entity.c: Use bitmap_zalloc() when applicable Christophe JAILLET
  2021-12-02 12:38 ` Kieran Bingham
@ 2021-12-03  2:51 ` Laurent Pinchart
  1 sibling, 0 replies; 3+ messages in thread
From: Laurent Pinchart @ 2021-12-03  2:51 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: sakari.ailus, mchehab, linux-media, linux-kernel, kernel-janitors

Hi Christophe,

Thank you for the patch.

On Wed, Dec 01, 2021 at 11:19:40PM +0100, Christophe JAILLET wrote:
> 'ent_enum->bmap' is a bitmap. So use 'bitmap_zalloc()' to simplify
> code, improve the semantic and avoid some open-coded arithmetic in
> allocator arguments.
> 
> Also change the corresponding 'kfree()' into 'bitmap_free()' to keep
> consistency.
> 
> While at it, remove a useless 'bitmap_zero()'.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/media/mc/mc-entity.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
> index c02340698ad6..b411f9796191 100644
> --- a/drivers/media/mc/mc-entity.c
> +++ b/drivers/media/mc/mc-entity.c
> @@ -48,12 +48,10 @@ __must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum,
>  					  int idx_max)
>  {
>  	idx_max = ALIGN(idx_max, BITS_PER_LONG);
> -	ent_enum->bmap = kcalloc(idx_max / BITS_PER_LONG, sizeof(long),
> -				 GFP_KERNEL);
> +	ent_enum->bmap = bitmap_zalloc(idx_max, GFP_KERNEL);
>  	if (!ent_enum->bmap)
>  		return -ENOMEM;
>  
> -	bitmap_zero(ent_enum->bmap, idx_max);
>  	ent_enum->idx_max = idx_max;
>  
>  	return 0;
> @@ -62,7 +60,7 @@ EXPORT_SYMBOL_GPL(__media_entity_enum_init);
>  
>  void media_entity_enum_cleanup(struct media_entity_enum *ent_enum)
>  {
> -	kfree(ent_enum->bmap);
> +	bitmap_free(ent_enum->bmap);
>  }
>  EXPORT_SYMBOL_GPL(media_entity_enum_cleanup);
>  

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-12-03  2:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-01 22:19 [PATCH] media: mc: mc-entity.c: Use bitmap_zalloc() when applicable Christophe JAILLET
2021-12-02 12:38 ` Kieran Bingham
2021-12-03  2:51 ` Laurent Pinchart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).