]> git.neil.brown.name Git - history.git/commitdiff
Check for failed kmalloc() in ext3_htree_store_dirent()
authorTheodore Y. Ts'o <tytso@snap.thunk.org>
Wed, 6 Nov 2002 11:15:27 +0000 (06:15 -0500)
committerLinus Torvalds <torvalds@home.transmeta.com>
Wed, 6 Nov 2002 11:15:27 +0000 (06:15 -0500)
This patch checks for a failed kmalloc() in ext3_htree_store_dirent(),
and passes the error up to its caller, ext3_htree_fill_tree().

fs/ext3/dir.c
fs/ext3/namei.c
include/linux/ext3_fs.h

index cacacbb1f87ad5d11658beea638615f12068b7bd..936ed5234988309278d3448854f30802e807087b 100644 (file)
@@ -314,7 +314,7 @@ void ext3_htree_free_dir_info(struct dir_private_info *p)
 /*
  * Given a directory entry, enter it into the fname rb tree.
  */
-void ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
+int ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
                             __u32 minor_hash,
                             struct ext3_dir_entry_2 *dirent)
 {
@@ -329,6 +329,8 @@ void ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
        /* Create and allocate the fname structure */
        len = sizeof(struct fname) + dirent->name_len + 1;
        new_fn = kmalloc(len, GFP_KERNEL);
+       if (!new_fn)
+               return -ENOMEM;
        memset(new_fn, 0, len);
        new_fn->hash = hash;
        new_fn->minor_hash = minor_hash;
@@ -350,7 +352,7 @@ void ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
                    (new_fn->minor_hash == fname->minor_hash)) {
                        new_fn->next = fname->next;
                        fname->next = new_fn;
-                       return;
+                       return 0;
                }
                        
                if (new_fn->hash < fname->hash)
@@ -365,6 +367,7 @@ void ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
 
        rb_link_node(&new_fn->rb_hash, parent, p);
        rb_insert_color(&new_fn->rb_hash, &info->root);
+       return 0;
 }
 
 
index decb86a9fce0f63747366be940c4cce2afdd322e..0a62b9ab6aaf20573f8ba055527b95b9c82f7a77 100644 (file)
@@ -552,9 +552,11 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
        /* Add '.' and '..' from the htree header */
        if (!start_hash && !start_minor_hash) {
                de = (struct ext3_dir_entry_2 *) frames[0].bh->b_data;
-               ext3_htree_store_dirent(dir_file, 0, 0, de);
+               if ((err = ext3_htree_store_dirent(dir_file, 0, 0, de)) != 0)
+                       goto errout;
                de = ext3_next_entry(de);
-               ext3_htree_store_dirent(dir_file, 0, 0, de);
+               if ((err = ext3_htree_store_dirent(dir_file, 0, 0, de)) != 0)
+                       goto errout;
                count += 2;
        }
 
@@ -573,8 +575,9 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
                            ((hinfo.hash == start_hash) &&
                             (hinfo.minor_hash < start_minor_hash)))
                                continue;
-                       ext3_htree_store_dirent(dir_file, hinfo.hash,
-                                               hinfo.minor_hash, de);
+                       if ((err = ext3_htree_store_dirent(dir_file,
+                                  hinfo.hash, hinfo.minor_hash, de)) != 0)
+                               goto errout;
                        count++;
                }
                brelse (bh);
index 01aa11bcdb9e6c740777cbad0834276102bf038f..f4dd7540c2f5746285467554dfc72cac55dc2794 100644 (file)
@@ -689,7 +689,7 @@ extern struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb,
 extern int ext3_check_dir_entry(const char *, struct inode *,
                                struct ext3_dir_entry_2 *,
                                struct buffer_head *, unsigned long);
-extern void ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
+extern int ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
                                    __u32 minor_hash,
                                    struct ext3_dir_entry_2 *dirent);
 extern void ext3_htree_free_dir_info(struct dir_private_info *p);