Skip to contentSkip to conversation

PowerPC: kernel: need return the related error code when failure occurs.

PATCH Superseded Chen Gang 2 participants 5 messages May 21, 2013 – May 27, 2013

Subsystems (2)
lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH 1/1 PowerPC: kernel: need return the related error code when failure occurs.

When error occurs, need return the related error code to let upper caller know about it.

ppc_md.nvram_size() can return the error code (e.g. core99_nvram_size() in 'arch/powerpc/platforms/powermac/nvram.c').

And when '*ppos >= size', need return -ESPIPE (Illegal seek)

The original related patch: "f9ce299 [PATCH] powerpc: fix large nvram access"

---
 arch/powerpc/kernel/nvram_64.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
arch/powerpc/kernel/nvram_64.c +7 -2
index 48fbc2b..db2a636 100644
@@ -88,10 +88,15 @@ static ssize_t dev_nvram_read(struct file *file, char __user *buf,
 	if (!ppc_md.nvram_size)
 		goto out;
 
-	ret = 0;
 	size = ppc_md.nvram_size();
-	if (*ppos >= size || size < 0)
+	if (size < 0) {
+		ret = size;
 		goto out;
+	}
+	if (*ppos >= size) {
+		ret = -ESPIPE;
+		goto out;
+	}
 
 	count = min_t(size_t, count, size - *ppos);
 	count = min(count, PAGE_SIZE);
Signature · 1 line
1.7.7.6
#1 lore raw
Quoted 8 lines · Chen Gang

When error occurs, need return the related error code to let upper caller know about it.

ppc_md.nvram_size() can return the error code (e.g. core99_nvram_size() in 'arch/powerpc/platforms/powermac/nvram.c').

And when '*ppos >= size', need return -ESPIPE (Illegal seek)

Why? When *ppos >= size, it should return 0 (end of file) in my opinion. ESPIPE means that any seek would be ineffective, not that a particular seek went out of bounds.

Paul.

author
#2 lore raw
Quoted 5 lines · Paul Mackerras
Quoted 4 lines · Chen Gang
Quoted 4 lines

When error occurs, need return the related error code to let upper caller know about it.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

ppc_md.nvram_size() can return the error code (e.g. core99_nvram_size() in 'arch/powerpc/platforms/powermac/nvram.c').

And when '*ppos >= size', need return -ESPIPE (Illegal seek)

Why? When *ppos >= size, it should return 0 (end of file) in my opinion. ESPIPE means that any seek would be ineffective, not that a particular seek went out of bounds.

OK, thanks, I will send patch v2. :-)

Thanks.

Signature · 3 lines
Chen Gang

Asianux Corporation
author
#3 lore raw

PATCH v2 1/1 PowerPC: kernel: need return the related error code when failure occurs

When error occurs, need return the related error code to let upper caller know about it.

ppc_md.nvram_size() can return the error code (e.g. core99_nvram_size() in 'arch/powerpc/platforms/powermac/nvram.c').

Also set ret value when only need it, so can save structions for normal cases.

The original related patch: "f9ce299 [PATCH] powerpc: fix large nvram access".

---
 arch/powerpc/kernel/nvram_64.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)
arch/powerpc/kernel/nvram_64.c +14 -6
index 48fbc2b..8213ee1 100644
@@ -84,22 +84,30 @@ static ssize_t dev_nvram_read(struct file *file, char __user *buf,
 	char *tmp = NULL;
 	ssize_t size;
 
-	ret = -ENODEV;
-	if (!ppc_md.nvram_size)
+	if (!ppc_md.nvram_size) {
+		ret = -ENODEV;
 		goto out;
+	}
 
-	ret = 0;
 	size = ppc_md.nvram_size();
-	if (*ppos >= size || size < 0)
+	if (size < 0) {
+		ret = size;
+		goto out;
+	}
+
+	if (*ppos >= size) {
+		ret = 0;
 		goto out;
+	}
 
 	count = min_t(size_t, count, size - *ppos);
 	count = min(count, PAGE_SIZE);
 
-	ret = -ENOMEM;
 	tmp = kmalloc(count, GFP_KERNEL);
-	if (!tmp)
+	if (!tmp) {
+		ret = -ENOMEM;
 		goto out;
+	}
 
 	ret = ppc_md.nvram_read(tmp, count, ppos);
 	if (ret <= 0)
Signature · 1 line
1.7.7.6
author
#4 lore raw

Re: [PATCH v2] PowerPC: kernel: need return the related error code when failure occurs

Hello Maintainers:

Please help check this patch whether is OK, when you have time.

Thanks.

Quoted 61 lines · Chen Gang

When error occurs, need return the related error code to let upper caller know about it.

ppc_md.nvram_size() can return the error code (e.g. core99_nvram_size() in 'arch/powerpc/platforms/powermac/nvram.c').

Also set ret value when only need it, so can save structions for normal cases.

The original related patch: "f9ce299 [PATCH] powerpc: fix large nvram access".

---
 arch/powerpc/kernel/nvram_64.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)
arch/powerpc/kernel/nvram_64.c +14 -6
index 48fbc2b..8213ee1 100644
@@ -84,22 +84,30 @@ static ssize_t dev_nvram_read(struct file *file, char __user *buf,
 	char *tmp = NULL;
 	ssize_t size;
 
-	ret = -ENODEV;
-	if (!ppc_md.nvram_size)
+	if (!ppc_md.nvram_size) {
+		ret = -ENODEV;
 		goto out;
+	}
 
-	ret = 0;
 	size = ppc_md.nvram_size();
-	if (*ppos >= size || size < 0)
+	if (size < 0) {
+		ret = size;
+		goto out;
+	}
+
+	if (*ppos >= size) {
+		ret = 0;
 		goto out;
+	}
 
 	count = min_t(size_t, count, size - *ppos);
 	count = min(count, PAGE_SIZE);
 
-	ret = -ENOMEM;
 	tmp = kmalloc(count, GFP_KERNEL);
-	if (!tmp)
+	if (!tmp) {
+		ret = -ENOMEM;
 		goto out;
+	}
 
 	ret = ppc_md.nvram_read(tmp, count, ppos);
 	if (ret <= 0)
Signature · 3 lines
Chen Gang

Asianux Corporation