Skip to contentSkip to conversation

sparc: prom: Sanitize return value from prom_nbputchar()

RFC Applied Julian Calaby 4 participants 7 messages Dec 4, 2010 – Jan 5, 2011 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

RFC 1/8 sparc: prom: Sanitize return value from prom_nbputchar()

---
 arch/sparc/prom/console_32.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
arch/sparc/prom/console_32.c +4 -3
index 4886310..b05e3db 100644
@@ -27,13 +27,14 @@ static int prom_nbputchar(const char *buf)
 	spin_lock_irqsave(&prom_lock, flags);
 	switch(prom_vers) {
 	case PROM_V0:
-		i = (*(romvec->pv_nbputchar))(*buf);
+		if ((*(romvec->pv_nbputchar))(*buf))
+			i = 1;
 		break;
 	case PROM_V2:
 	case PROM_V3:
 		if ((*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout,
 							  buf, 0x1) = 1)
-			i = 0;
+			i = 1;
 		break;
 	default:
 		break;
@@ -47,7 +48,7 @@ void prom_console_write_buf(const char *buf, int len)
 {
 	while (len) {
 		int n = prom_nbputchar(buf);
-		if (n)
+		if (n < 0)
 			continue;
 		len--;
 		buf++;
Signature · 1 line
1.7.2.3
#1 lore raw

RFC 1/8 sparc: prom: Sanitize return value from prom_nbputchar()

---

Sorry about the dupe, wrong from address.

 arch/sparc/prom/console_32.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
arch/sparc/prom/console_32.c +4 -3
index 4886310..b05e3db 100644
@@ -27,13 +27,14 @@ static int prom_nbputchar(const char *buf)
 	spin_lock_irqsave(&prom_lock, flags);
 	switch(prom_vers) {
 	case PROM_V0:
-		i = (*(romvec->pv_nbputchar))(*buf);
+		if ((*(romvec->pv_nbputchar))(*buf))
+			i = 1;
 		break;
 	case PROM_V2:
 	case PROM_V3:
 		if ((*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout,
 							  buf, 0x1) = 1)
-			i = 0;
+			i = 1;
 		break;
 	default:
 		break;
@@ -47,7 +48,7 @@ void prom_console_write_buf(const char *buf, int len)
 {
 	while (len) {
 		int n = prom_nbputchar(buf);
-		if (n)
+		if (n < 0)
 			continue;
 		len--;
 		buf++;
#3 lore raw
In reply to Julian Calaby
Quoted 5 lines · David Miller

From: Julian Calaby <[email protected]>
Date: Sat, 04 Dec 2010 14:55:50 +1100

Quoted 7 lines
Quoted 3 lines

Applied.

I think this patch breaks the backwards compatability... Before this patch one had to return -1 from prom-code in order to implement a non-locking nbputchar() in PROM code (see old code below). With the new patch however one has to return a 0 and -1 is now interpreted as send successful.

Should we not check for values bigger than 0 so that -1 can be return by old PROMs? I suggest:

- i = (*(romvec->pv_nbputchar))(*buf);
+ if ((*(romvec->pv_nbputchar))(*buf) > 0)
+ i = 1;

Regards,
Daniel

The applied patch:

- i = (*(romvec->pv_nbputchar))(*buf);
+ if ((*(romvec->pv_nbputchar))(*buf))
+ i = 1;

Old version of nbputchar():

/* Non blocking put character to console device, returns -1 if
* unsuccessful.
*/
int
prom_nbputchar(char c)

{
	static char outc;
	unsigned long flags;
	int i = -1;

	spin_lock_irqsave(&prom_lock, flags);
	switch(prom_vers) {
	case PROM_V0:
		i = (*(romvec->pv_nbputchar))(c);
		break;
	case PROM_V2:
	case PROM_V3:
		outc = c;
		if( (*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout, &outc, 0x1) = 1)
			i = 0;
		else
			i = -1;
		break;
	default:
		i = -1;
		break;
	};
	restore_current();
	spin_unlock_irqrestore(&prom_lock, flags);
	return i; /* Ugh, we could spin forever on unsupported proms ;( */
}

/* Blocking version of put character routine above. */ void
prom_putchar(char c)

{
	while(prom_nbputchar(c) = -1) ;
}
maintainer
#4 lore raw

Re: [RFC 1/8] sparc: prom: Sanitize return value from

In reply to Julian Calaby

From: Daniel Hellstrom <[email protected]>
Date: Tue, 04 Jan 2011 15:42:45 +0100

Quoted 6 lines
Quoted 4 lines · David Miller

From: Julian Calaby <[email protected]>
Date: Sat, 04 Dec 2010 14:55:50 +1100

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Applied.

I think this patch breaks the backwards compatability...

Backwards compatability for who? There is one and only one caller of this function, and it is marked static and not exported to any other piece of code in the tree.

#5 lore raw
In reply to Julian Calaby
Quoted 12 lines · David Miller

From: Daniel Hellstrom <[email protected]>
Date: Tue, 04 Jan 2011 15:42:45 +0100

Quoted 9 lines
Quoted 7 lines · David Miller

From: Julian Calaby <[email protected]>
Date: Sat, 04 Dec 2010 14:55:50 +1100

Quoted 2 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Applied.

I think this patch breaks the backwards compatability...

Backwards compatability for who?  There is one and only one caller of this function, and it is marked static and not exported to any other piece of code in the tree.

The other point is that sparc64's version works like this, so why should sparc32's version be different?

Signature · 5 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
.Plan: http://sites.google.com/site/juliancalaby/
#6 lore raw
In reply to Julian Calaby
Quoted 26 lines · Julian Calaby
Quoted 23 lines · David Miller

From: Daniel Hellstrom <[email protected]>
Date: Tue, 04 Jan 2011 15:42:45 +0100

Quoted 18 lines
Quoted 14 lines · David Miller

From: Julian Calaby <[email protected]>
Date: Sat, 04 Dec 2010 14:55:50 +1100

Quoted 4 lines

Applied.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

I think this patch breaks the backwards compatability...

Backwards compatability for who? There is one and only one caller of this function, and it is marked static and not exported to any other piece of code in the tree.

With this patch we need to have two different versions of the PROM emulation implementation, it is a bit sad that it will not work for both versions of the linux kernel 2.6.36 and 2.6.37, that's all.

I'm probably out of line here, I havn't read the PROMv0 specification, the old linux implementation was perhaps faulty all along and we made our PROM code looking at it rather than the PROMv0 spec.

My impression was that pv_nbputchar() in PROM has to be implemented as non-blocking in order to avoid taking the prom_lock too long, in order to do that in a linux 2.6.36 kernel the PROM has to return -1 from pv_nbputchar() when the UART is busy and a 1 when pv_nbputchar() actually sends a character. However with this patch the pv_nbputchar() must return a 0 when UART is busy, this means that backwards compability to the PROM emultation software is lost.

Quoted 5 lines

The other point is that sparc64's version works like this, so why should sparc32's version be different?

Good point. Havn't looked at the SPARC64 code. Probably we should have submitted a patch for the old bad behaviour before.

We can live with two different versions of the PROM... there are more important things in life :)

Thank you,
Daniel