Skip to contentSkip to conversation

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

PATCH Chen Gang 1 participant 1 message Jun 22, 2013 Generic include/asm header files

lore
Share & tools
lore

Chen Gang

author
#0 lore raw

Hello Maintainers:

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

Thanks.

Quoted 51 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 +11 -4
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);
 

arch/powerpc/kernel/nvram_64.c static ssize_t dev_nvram_read(struct file *file, char __user *buf, · line 113

Quoted 10 lines
arch/powerpc/kernel/nvram_64.c +3 -2
-	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)

Thanks

Signature · 3 lines
Chen Gang

Asianux Corporation