cifs: verify that tcon is valid before dereference in cifs_kill_sb
[sfrench/cifs-2.6.git] / fs / cifs / cifsfs.c
index aba0783a8f09b084868518514fce7a9918b4f421..2b1a1c029c75ec19376a7250fb806b516e59ad03 100644 (file)
@@ -266,10 +266,11 @@ static void cifs_kill_sb(struct super_block *sb)
         * before we kill the sb.
         */
        if (cifs_sb->root) {
-               node = rb_first(root);
-               while (node != NULL) {
+               for (node = rb_first(root); node; node = rb_next(node)) {
                        tlink = rb_entry(node, struct tcon_link, tl_rbnode);
                        tcon = tlink_tcon(tlink);
+                       if (IS_ERR(tcon))
+                               continue;
                        cfid = &tcon->crfid;
                        mutex_lock(&cfid->fid_mutex);
                        if (cfid->dentry) {
@@ -277,7 +278,6 @@ static void cifs_kill_sb(struct super_block *sb)
                                cfid->dentry = NULL;
                        }
                        mutex_unlock(&cfid->fid_mutex);
-                       node = rb_next(node);
                }
 
                /* finally release root dentry */