From: Yann Droneaud Subject: [janitor] Small fix on devmem.c Date: Thu, 24 Feb 2005 12:40:54 +0100 Message-ID: <1109245254.11697.31.camel@dhcp103.edge-it.subnet> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-NeTmA2FQ2TW5zNSs0EGN" Sender: xen-devel-admin@lists.sourceforge.net Errors-To: xen-devel-admin@lists.sourceforge.net List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , List-Archive: To: xen-devel@lists.sourceforge.net List-Id: xen-devel@lists.xenproject.org --=-NeTmA2FQ2TW5zNSs0EGN Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Here's a little patch to call iounmap() after ioremap() in read() and write() to cleanup in case of error. Regards --=20 Yann Droneaud Ing=E9nieur Conseil Mandrakesoft SA http://mandrakesoft.com/ --=-NeTmA2FQ2TW5zNSs0EGN Content-Disposition: attachment; filename=devmem.c.cleanup.path Content-Type: text/plain; name=devmem.c.cleanup.path; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit --- 20050223/xen-unstable/linux-2.6.10-xen-sparse/arch/xen/kernel/devmem.c 2005-02-23 05:12:38.000000000 +0100 +++ mandrake/SOURCES/linux-2.6.10.3mdk-xen/arch/xen/kernel/devmem.c 2005-02-24 12:23:15.920125424 +0100 @@ -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; } --=-NeTmA2FQ2TW5zNSs0EGN-- ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click