All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [MTD] phram: cleanup error handling and associated messages
@ 2009-06-17 10:50 Mike Frysinger
  2009-06-17 11:24 ` Jörn Engel
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Frysinger @ 2009-06-17 10:50 UTC (permalink / raw)
  To: joern; +Cc: linux-mtd

The error handling in the phram driver is pretty bad -- in many places,
errors are silently ignored or logged, but then still ignored in the
return value.  So convert all of the code to pass back the correct return
value and log error messages properly (and using the new pr_fmt() helper).

If everything does go smoothly, rather than exit silently, dump a helpful
info message like pretty much every other MTD driver does.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 drivers/mtd/devices/phram.c |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index 088fbb7..1696bbe 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -14,6 +14,9 @@
  * Example:
  *	phram=swap,64Mi,128Mi phram=test,900Mi,1Mi
  */
+
+#define pr_fmt(fmt) "phram: " fmt
+
 #include <asm/io.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
@@ -23,8 +26,6 @@
 #include <linux/slab.h>
 #include <linux/mtd/mtd.h>
 
-#define ERROR(fmt, args...) printk(KERN_ERR "phram: " fmt , ## args)
-
 struct phram_mtd_list {
 	struct mtd_info mtd;
 	struct list_head list;
@@ -132,7 +133,7 @@ static int register_device(char *name, unsigned long start, unsigned long len)
 	ret = -EIO;
 	new->mtd.priv = ioremap(start, len);
 	if (!new->mtd.priv) {
-		ERROR("ioremap failed\n");
+		pr_err("ioremap failed\n");
 		goto out1;
 	}
 
@@ -152,7 +153,7 @@ static int register_device(char *name, unsigned long start, unsigned long len)
 
 	ret = -EAGAIN;
 	if (add_mtd_device(&new->mtd)) {
-		ERROR("Failed to register new device\n");
+		pr_err("Failed to register new device\n");
 		goto out2;
 	}
 
@@ -227,8 +228,8 @@ static inline void kill_final_newline(char *str)
 
 
 #define parse_err(fmt, args...) do {	\
-	ERROR(fmt , ## args);	\
-	return 0;		\
+	pr_err(fmt , ## args);	\
+	return 1;		\
 } while (0)
 
 static int phram_setup(const char *val, struct kernel_param *kp)
@@ -256,12 +257,8 @@ static int phram_setup(const char *val, struct kernel_param *kp)
 		parse_err("not enough arguments\n");
 
 	ret = parse_name(&name, token[0]);
-	if (ret == -ENOMEM)
-		parse_err("out of memory\n");
-	if (ret == -ENOSPC)
-		parse_err("name too long\n");
 	if (ret)
-		return 0;
+		return ret;
 
 	ret = parse_num32(&start, token[1]);
 	if (ret) {
@@ -275,9 +272,11 @@ static int phram_setup(const char *val, struct kernel_param *kp)
 		parse_err("illegal device length\n");
 	}
 
-	register_device(name, start, len);
+	ret = register_device(name, start, len);
+	if (!ret)
+		pr_info("%s device: %#x at %#x\n", name, len, start);
 
-	return 0;
+	return ret;
 }
 
 module_param_call(phram, phram_setup, NULL, NULL, 000);
-- 
1.6.3.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] [MTD] phram: cleanup error handling and associated messages
  2009-06-17 10:50 [PATCH] [MTD] phram: cleanup error handling and associated messages Mike Frysinger
@ 2009-06-17 11:24 ` Jörn Engel
  2009-06-17 11:49   ` Mike Frysinger
  0 siblings, 1 reply; 4+ messages in thread
From: Jörn Engel @ 2009-06-17 11:24 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: linux-mtd, joern

On Wed, 17 June 2009 06:50:18 -0400, Mike Frysinger wrote:
> 
> The error handling in the phram driver is pretty bad -- in many places,
> errors are silently ignored or logged, but then still ignored in the
> return value.  So convert all of the code to pass back the correct return
> value and log error messages properly (and using the new pr_fmt() helper).

I don't remember why I always returned 0 in phram_setup.  Could well
have been an oversight.

> If everything does go smoothly, rather than exit silently, dump a helpful
> info message like pretty much every other MTD driver does.
> 
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>

Acked-by: Joern Engel <joern@logfs.org>

Care to take over maintainership?  I haven't used this driver in ages
and don't foresee using it anytime soon.

Jörn

-- 
You cannot suppose that Moliere ever troubled himself to be original in the
matter of ideas. You cannot suppose that the stories he tells in his plays
have never been told before. They were culled, as you very well know.
-- Andre-Louis Moreau in Scarabouche

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [MTD] phram: cleanup error handling and associated messages
  2009-06-17 11:24 ` Jörn Engel
@ 2009-06-17 11:49   ` Mike Frysinger
  2009-06-17 11:58     ` Jörn Engel
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Frysinger @ 2009-06-17 11:49 UTC (permalink / raw)
  To: Jörn Engel; +Cc: joern, linux-mtd

On Wed, Jun 17, 2009 at 07:24, Jörn Engel wrote:
> On Wed, 17 June 2009 06:50:18 -0400, Mike Frysinger wrote:
>> The error handling in the phram driver is pretty bad -- in many places,
>> errors are silently ignored or logged, but then still ignored in the
>> return value.  So convert all of the code to pass back the correct return
>> value and log error messages properly (and using the new pr_fmt() helper).
>
> I don't remember why I always returned 0 in phram_setup.  Could well
> have been an oversight.
>
>> If everything does go smoothly, rather than exit silently, dump a helpful
>> info message like pretty much every other MTD driver does.
>>
>> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
>
> Acked-by: Joern Engel <joern@logfs.org>
>
> Care to take over maintainership?  I haven't used this driver in ages
> and don't foresee using it anytime soon.

i actually have no vested interest in this driver either, sorry.  i
was asked a question about the driver where the user was using wrong
parameters but they didnt get any feedback -- no kernel messages and
the driver loading did not error out.  figured i'd fix it up rather
than have to answer the question again :).
-mike

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] [MTD] phram: cleanup error handling and associated messages
  2009-06-17 11:49   ` Mike Frysinger
@ 2009-06-17 11:58     ` Jörn Engel
  0 siblings, 0 replies; 4+ messages in thread
From: Jörn Engel @ 2009-06-17 11:58 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: linux-mtd

On Wed, 17 June 2009 07:49:43 -0400, Mike Frysinger wrote:
> 
> i actually have no vested interest in this driver either, sorry.  i
> was asked a question about the driver where the user was using wrong
> parameters but they didnt get any feedback -- no kernel messages and
> the driver loading did not error out.  figured i'd fix it up rather
> than have to answer the question again :).

Fair enough.

Jörn

-- 
The wise man seeks everything in himself; the ignorant man tries to get
everything from somebody else.
-- unknown

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-06-17 11:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-17 10:50 [PATCH] [MTD] phram: cleanup error handling and associated messages Mike Frysinger
2009-06-17 11:24 ` Jörn Engel
2009-06-17 11:49   ` Mike Frysinger
2009-06-17 11:58     ` Jörn Engel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.