Skip to contentSkip to conversation

2.4.10-ac11 parport_pc.c bugfix

PATCH In review Thomas Hood 4 participants 6 messages Oct 11, 2001 – Oct 12, 2001 Parallel port

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 2.4.10-ac11 parport_pc.c bugfix

This fix makes the parport driver print the correct dma number and makes explicit a couple of type casts. Applies cleanly against
-ac11 // Thomas Hood

The patch:

drivers/parport/parport_pc.c +3 -3
@@ -2826,7 +2826,7 @@
 	if ( UNSET(dev->irq_resource[0]) ) {
 		irq = PARPORT_IRQ_NONE;
 	} else {
-		if ( dev->irq_resource[0].start == -1 ) {
+		if ( dev->irq_resource[0].start == (unsigned long)-1 ) {
 			irq = PARPORT_IRQ_NONE;
 			printk(", irq disabled");
 		} else {
@@ -2838,12 +2838,12 @@
 	if ( UNSET(dev->dma_resource[0]) ) {
 		dma = PARPORT_DMA_NONE;
 	} else {
-		if ( dev->dma_resource[0].start == -1 ) {
+		if ( dev->dma_resource[0].start == (unsigned long)-1 ) {
 			dma = PARPORT_DMA_NONE;
 			printk(", dma disabled");
 		} else {
 			dma = dev->dma_resource[0].start;
-			printk(", dma %d",irq);
+			printk(", dma %d",dma);
 		}
 	}
 
#1 lore raw

drivers/parport/parport_pc.c line 2829

Quoted 3 lines · On 20011011 Thomas Hood wrote:
	} else {
drivers/parport/parport_pc.c +1 -1
-		if ( dev->irq_resource[0].start == -1 ) {
+		if ( dev->irq_resource[0].start == (unsigned long)-1 ) {
                                                   ^^^^^^^^^      ^

Uh ?

Perhaps I miss some black magic in kernel programming, but could not this be written much cleaner like

Quoted 1 line
(quoted diff) +1 -0
+		if ( dev->irq_resource[0].start == ~0U ) {
Signature · 4 lines
J.A. Magallon                           #  Let the source be with you...        
mailto:[email protected]
Mandrake Linux release 8.2 (Cooker) for i586
Linux werewolf 2.4.10-ac11-beo #2 SMP Thu Oct 11 02:41:04 CEST 2001 i686
#2 lore raw

I guess the question is: Which way is more portable? Is "(unsigned long)-1" liable to turn out as something other than ~0U?

If your way of expressing it is more portable then we should make the change ... BOTH in pnp_bios.c and in parport_pc.c .

Opinions?

--
Thomas

Quoted 19 lines · J . A . Magallon

drivers/parport/parport_pc.c line 2829

Quoted 3 lines · On 20011011 Thomas Hood wrote:
	} else {
drivers/parport/parport_pc.c +1 -1
-		if ( dev->irq_resource[0].start == -1 ) {
+		if ( dev->irq_resource[0].start == (unsigned long)-1 ) {
                                                   ^^^^^^^^^      ^

Uh ?

Perhaps I miss some black magic in kernel programming, but could not this be written much cleaner like

Quoted 1 line
(quoted diff) +1 -0
+		if ( dev->irq_resource[0].start == ~0U ) {
Signature · 4 lines
J.A. Magallon                           #  Let the source be with you...        
mailto:[email protected]
Mandrake Linux release 8.2 (Cooker) for i586
Linux werewolf 2.4.10-ac11-beo #2 SMP Thu Oct 11 02:41:04 CEST 2001 i686
#3 lore raw

In article <1002808349.10317.7.camel@thanatos> you write:

| I guess the question is: Which way is more portable?  Is
| "(unsigned long)-1" liable to turn out as something other than
| ~0U?
| 
| If your way of expressing it is more portable then we should
| make the change ... BOTH in pnp_bios.c and in parport_pc.c .
| 
| Opinions?

Does this address any bug present without the cast? If the expression left of == is unsigned long, ~0U will work, as will (unsigned)~0. But more to the point, do you mean "minus one" or "all ones" here? While Linux does not currently run on any machine which is not 2's complement, I think if you want all ones you should use (unsigned long)~0 as most portable.

Yes, I have programmed 1's complement machines :-(

Signature · 4 lines
bill davidsen <[email protected]>
 "If I were a diplomat, in the best case I'd go hungry.  In the worst
  case, people would die."
		-- Robert Lipe
#4 lore raw
Quoted 1 line · bill davidsen

Does this address any bug present without the cast?

No. There's no bug. The debate is over whether or not it's naughty to cast -1 to unsigned long.

--
Thomas

#5 lore raw
In reply to Thomas Hood
Quoted 8 lines · Thomas Hood [[email protected]] wrote:

I guess the question is: Which way is more portable? Is "(unsigned long)-1" liable to turn out as something other than ~0U?

If your way of expressing it is more portable then we should make the change ... BOTH in pnp_bios.c and in parport_pc.c .

Opinions?

unsigned long is 64-bits on 64-bit archs, and so (unsigned long)-1 will be different than on intel...

I think that's ~0UL?

Maybe this is why I can't get pnp stuff to work on my alpha?

Cheers,
-- Bob

Bob McElrath ([email protected]) Univ. of Wisconsin at Madison, Department of Physics