[PATCH] drivers/char/stradis.c: reorganizing resource release

From: Arnaldo Carvalho de Melo (acme@conectiva.com.br)
Date: Mon Aug 14 2000 - 16:16:16 EST


Nathan

    I was looking for some class of bugs when I looked at your driver
and thought that I had found a bug (not releasing saa->dmadebi in
init_saa7146), which later I've discovered to be a non-issue, cause
release_saa takes care of it, but in the process I've modified the
source to use cleanup with gotos, could you please take a look and
consider applying?

                        - Arnaldo

--- linux-2.4.0-test7-pre3/drivers/char/stradis.c Wed Jul 5 14:56:13 2000
+++ linux-2.4.0-test7-pre3.acme/drivers/char/stradis.c Mon Aug 14 18:11:43 2000
@@ -17,6 +17,10 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Changes:
+ * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 08/14/2000
+ * - reorganize resource release on case of failure in init_saa7146
  */
 
 #include <linux/module.h>
@@ -2126,7 +2130,7 @@
         /* allocate 32k dma buffer + 4k for page table */
         if ((saa->dmadebi = kmalloc(32768 + 4096, GFP_KERNEL)) == NULL) {
                 printk(KERN_ERR "stradis%d: debi kmalloc failed\n", i);
- return -1;
+ return -ENOMEM;
         }
 #if 0
         saa->pagedebi = saa->dmadebi + 32768; /* top 4k is for mmu */
@@ -2139,32 +2143,22 @@
         if (saa->vidbuf == NULL)
                 if ((saa->vidbuf = vmalloc(524288)) == NULL) {
                         printk(KERN_ERR "stradis%d: malloc failed\n", saa->nr);
- return -ENOMEM;
+ goto cleanup_dmadebi;
                 }
         if (saa->audbuf == NULL)
                 if ((saa->audbuf = vmalloc(65536)) == NULL) {
                         printk(KERN_ERR "stradis%d: malloc failed\n", saa->nr);
- vfree(saa->vidbuf);
- saa->vidbuf = NULL;
- return -ENOMEM;
+ goto cleanup_vidbuf;
                 }
         if (saa->osdbuf == NULL)
                 if ((saa->osdbuf = vmalloc(131072)) == NULL) {
                         printk(KERN_ERR "stradis%d: malloc failed\n", saa->nr);
- vfree(saa->vidbuf);
- vfree(saa->audbuf);
- saa->vidbuf = saa->audbuf = NULL;
- return -ENOMEM;
+ goto cleanup_audbuf;
                 }
         /* allocate 81920 byte buffer for clipping */
         if ((saa->dmavid2 = kmalloc(VIDEO_CLIPMAP_SIZE, GFP_KERNEL)) == NULL) {
                 printk(KERN_ERR "stradis%d: clip kmalloc failed\n", saa->nr);
- vfree(saa->vidbuf);
- vfree(saa->audbuf);
- vfree(saa->osdbuf);
- saa->vidbuf = saa->audbuf = saa->osdbuf = NULL;
- saa->dmavid2 = NULL;
- return -1;
+ goto cleanup_osdbuf;
         }
         memset(saa->dmavid2, 0x00, VIDEO_CLIPMAP_SIZE); /* clip everything */
         /* setup clipping registers */
@@ -2178,6 +2172,20 @@
                  SAA7146_MC2);
         I2CBusScan(&(saa->i2c));
         return 0;
+
+cleanup_osdbuf:
+ vfree(saa->osdbuf);
+ saa->osdbuf = NULL;
+cleanup_audbuf:
+ vfree(saa->audbuf);
+ saa->audbuf = NULL;
+cleanup_vidbuf:
+ vfree(saa->vidbuf);
+ saa->vidbuf = NULL;
+cleanup_dmadebi:
+ kfree(saa->dmadebi);
+ saa->dmadebi = NULL;
+ return -ENOMEM;
 }
 
 static void release_saa(void)

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Aug 15 2000 - 21:00:34 EST