linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] coresight: Use devm_bitmap_zalloc when applicable
@ 2021-10-23 19:24 Christophe JAILLET
  2021-10-23 19:36 ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: Christophe JAILLET @ 2021-10-23 19:24 UTC (permalink / raw)
  To: mathieu.poirier, suzuki.poulose, mike.leach, leo.yan,
	alexander.shishkin, mcoquelin.stm32, alexandre.torgue
  Cc: coresight, linux-arm-kernel, linux-stm32, linux-kernel,
	kernel-janitors, Christophe JAILLET

'drvdata->chs.guaranteed' is a bitmap. So use 'devm_bitmap_kzalloc()' to
simplify code, improve the semantic and avoid some open-coded arithmetic
in allocator arguments.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/hwtracing/coresight/coresight-stm.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracing/coresight/coresight-stm.c
index 58062a5a8238..db9eada24275 100644
--- a/drivers/hwtracing/coresight/coresight-stm.c
+++ b/drivers/hwtracing/coresight/coresight-stm.c
@@ -862,7 +862,6 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id)
 	struct stm_drvdata *drvdata;
 	struct resource *res = &adev->res;
 	struct resource ch_res;
-	size_t bitmap_size;
 	struct coresight_desc desc = { 0 };
 
 	desc.name = coresight_alloc_device_name(&stm_devs, dev);
@@ -904,9 +903,7 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id)
 	else
 		drvdata->numsp = stm_num_stimulus_port(drvdata);
 
-	bitmap_size = BITS_TO_LONGS(drvdata->numsp) * sizeof(long);
-
-	guaranteed = devm_kzalloc(dev, bitmap_size, GFP_KERNEL);
+	guaranteed = devm_bitmap_zalloc(dev, drvdata->numsp, GFP_KERNEL);
 	if (!guaranteed)
 		return -ENOMEM;
 	drvdata->chs.guaranteed = guaranteed;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] coresight: Use devm_bitmap_zalloc when applicable
  2021-10-23 19:24 [PATCH] coresight: Use devm_bitmap_zalloc when applicable Christophe JAILLET
@ 2021-10-23 19:36 ` Joe Perches
  2021-10-23 20:09   ` Christophe JAILLET
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2021-10-23 19:36 UTC (permalink / raw)
  To: Christophe JAILLET, mathieu.poirier, suzuki.poulose, mike.leach,
	leo.yan, alexander.shishkin, mcoquelin.stm32, alexandre.torgue
  Cc: coresight, linux-arm-kernel, linux-stm32, linux-kernel,
	kernel-janitors

On Sat, 2021-10-23 at 21:24 +0200, Christophe JAILLET wrote:
> 'drvdata->chs.guaranteed' is a bitmap. So use 'devm_bitmap_kzalloc()' to
> simplify code, improve the semantic and avoid some open-coded arithmetic
> in allocator arguments.
[]
> diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracing/coresight/coresight-stm.c
[]
> @@ -862,7 +862,6 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id)
>  	struct stm_drvdata *drvdata;
>  	struct resource *res = &adev->res;
>  	struct resource ch_res;
> -	size_t bitmap_size;
>  	struct coresight_desc desc = { 0 };
>  
>  	desc.name = coresight_alloc_device_name(&stm_devs, dev);
> @@ -904,9 +903,7 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id)
>  	else
>  		drvdata->numsp = stm_num_stimulus_port(drvdata);
>  
> -	bitmap_size = BITS_TO_LONGS(drvdata->numsp) * sizeof(long);
> -
> -	guaranteed = devm_kzalloc(dev, bitmap_size, GFP_KERNEL);
> +	guaranteed = devm_bitmap_zalloc(dev, drvdata->numsp, GFP_KERNEL);
>  	if (!guaranteed)
>  		return -ENOMEM;
>  	drvdata->chs.guaranteed = guaranteed;

guaranteed is also pretty useless




