Skip to contentSkip to conversation

drivers/block/floppy.c: Add function is_ready_state

PATCH James Kosin 2 participants 4 messages Jan 23, 2010 – Jan 26, 2010 3 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 12 lines · Joe Perches

Used a couple of times, might simplify the code a bit.

---
  drivers/block/floppy.c |   19 +++++++++++++++----
  1 files changed, 15 insertions(+), 4 deletions(-)
drivers/block/floppy.c +0 -0
index 2f6ed78..fd56b26 100644

drivers/block/floppy.c static inline int is_selected(int dor, int unit) · line 790

Quoted 9 lines
drivers/block/floppy.c +6 -0
@@ -782,6 +782,12 @@ static inline int is_selected(int dor, int unit)
  	return ((dor&  (0x10<<  unit))&&  (dor&  3) == unit);
  }
 
+static bool is_ready_state(int status)
+{
+	int state = status&  (STATUS_READY | STATUS_DIR | STATUS_DMA);
+	return state == STATUS_READY;
+}
+

This should probably be simplified to:

static bool is_ready_state(int status)

{
	return ((state & STATUS_READY) == STATUS_READY);
}

James

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 33 lines · Joe Perches
Quoted 26 lines · James Kosin
Quoted 12 lines · Joe Perches

Used a couple of times, might simplify the code a bit.

---
   drivers/block/floppy.c |   19 +++++++++++++++----
   1 files changed, 15 insertions(+), 4 deletions(-)
drivers/block/floppy.c +0 -0
index 2f6ed78..fd56b26 100644

drivers/block/floppy.c static inline int is_selected(int dor, int unit) · line 791

Quoted 10 lines
drivers/block/floppy.c +6 -0
@@ -782,6 +782,12 @@ static inline int is_selected(int dor, int unit)
   	return ((dor&   (0x10<<   unit))&&   (dor&   3) == unit);
   }
 
+static bool is_ready_state(int status)
+{
+	int state = status&   (STATUS_READY | STATUS_DIR | STATUS_DMA);
+	return state == STATUS_READY;
+}
+
 

This should probably be simplified to:

Quoted 5 lines

static bool is_ready_state(int status)

{
	return ((state&  STATUS_READY) == STATUS_READY);
}
Quoted 9 lines

Certainly not.
That wouldn't be the same code.

include/linux/fdreg.h:#define STATUS_DMA 0x20 /* 0- DMA mode */
include/linux/fdreg.h:#define STATUS_DIR 0x40 /* 0- cpu->fdc */
include/linux/fdreg.h:#define STATUS_READY 0x80 /* Data reg ready */

Read the code....

It simplifies what is already there. The two other status flags make no difference in the test for equality with STATUS_READY.

James

#5 lore raw
Quoted 22 lines · James Kosin
Quoted 21 lines · Joe Perches
Quoted 11 lines · James Kosin

Review

Quoted 7 lines · Joe Perches
(quoted diff) +6 -0
+static bool is_ready_state(int status)
+{
+	int state = status&   (STATUS_READY | STATUS_DIR | STATUS_DMA);
+	return state == STATUS_READY;
+}
+

This should probably be simplified to:

Quoted 5 lines

static bool is_ready_state(int status)

{
	return ((state&  STATUS_READY) == STATUS_READY);
}

Certainly not.
That wouldn't be the same code.

Quoted 8 lines
Quoted 4 lines

include/linux/fdreg.h:#define STATUS_DMA 0x20 /* 0- DMA mode */
include/linux/fdreg.h:#define STATUS_DIR 0x40 /* 0- cpu->fdc */
include/linux/fdreg.h:#define STATUS_READY 0x80 /* Data reg ready */

Read the code....

It simplifies what is already there. The two other status flags make no difference in the test for equality with STATUS_READY.

Sure they do: the old code tests that the STATUS_READY is set and both STATUS_DMA and STATUS_DIR bits are clear. So, for example, if STATUS_READY and STATUS_DMA are both set, then the old test will return false.

Your "simplification" has removed the check for those clear bits, and will return true even if all three bits are set.

Signature · 1 line
Nick Bowler, Elliptic Technologies (http://www.elliptictech.com/)
#6 lore raw
In reply to a message not in the archive
Quoted 33 lines · Joe Perches
Quoted 26 lines · James Kosin
Quoted 12 lines · Joe Perches

Used a couple of times, might simplify the code a bit.

---
   drivers/block/floppy.c |   19 +++++++++++++++----
   1 files changed, 15 insertions(+), 4 deletions(-)
drivers/block/floppy.c +0 -0
index 2f6ed78..fd56b26 100644

drivers/block/floppy.c static inline int is_selected(int dor, int unit) · line 791

Quoted 10 lines
drivers/block/floppy.c +6 -0
@@ -782,6 +782,12 @@ static inline int is_selected(int dor, int unit)
   	return ((dor&   (0x10<<   unit))&&   (dor&   3) == unit);
   }
 
+static bool is_ready_state(int status)
+{
+	int state = status&   (STATUS_READY | STATUS_DIR | STATUS_DMA);
+	return state == STATUS_READY;
+}
+
 

This should probably be simplified to:

Quoted 5 lines

static bool is_ready_state(int status)

{
	return ((state&  STATUS_READY) == STATUS_READY);
}
Quoted 9 lines

Certainly not.
That wouldn't be the same code.

include/linux/fdreg.h:#define STATUS_DMA 0x20 /* 0- DMA mode */
include/linux/fdreg.h:#define STATUS_DIR 0x40 /* 0- cpu->fdc */
include/linux/fdreg.h:#define STATUS_READY 0x80 /* Data reg ready */

Sorry,

That probably should have been:

        return ((status & STATUS_READY) == STATUS_READY);

James