patch] inotify: use bitmap.h functions

From: Robert Love
Date: Mon Sep 27 2004 - 15:39:51 EST


On Mon, 2004-09-27 at 12:48 -0700, Paul Jackson wrote:

> > unsigned long bitmask[MAX_INOTIFY_DEV_WATCHERS/BITS_PER_LONG];
>
> This assumes that MAX_INOTIFY_DEV_WATCHERS is an integral multiple
> of BITS_PER_LONG, otherwise, the last word will be missing.

Yah. Since we defined MAX_INOTIFY_DEV_WATCHERS, I presumed to be able
to ensure it was a multiple (e.g. just keep it a power of two) ...

> Perhaps this would this better be written as:
>
> DECLARE_BITMAP(bitmask, MAX_INOTIFY_DEV_WATCHERS);

... but this is indeed cleaner.

> and the clearing of it in the original patch:
>
> > + memset(dev->bitmask, 0,
> > + sizeof(unsigned long) * MAX_INOTIFY_DEV_WATCHERS / BITS_PER_LONG);
>
> might better be written as:
>
> CLEAR_BITMAP(dev->bitmask, MAX_INOTIFY_DEV_WATCHERS);

I think you mean bitmap_zero(), but yah. Agreed.

John, here is a patch to use the bitmap.h functions to manipulate the
bitmap.

Robert Love

Use <linux/bitmap.h> bitmap functions

Signed-Off-By: Robert Love <rml@xxxxxxxxxx>

drivers/char/inotify.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)

diff -urN linux-inotify/drivers/char/inotify.c linux/drivers/char/inotify.c
--- linux-inotify/drivers/char/inotify.c 2004-09-27 16:08:22.701736912 -0400
+++ linux/drivers/char/inotify.c 2004-09-27 16:20:48.012432464 -0400
@@ -21,6 +21,7 @@
*/

#include <linux/bitops.h>
+#include <linux/bitmap.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/sched.h>
@@ -64,7 +65,7 @@
* implies that the given WD is valid, unset implies it is not.
*/
struct inotify_device {
- unsigned long bitmask[MAX_INOTIFY_DEV_WATCHERS/BITS_PER_LONG];
+ DECLARE_BITMAP(bitmask, MAX_INOTIFY_DEV_WATCHERS);
struct timer_list timer;
wait_queue_head_t wait;
struct list_head events;
@@ -286,7 +287,7 @@

dev->nr_watches++;
wd = find_first_zero_bit(dev->bitmask, MAX_INOTIFY_DEV_WATCHERS);
- set_bit (wd, dev->bitmask);
+ set_bit(wd, dev->bitmask);

return wd;
}
@@ -775,8 +776,7 @@
if (!dev)
return -ENOMEM;

- memset(dev->bitmask, 0,
- sizeof(unsigned long) * MAX_INOTIFY_DEV_WATCHERS / BITS_PER_LONG);
+ bitmap_zero(dev->bitmask, MAX_INOTIFY_DEV_WATCHERS);

INIT_LIST_HEAD(&dev->events);
INIT_LIST_HEAD(&dev->watchers);