_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] coresight: Use devm_bitmap_zalloc when applicable
  2021-10-23 19:36 ` Joe Perches
@ 2021-10-23 20:09   ` Christophe JAILLET
  2021-10-28 16:44     ` Mathieu Poirier
  0 siblings, 1 reply; 4+ messages in thread
From: Christophe JAILLET @ 2021-10-23 20:09 UTC (permalink / raw)
  To: Joe Perches, mathieu.poirier, suzuki.poulose, mike.leach, leo.yan,
	alexander.shishkin, mcoquelin.stm32, alexandre.torgue
  Cc: coresight, linux-arm-kernel, linux-stm32, linux-kernel,
	kernel-janitors

Le 23/10/2021 à 21:36, Joe Perches a écrit :
> On Sat, 2021-10-23 at 21:24 +0200, Christophe JAILLET wrote:
>> 'drvdata->chs.guaranteed' is a bitmap. So use 'devm_bitmap_kzalloc()' to
>> simplify code, improve the semantic and avoid some open-coded arithmetic
>> in allocator arguments.
> []
>> diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracing/coresight/coresight-stm.c
> []
>> @@ -862,7 +862,6 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id)
>>   	struct stm_drvdata *drvdata;
>>   	struct resource *res = &adev->res;
>>   	struct resource ch_res;
>> -	size_t bitmap_size;
>>   	struct coresight_desc desc = { 0 };
>>   
>>   	desc.name = coresight_alloc_device_name(&stm_devs, dev);
>> @@ -904,9 +903,7 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id)
>>   	else
>>   		drvdata->numsp = stm_num_stimulus_port(drvdata);
>>   
>> -	bitmap_size = BITS_TO_LONGS(drvdata->numsp) * sizeof(long);
>> -
>> -	guaranteed = devm_kzalloc(dev, bitmap_size, GFP_KERNEL);
>> +	guaranteed = devm_bitmap_zalloc(dev, drvdata->numsp, GFP_KERNEL);
>>   	if (!guaranteed)
>>   		return -ENOMEM;
>>   	drvdata->chs.guaranteed = guaranteed;
> 
> guaranteed is also pretty useless
> 

I agree, but removing it would make the line with devm_bitmap_zalloc() 
86 chars. This would not be consistent with the rest of the file and 
would (IMHO) require splitting.

Let see if the maintainer prefer saving one additional line of code, or 
keeping the logic in place.

CJ


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] coresight: Use devm_bitmap_zalloc when applicable
  2021-10-23 20:09   ` Christophe JAILLET
@ 2021-10-28 16:44     ` Mathieu Poirier
  0 siblings, 0 replies; 4+ messages in thread
From: Mathieu Poirier @ 2021-10-28 16:44 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Joe Perches, suzuki.poulose, mike.leach, leo.yan,
	alexander.shishkin, mcoquelin.stm32, alexandre.torgue, coresight,
	linux-arm-kernel, linux-stm32, linux-kernel, kernel-janitors

Good day,

On Sat, Oct 23, 2021 at 10:09:14PM +0200, Christophe JAILLET wrote:
> Le 23/10/2021 à 21:36, Joe Perches a écrit :
> > On Sat, 2021-10-23 at 21:24 +0200, Christophe JAILLET wrote:
> > > 'drvdata->chs.guaranteed' is a bitmap. So use 'devm_bitmap_kzalloc()' to
> > > simplify code, improve the semantic and avoid some open-coded arithmetic
> > > in allocator arguments.
> > []
> > > diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracing/coresight/coresight-stm.c
> > []
> > > @@ -862,7 +862,6 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id)
> > >   	struct stm_drvdata *drvdata;
> > >   	struct resource *res = &adev->res;
> > >   	struct resource ch_res;
> > > -	size_t bitmap_size;
> > >   	struct coresight_desc desc = { 0 };
> > >   	desc.name = coresight_alloc_device_name(&stm_devs, dev);
> > > @@ -904,9 +903,7 @@ static int stm_probe(struct amba_device *adev, const struct amba_id *id)
> > >   	else
> > >   		drvdata->numsp = stm_num_stimulus_port(drvdata);
> > > -	bitmap_size = BITS_TO_LONGS(drvdata->numsp) * sizeof(long);
> > > -
> > > -	guaranteed = devm_kzalloc(dev, bitmap_size, GFP_KERNEL);
> > > +	guaranteed = devm_bitmap_zalloc(dev, drvdata->numsp, GFP_KERNEL);
> > >   	if (!guaranteed)
> > >   		return -ENOMEM;
> > >   	drvdata->chs.guaranteed = guaranteed;
> > 
> > guaranteed is also pretty useless
> > 
> 
> I agree, but removing it would make the line with devm_bitmap_zalloc() 86
> chars. This would not be consistent with the rest of the file and would
> (IMHO) require splitting.
> 
> Let see if the maintainer prefer saving one additional line of code, or
> keeping the logic in place.

I think we can get rid of @guaranteed and splitting is fine with me:

        drvdata->chs.guaranteed = devm_bitmap_zalloc(dev,
                                                     drvdata->numsp,
                                                     GFP_KERNEL);

Thanks,
Mathieu


> 
> CJ
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2021-10-28 16:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-23 19:24 [PATCH] coresight: Use devm_bitmap_zalloc when applicable Christophe JAILLET
2021-10-23 19:36 ` Joe Perches
2021-10-23 20:09   ` Christophe JAILLET
2021-10-28 16:44     ` Mathieu Poirier

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).