linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] watch_queue: Use the bitmap API when applicable
@ 2021-11-28 13:58 Christophe JAILLET
  2021-11-28 13:58 ` [PATCH 2/2] watch_queue: Fix a memory leak Christophe JAILLET
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2021-11-28 13:58 UTC (permalink / raw)
  To: dhowells, lukas.bulwahn; +Cc: linux-kernel, kernel-janitors, Christophe JAILLET

Use 'bitmap_malloc()' to simplify code, improve the semantic and avoid some
open-coded arithmetic in allocator arguments.

While at it, use 'bitmap_fill()' to avoid an explicit 'memset()'

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 kernel/watch_queue.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c
index 9c9eb20dd2c5..41ea30948c57 100644
--- a/kernel/watch_queue.c
+++ b/kernel/watch_queue.c
@@ -219,7 +219,6 @@ long watch_queue_set_size(struct pipe_inode_info *pipe, unsigned int nr_notes)
 	struct page **pages;
 	unsigned long *bitmap;
 	unsigned long user_bufs;
-	unsigned int bmsize;
 	int ret, i, nr_pages;
 
 	if (!wqueue)
@@ -258,13 +257,11 @@ long watch_queue_set_size(struct pipe_inode_info *pipe, unsigned int nr_notes)
 		pages[i]->index = i * WATCH_QUEUE_NOTES_PER_PAGE;
 	}
 
-	bmsize = (nr_notes + BITS_PER_LONG - 1) / BITS_PER_LONG;
-	bmsize *= sizeof(unsigned long);
-	bitmap = kmalloc(bmsize, GFP_KERNEL);
+	bitmap = bitmap_alloc(nr_notes, GFP_KERNEL);
 	if (!bitmap)
 		goto error_p;
 
-	memset(bitmap, 0xff, bmsize);
+	bitmap_fill(bitmap, nr_notes);
 	wqueue->notes = pages;
 	wqueue->notes_bitmap = bitmap;
 	wqueue->nr_pages = nr_pages;
-- 
2.30.2


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

* [PATCH 2/2] watch_queue: Fix a memory leak
  2021-11-28 13:58 [PATCH 1/2] watch_queue: Use the bitmap API when applicable Christophe JAILLET
@ 2021-11-28 13:58 ` Christophe JAILLET
  0 siblings, 0 replies; 2+ messages in thread
From: Christophe JAILLET @ 2021-11-28 13:58 UTC (permalink / raw)
  To: dhowells, lukas.bulwahn; +Cc: linux-kernel, kernel-janitors, Christophe JAILLET

The 'notes_bitmap' is allocated in 'watch_queue_set_size()' but is never
released.
Free it when 'wqueue' and its other fields are freed.

Fixes: c73be61cede5 ("pipe: Add general notification queue support")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
WARNING: This patch is certainly buggy because there is 'rcu'
consideration, but I've nothing better to propose.

It is maybe also completely buggy because freeing reference counted
resources is sometimes puzzling!

So review with care and update as needed (if needed :) )
---
 kernel/watch_queue.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/watch_queue.c b/kernel/watch_queue.c
index 41ea30948c57..36c6822bec86 100644
--- a/kernel/watch_queue.c
+++ b/kernel/watch_queue.c
@@ -372,6 +372,7 @@ static void __put_watch_queue(struct kref *kref)
 	wfilter = rcu_access_pointer(wqueue->filter);
 	if (wfilter)
 		kfree_rcu(wfilter, rcu);
+	bitmap_free(wqueue->notes_bitmap);
 	kfree_rcu(wqueue, rcu);
 }
 
-- 
2.30.2


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

end of thread, other threads:[~2021-11-28 14:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-28 13:58 [PATCH 1/2] watch_queue: Use the bitmap API when applicable Christophe JAILLET
2021-11-28 13:58 ` [PATCH 2/2] watch_queue: Fix a memory leak 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).