* [PATCH v2] xen-blkfront: Use the bitmap API when applicable
@ 2021-12-02 20:16 Christophe JAILLET
2021-12-14 10:59 ` Roger Pau Monné
0 siblings, 1 reply; 4+ messages in thread
From: Christophe JAILLET @ 2021-12-02 20:16 UTC (permalink / raw)
To: boris.ostrovsky, jgross, sstabellini, roger.pau, axboe
Cc: xen-devel, linux-block, linux-kernel, kernel-janitors,
Christophe JAILLET
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.
Use 'bitmap_copy()' to avoid an explicit 'memcpy()'
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
v1 --> v2: change another kfree into bitmap_free
---
drivers/block/xen-blkfront.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 700c765a759a..69cf13608ce0 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -442,22 +442,20 @@ static int xlbd_reserve_minors(unsigned int minor, unsigned int nr)
if (end > nr_minors) {
unsigned long *bitmap, *old;
- bitmap = kcalloc(BITS_TO_LONGS(end), sizeof(*bitmap),
- GFP_KERNEL);
+ bitmap = bitmap_zalloc(end, GFP_KERNEL);
if (bitmap == NULL)
return -ENOMEM;
spin_lock(&minor_lock);
if (end > nr_minors) {
old = minors;
- memcpy(bitmap, minors,
- BITS_TO_LONGS(nr_minors) * sizeof(*bitmap));
+ bitmap_copy(bitmap, minors, nr_minors);
minors = bitmap;
nr_minors = BITS_TO_LONGS(end) * BITS_PER_LONG;
} else
old = bitmap;
spin_unlock(&minor_lock);
- kfree(old);
+ bitmap_free(old);
}
spin_lock(&minor_lock);
@@ -2610,7 +2608,7 @@ static void __exit xlblk_exit(void)
xenbus_unregister_driver(&blkfront_driver);
unregister_blkdev(XENVBD_MAJOR, DEV_NAME);
- kfree(minors);
+ bitmap_free(minors);
}
module_exit(xlblk_exit);
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] xen-blkfront: Use the bitmap API when applicable
2021-12-02 20:16 [PATCH v2] xen-blkfront: Use the bitmap API when applicable Christophe JAILLET
@ 2021-12-14 10:59 ` Roger Pau Monné
2021-12-14 11:08 ` Roger Pau Monné
0 siblings, 1 reply; 4+ messages in thread
From: Roger Pau Monné @ 2021-12-14 10:59 UTC (permalink / raw)
To: Christophe JAILLET
Cc: boris.ostrovsky, jgross, sstabellini, axboe, xen-devel,
linux-block, linux-kernel, kernel-janitors
On Thu, Dec 02, 2021 at 09:16:04PM +0100, Christophe JAILLET wrote:
> 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.
>
> Use 'bitmap_copy()' to avoid an explicit 'memcpy()'
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
Thanks, Roger.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] xen-blkfront: Use the bitmap API when applicable
2021-12-14 10:59 ` Roger Pau Monné
@ 2021-12-14 11:08 ` Roger Pau Monné
2021-12-14 17:57 ` Christophe JAILLET
0 siblings, 1 reply; 4+ messages in thread
From: Roger Pau Monné @ 2021-12-14 11:08 UTC (permalink / raw)
To: Roger Pau Monné
Cc: Christophe JAILLET, boris.ostrovsky, jgross, sstabellini, axboe,
xen-devel, linux-block, linux-kernel, kernel-janitors
On Tue, Dec 14, 2021 at 11:59:39AM +0100, Roger Pau Monné wrote:
> On Thu, Dec 02, 2021 at 09:16:04PM +0100, Christophe JAILLET wrote:
> > 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.
> >
> > Use 'bitmap_copy()' to avoid an explicit 'memcpy()'
> >
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>
> Acked-by: Roger Pau Monné <roger.pau@citrix.com>
Oh, I see there's been further discussion on this to avoid relying
implicitly on the size of the bitmap being rounded to the size of an
unsigned long. I think a new version is expected then?
Thanks, Roger.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] xen-blkfront: Use the bitmap API when applicable
2021-12-14 11:08 ` Roger Pau Monné
@ 2021-12-14 17:57 ` Christophe JAILLET
0 siblings, 0 replies; 4+ messages in thread
From: Christophe JAILLET @ 2021-12-14 17:57 UTC (permalink / raw)
To: Roger Pau Monné
Cc: boris.ostrovsky, jgross, sstabellini, axboe, xen-devel,
linux-block, linux-kernel, kernel-janitors
Le 14/12/2021 à 12:08, Roger Pau Monné a écrit :
> On Tue, Dec 14, 2021 at 11:59:39AM +0100, Roger Pau Monné wrote:
>> On Thu, Dec 02, 2021 at 09:16:04PM +0100, Christophe JAILLET wrote:
>>> 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.
>>>
>>> Use 'bitmap_copy()' to avoid an explicit 'memcpy()'
>>>
>>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>>
>> Acked-by: Roger Pau Monné <roger.pau@citrix.com>
>
> Oh, I see there's been further discussion on this to avoid relying
> implicitly on the size of the bitmap being rounded to the size of an
> unsigned long. I think a new version is expected then?
>
> Thanks, Roger.
>
Yes, I'll send a patch in order to add a 'bitmap_size()'
I'll update this patch when/if it is merged.
You can drop it for now.
CJ
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-12-14 17:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-02 20:16 [PATCH v2] xen-blkfront: Use the bitmap API when applicable Christophe JAILLET
2021-12-14 10:59 ` Roger Pau Monné
2021-12-14 11:08 ` Roger Pau Monné
2021-12-14 17:57 ` Christophe JAILLET
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).