Re: [CHECKER] repetitive/contradictory comparison bugs for 2.4.7

From: Russell King (rmk@arm.linux.org.uk)
Date: Wed Jul 25 2001 - 03:27:32 EST


On Tue, Jul 24, 2001 at 05:08:23PM -0700, Evan Parker wrote:
> One of them, the last one, is pretty clearly a bug, but the
> other 10 are questionable. Those 10 are all simple variations on the
> following code:
>
> Start --->
> if (!tmp_buf) {
> page = get_free_page(GFP_KERNEL);
>
> Error --->
> if (tmp_buf)
> free_page(page);
> else
> tmp_buf = (unsigned char *) page;
> }

The following patch fixes this:

--- orig/drivers/char/serial.c Sat Jul 21 10:46:42 2001
+++ linux/drivers/char/serial.c Wed Jul 25 09:19:49 2001
@@ -3157,17 +3157,17 @@
         info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
 #endif
 
+ down(&tmp_buf_sem);
         if (!tmp_buf) {
                 page = get_zeroed_page(GFP_KERNEL);
                 if (!page) {
+ up(&tmp_buf_sem);
                         MOD_DEC_USE_COUNT;
                         return -ENOMEM;
                 }
- if (tmp_buf)
- free_page(page);
- else
- tmp_buf = (unsigned char *) page;
+ tmp_buf = (unsigned char *) page;
         }
+ up(&tmp_buf_sem);
 
         /*
          * If the port is the middle of closing, bail out now
@@ -5666,12 +5666,14 @@
                 if (DEACTIVATE_FUNC(brd->dev))
                         (DEACTIVATE_FUNC(brd->dev))(brd->dev);
         }
-#endif
+#endif
+ down(&tmp_buf_sem);
         if (tmp_buf) {
                 unsigned long pg = (unsigned long) tmp_buf;
                 tmp_buf = NULL;
                 free_page(pg);
         }
+ up(&tmp_buf_sem);
         
 #ifdef ENABLE_SERIAL_PCI
         if (serial_pci_driver.name[0])

--
Russell King (rmk@arm.linux.org.uk)                The developer of ARM Linux
             http://www.arm.linux.org.uk/personal/aboutme.html

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



This archive was generated by hypermail 2b29 : Tue Jul 31 2001 - 21:00:21 EST