ocfs2: ocfs2_write_begin_nolock() should handle len=0
authorSunil Mushran <sunil.mushran@oracle.com>
Fri, 4 Sep 2009 18:12:01 +0000 (11:12 -0700)
committerJoel Becker <joel.becker@oracle.com>
Fri, 4 Sep 2009 21:28:31 +0000 (14:28 -0700)
Bug introduced by mainline commit e7432675f8ca868a4af365759a8d4c3779a3d922
The bug causes ocfs2_write_begin_nolock() to oops when len=0.

Signed-off-by: Sunil Mushran <sunil.mushran@oracle.com>
Cc: stable@kernel.org
Signed-off-by: Joel Becker <joel.becker@oracle.com>
fs/ocfs2/aops.c

index b401654011a2b64c4e55f87c7916e3badc07f68e..8a1e61545f4169de491eb00ee6c661ebf0054a30 100644 (file)
@@ -1747,8 +1747,8 @@ int ocfs2_write_begin_nolock(struct address_space *mapping,
         * we know zeros will only be needed in the first and/or last cluster.
         */
        if (clusters_to_alloc || extents_to_split ||
-           wc->w_desc[0].c_needs_zero ||
-           wc->w_desc[wc->w_clen - 1].c_needs_zero)
+           (wc->w_clen && (wc->w_desc[0].c_needs_zero ||
+                           wc->w_desc[wc->w_clen - 1].c_needs_zero)))
                cluster_of_pages = 1;
        else
                cluster_of_pages = 0;