Skip to contentSkip to conversation

Small fix on devmem.c

janitor Yann Droneaud 1 participant 1 message Feb 24, 2005

lore
Share & tools
lore
#0 lore raw

Here's a little patch to call iounmap() after ioremap() in read() and write() to cleanup in case of error.

Regards

Signature · 4 lines
Yann Droneaud <[email protected]>
Ingénieur Conseil
Mandrakesoft SA
http://mandrakesoft.com/
SOURCES/linux-2.6.10.3mdk-xen/arch/xen/kernel/devmem.c renamed from xen-unstable/linux-2.6.10-xen-sparse/arch/xen/kernel/devmem.c +21 -10
@@ -43,7 +43,7 @@ static ssize_t read_mem(struct file * fi
 			size_t count, loff_t *ppos)
 {
 	unsigned long i, p = *ppos;
-	ssize_t read = 0;
+	ssize_t read = -EFAULT;
 	void *v;
 
 	if ((v = ioremap(p, count)) == NULL) {
@@ -56,16 +56,21 @@ static ssize_t read_mem(struct file * fi
 		 */
 		for (i = 0; i < count; i++)
 			if (put_user(0, buf+i))
-				return -EFAULT;
+				goto leave;
 		return count;
 	}
 	if (copy_to_user(buf, v, count))
-		return -EFAULT;
-	iounmap(v);
+		goto cleanup;
 
-	read += count;
+	read = count;
 	*ppos += read;
 
+ cleanup:
+
+	iounmap(v);
+
+ leave:
+
 	return read;
 }
 
@@ -73,18 +78,24 @@ static ssize_t write_mem(struct file * f
 			 size_t count, loff_t *ppos)
 {
 	unsigned long p = *ppos;
-	ssize_t written = 0;
+	ssize_t written = -EFAULT;
 	void *v;
 
 	if ((v = ioremap(p, count)) == NULL)
-		return -EFAULT;
+	  goto leave;
+
 	if (copy_to_user(v, buf, count))
-		return -EFAULT;
-	iounmap(v);
+	  goto cleanup;
 
-	written += count;
+	written = count;
 	*ppos += written;
 
+ cleanup:
+
+	iounmap(v);
+
+ leave:
+	
 	return written;
 }