Skip to contentSkip to conversation

ext4: locking issue on error path

PATCH In review Dan Carpenter 3 participants 3 messages Jul 17, 2012 – Jul 23, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: locking issue on error path

We recently changed how the locking worked here, but this error path was missed.

fs/ext4/inode.c +5 -2
index 8c84070..2728fb7 100644
@@ -3031,8 +3031,10 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
 		if (!is_sync_kiocb(iocb)) {
 			ext4_io_end_t *io_end  				ext4_init_io_end(inode, GFP_NOFS);
-			if (!io_end)
-				return -ENOMEM;
+			if (!io_end) {
+				ret = -ENOMEM;
+				goto retake_lock;
+			}
 			io_end->flag |= EXT4_IO_END_DIRECT;
 			iocb->private = io_end;
 			/*
@@ -3094,6 +3096,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
 			ext4_clear_inode_state(inode, EXT4_STATE_DIO_UNWRITTEN);
 		}
 
+retake_lock:
 		/* take i_mutex locking again if we do a ovewrite dio */
 		if (overwrite) {
 			up_read(&EXT4_I(inode)->i_data_sem);
#1 lore raw
Quoted 4 lines · Dan Carpenter

We recently changed how the locking worked here, but this error path was missed.

Sorry, it is my fault. Thanks for pointing out this bug.

Regards,
Zheng

Quoted 30 lines
fs/ext4/inode.c +5 -3
index 8c84070..2728fb7 100644
@@ -3031,8 +3031,10 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
 		if (!is_sync_kiocb(iocb)) {
 			ext4_io_end_t *io_end =
 				ext4_init_io_end(inode, GFP_NOFS);
-			if (!io_end)
-				return -ENOMEM;
+			if (!io_end) {
+				ret = -ENOMEM;
+				goto retake_lock;
+			}
 			io_end->flag |= EXT4_IO_END_DIRECT;
 			iocb->private = io_end;
 			/*
@@ -3094,6 +3096,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
 			ext4_clear_inode_state(inode, EXT4_STATE_DIO_UNWRITTEN);
 		}
 
+retake_lock:
 		/* take i_mutex locking again if we do a ovewrite dio */
 		if (overwrite) {
 			up_read(&EXT4_I(inode)->i_data_sem);
--

To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#2 lore raw
Quoted 7 lines · Zheng Liu
Quoted 4 lines · Dan Carpenter

We recently changed how the locking worked here, but this error path was missed.

Sorry, it is my fault. Thanks for pointing out this bug.

Since this patch hadn't been promoted past the master branch pointer (it was only in the dev branch, which can be rebased), I've merged this fix up with Zheng's original patch.

Dan, may thanks for finding and pointing it out!!

- Ted