linux-8086.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Juan Perez-Sanchez <lithoxs@gmail.com>
To: linux-8086 <linux-8086@vger.kernel.org>
Cc: Jody Bruchon <jody@jodybruchon.com>
Subject: [PATCH 6 of 6]
Date: Sun, 17 Mar 2013 13:22:44 -0600	[thread overview]
Message-ID: <CAD6VGub-BLG2A2DY+zyWg8nn8=QBFB4hHvi1aEUc7NsX7yJqkQ@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 794 bytes --]

Hi,

 Fixed a problem which produced a kernel message error when running
the command "fsck". Now that the implementation of read and write file
is cleaner, it was very easy to find and fix the problem in file
fs/block_dev.c.

 General optimization in files arch/i86/drivers/block/doshd.c,
arch/i86/mm/init.c, arch/i86/mm/malloc.c, arch/i86/mm/user.c,
fs/buffer.c  fs/minix/file.c, kernel/printk.c and kernel/sched.c,
removing unused variables and redundant statements, using pointers
instead of array  indexing, using do{}while() whenever possible and
simplifying code.

3. As result of the modifications the code size was reduced in 112 bytes.

 The Image builded without errors. The kernel was tested with QEMU and
dioscuri emulators. Also in a PPro pc booting from floppy.

Greetings,

Juan

