[gamin] Re: [RFC][PATCH] inotify 0.9.2



On Sun, 2004-09-19 at 23:56 -0400, John McCutchan wrote:

> I would appreciate design review, code review and testing.

Hello sir!

kmalloc() can fail, so check the return value and handle appropriately.

Patch is against inotify 0.9.2 plus the last patches I sent.

Thanks,

	Robert Love

kmalloc() can fail. Check the return value.

Signed-Off-By: Robert Love <rml novell com>

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

--- linux-inotify/drivers/char/inotify.c	2004-09-21 01:30:09.160707592 -0400
+++ linux/drivers/char/inotify.c	2004-09-21 01:40:47.777623064 -0400
@@ -551,11 +551,15 @@
 	int events;
 	int event_count;
 
-	eventbuf = kmalloc(sizeof(struct inotify_event) * MAX_EVENTS_AT_ONCE, 
-			GFP_KERNEL);
+	out = -ENOMEM;
+	eventbuf = kmalloc(sizeof(struct inotify_event) * MAX_EVENTS_AT_ONCE,
+			   GFP_KERNEL);
+	if (!eventbuf)
+		goto out;
+
+	out = 0;
 	events = 0;
 	event_count = 0;
-	out = 0;
 	err = 0;
 
 	obuf = buf;
@@ -644,7 +648,8 @@
 	}
 }
 
-static int inotify_open(struct inode *inode, struct file *file) {
+static int inotify_open(struct inode *inode, struct file *file)
+{
 	struct inotify_device *dev;
 
 	if (atomic_read(&watcher_count) == MAX_INOTIFY_DEVS)
@@ -653,7 +658,11 @@
 	atomic_inc(&watcher_count);
 
 	dev = kmalloc(sizeof(struct inotify_device), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
 	dev->bitmask = kmalloc(__BITMASK_SIZE, GFP_KERNEL);
+	if (!dev->bitmask)
+		return -ENOMEM;
 	memset(dev->bitmask, 0, __BITMASK_SIZE);
 
 	INIT_LIST_HEAD(&dev->events);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]