[-- Attachment #2: elksZ.patch --]
[-- Type: application/octet-stream, Size: 7167 bytes --]

diff -Nurb elks.orig/arch/i86/drivers/block/doshd.c elks/arch/i86/drivers/block/doshd.c
--- elks.orig/arch/i86/drivers/block/doshd.c	2013-03-04 13:20:07.000000000 -0600
+++ elks/arch/i86/drivers/block/doshd.c	2013-03-06 17:37:50.000000000 -0600
@@ -532,8 +532,8 @@
 	return 0;
 
 #ifdef TEMP_PRINT_DRIVES_MAX
-    for (i = 0; i < TEMP_PRINT_DRIVES_MAX; i++) {
-	drivep = drive_info + i;
+    drivep = drive_info;
+    for (i = 0; i < TEMP_PRINT_DRIVES_MAX; i++, drivep++) {
 	if (drivep->heads != 0) {
 	    char *unit = "kMGT";
 	    __u32 size = ((__u32) drivep->sectors) * 5 /* 0.1 kB units */;
diff -Nurb elks.orig/arch/i86/mm/init.c elks/arch/i86/mm/init.c
--- elks.orig/arch/i86/mm/init.c	2013-03-04 13:20:07.000000000 -0600
+++ elks/arch/i86/mm/init.c	2013-03-06 14:32:03.000000000 -0600
@@ -34,10 +34,11 @@
     __u16 basemem = setupw(0x2a);
     __u16 xms = setupw(2);		/* Fetched by boot code */
 
-    for (pi = 0; ((int)pi) < 16; pi++) {
+    pi = 0;
+    do {
 	proc_name[(int)pi] = setupb(0x30 + (int)pi);
 	cpuid[(int)pi] = setupb(0x50 + (int)pi);
-    }
+    } while((int)(++pi) < 16);
     proc_name[16] = cpuid[16] = '\0';
 
 #ifdef CONFIG_ARCH_SIBO
@@ -52,7 +53,7 @@
 	   arch_cpu > 5 ? 'A' : 'X', proc_name, basemem);
     if (arch_cpu < 6)
 	xms = 0;		/* XT bios hasn't got xms interrupt */
-    if (xms)
+    else
 	printk(", %dK extended memory (XMS)", xms);
     if (*cpuid)
 	printk(", CPUID `%s'", cpuid);
diff -Nurb elks.orig/arch/i86/mm/malloc.c elks/arch/i86/mm/malloc.c
--- elks.orig/arch/i86/mm/malloc.c	2013-03-04 13:20:07.000000000 -0600
+++ elks/arch/i86/mm/malloc.c	2013-03-06 15:09:26.000000000 -0600
@@ -161,7 +161,7 @@
     register struct malloc_hole *best = NULL;
 
     while (m) {
-	if (m->extent >= size && m->flags == HOLE_FREE)
+	if (m->flags == HOLE_FREE && m->extent >= size)
 	    if (!best || best->extent > m->extent)
 		best = m;
 	m = m->next;
@@ -483,14 +483,14 @@
 
 void mm_init(seg_t start, seg_t end)
 {
-    register struct malloc_hole *holep = &holes[0];
-    register char *pct;
+    register struct malloc_hole *holep = &holes[MAX_SEGMENTS - 1];
 
     /*
      *      Mark pages free.
      */
-    for (pct = (char *) 1 ; ((int) pct) < MAX_SEGMENTS ; pct++)
-	holes[(int)pct].flags = HOLE_SPARE;
+    do {
+	holep->flags = HOLE_SPARE;
+    } while(--holep > holes);
 
     /*
      *      Single hole containing all user memory.
diff -Nurb elks.orig/arch/i86/mm/user.c elks/arch/i86/mm/user.c
--- elks.orig/arch/i86/mm/user.c	2013-03-04 13:20:07.000000000 -0600
+++ elks/arch/i86/mm/user.c	2013-03-04 13:20:18.000000000 -0600
@@ -228,7 +228,8 @@
 
 int fs_memcmp(void *s, void *d, size_t len)
 {
-    unsigned char *p1 = s, *p2 = d;
+    register unsigned char *p1 = s;
+    register unsigned char *p2 = d;
     int c = 0;
 
     while (len-- && !c)
diff -Nurb elks.orig/fs/block_dev.c elks/fs/block_dev.c
--- elks.orig/fs/block_dev.c	2013-03-04 13:20:07.000000000 -0600
+++ elks/fs/block_dev.c	2013-03-04 19:11:19.000000000 -0600
@@ -23,13 +23,11 @@
 		  char *buf, size_t count, int wr)
 {
     register struct buffer_head *bh;
-    block_t block;
     kdev_t dev;
     unsigned int offset;
     size_t chars;
-    int written;
+    int written = 0;
 
-    written = 0;
     dev = inode->i_rdev;
 
     while (count > 0) {
@@ -37,7 +35,6 @@
 	/*
 	*      Offset to block/offset
 	*/
-        block = (block_t) (filp->f_pos >> BLOCK_SIZE_BITS);
 	offset = ((unsigned int)filp->f_pos) & (BLOCK_SIZE - 1);
 
 	/*
@@ -50,15 +47,13 @@
 	 *      Read the block in - use getblk on a write
 	 *      of a whole block to avoid a read of the data.
 	 */
-	if(wr == BLOCK_WRITE && chars == BLOCK_SIZE) {
-	    bh = getblk(dev, block);
-	    map_buffer(bh);
-	} else {
-	    bh = bread(dev, block);
-	    if (!bh)
+	bh = getblk(dev, (block_t)(filp->f_pos >> BLOCK_SIZE_BITS));
+	if((wr == BLOCK_READ) || (chars != BLOCK_SIZE)) {
+	    if (!readbuf(bh))
 		return written ? written : -EIO;
 	}
 
+	map_buffer(bh);
 	if (wr == BLOCK_WRITE) {
 	    /*
 	     *      Alter buffer, mark dirty
diff -Nurb elks.orig/fs/buffer.c elks/fs/buffer.c
--- elks.orig/fs/buffer.c	2013-03-04 13:20:07.000000000 -0600
+++ elks/fs/buffer.c	2013-03-04 13:20:18.000000000 -0600
@@ -204,15 +204,14 @@
 {
     register struct buffer_head *bh;
 
-    for (;;) {
-	if (!(bh = find_buffer(dev, block)))
-	    return NULL;
+    while((bh = find_buffer(dev, block))) {
 	bh->b_count++;
 	wait_on_buffer(bh);
 	if (bh->b_dev == dev && bh->b_blocknr == block)
-	    return bh;
+	    break;
 	bh->b_count--;
     }
+    return bh;
 }
 
 /*
@@ -235,11 +234,10 @@
      * now so as to ensure that there are still clean buffers available
      * for user processes to use (and dirty) */
 
-    for (;;) {
+    do {
 	bh = get_hash_table(dev, block);
 	if (bh != NULL) {
-	    if (buffer_clean(bh))
-		if (buffer_uptodate(bh))
+	    if (buffer_clean(bh) && buffer_uptodate(bh))
 		    put_last_lru(bh);
 	    return bh;
 	}
@@ -248,9 +246,7 @@
 	 * So I will remove it for now
 	 */
 
-	if (!find_buffer(dev, block))
-	    break;
-    }
+    } while(find_buffer(dev, block));
 
     /*
      *      Create a buffer for this job.
diff -Nurb elks.orig/fs/minix/file.c elks/fs/minix/file.c
--- elks.orig/fs/minix/file.c	2013-03-04 13:20:07.000000000 -0600
+++ elks/fs/minix/file.c	2013-03-04 19:02:17.000000000 -0600
@@ -195,7 +195,7 @@
 		written = -ENOSPC;
 	    break;
 	}
-	if (chars != BLOCK_SIZE && !buffer_uptodate(bh)) {
+	if (chars != BLOCK_SIZE) {
 	    if (!readbuf(bh)) {
 		if (!written)
 		    written = -EIO;
diff -Nurb elks.orig/kernel/printk.c elks/kernel/printk.c
--- elks.orig/kernel/printk.c	2013-03-04 13:20:07.000000000 -0600
+++ elks/kernel/printk.c	2013-03-05 15:59:41.000000000 -0600
@@ -74,7 +74,8 @@
 static void numout(unsigned long v, int width, int base, int useSign,
 		   int Upper, int Zero)
 {
-    char *bp, *bp2;
+    register char *bp;
+    char *bp2;
     char buf[12];
 
     if (width > sizeof(buf))		/* Error-check width specified */
@@ -206,7 +207,8 @@
 void panic(char *error, ...)
 {
     va_list p;
-    int *bp = (int *) &error - 2, i = 0, j;
+    register int *bp = (int *) &error - 2;
+    int i = 0, j;
 
     kputs("\npanic: ");
     va_start(p, error);
diff -Nurb elks.orig/kernel/sched.c elks/kernel/sched.c
--- elks.orig/kernel/sched.c	2013-03-04 13:20:07.000000000 -0600
+++ elks/kernel/sched.c	2013-03-04 13:20:18.000000000 -0600
@@ -48,8 +48,7 @@
         return;
     }
     nr_running--;
-    p->next_run->prev_run = p->prev_run;
-    p->prev_run->next_run = p->next_run;
+    (p->next_run->prev_run = p->prev_run)->next_run = p->next_run;
     p->next_run = p->prev_run = NULL;
 #ifdef CONFIG_SWAP
     p->last_running = jiffies;
@@ -207,14 +206,12 @@
 
     do {
         prev = next;
-        if (!(next = next->tl_next))
-            goto link_tmr;
-    } while(next->tl_expires < timer->tl_expires);
+    } while((next = next->tl_next) && (next->tl_expires < timer->tl_expires));
 
-    (timer->tl_next = next)->tl_prev = timer;
-
- link_tmr:
     (timer->tl_prev = prev)->tl_next = timer;
+    if((timer->tl_next = next))
+        next->tl_prev = timer;
+
     restore_flags(flags);
 }
 

                 reply	other threads:[~2013-03-17 19:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAD6VGub-BLG2A2DY+zyWg8nn8=QBFB4hHvi1aEUc7NsX7yJqkQ@mail.gmail.com' \
    --to=lithoxs@gmail.com \
    --cc=jody@jodybruchon.com \
    --cc=linux-8086@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).