public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH -mm] UBI: one less BUG usage
@ 2007-06-26 22:30 Randy Dunlap
  2007-06-27 21:47 ` Artem Bityutskiy
  0 siblings, 1 reply; 4+ messages in thread
From: Randy Dunlap @ 2007-06-26 22:30 UTC (permalink / raw)
  To: linux-mtd; +Cc: akpm

From: Randy Dunlap <randy.dunlap@oracle.com>

Eliminate one BUG() usage.  The callers of major_to_device() already
handle and report errors.  This is just another error to return.

Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
---
 drivers/mtd/ubi/cdev.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

--- linux-2622-rc4mm2.orig/drivers/mtd/ubi/cdev.c
+++ linux-2622-rc4mm2/drivers/mtd/ubi/cdev.c
@@ -63,7 +63,7 @@ static struct ubi_device *major_to_devic
 	for (i = 0; i < ubi_devices_cnt; i++)
 		if (ubi_devices[i] && ubi_devices[i]->major == major)
 			return ubi_devices[i];
-	BUG();
+	return ERR_PTR(-ENODEV);
 }
 
 /**
@@ -127,6 +127,9 @@ static int vol_cdev_open(struct inode *i
 	int vol_id = iminor(inode) - 1;
 	int mode;
 
+	if (IS_ERR(ubi))
+		return PTR_ERR(ubi);
+
 	if (file->f_mode & FMODE_WRITE)
 		mode = UBI_READWRITE;
 	else

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

* Re: [PATCH -mm] UBI: one less BUG usage
  2007-06-26 22:30 [PATCH -mm] UBI: one less BUG usage Randy Dunlap
@ 2007-06-27 21:47 ` Artem Bityutskiy
  2007-06-28  5:13   ` Randy Dunlap
  0 siblings, 1 reply; 4+ messages in thread
From: Artem Bityutskiy @ 2007-06-27 21:47 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: akpm, linux-mtd

On Tue, 26 Jun 2007, Randy Dunlap wrote:

> From: Randy Dunlap <randy.dunlap@oracle.com>
>
> Eliminate one BUG() usage.  The callers of major_to_device() already
> handle and report errors.  This is just another error to return.

Why is this just an error? It must never happen unles there is a bug in 
the code. Or is there a campaign against BUG() calls?

Artem.

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

* Re: [PATCH -mm] UBI: one less BUG usage
  2007-06-27 21:47 ` Artem Bityutskiy
@ 2007-06-28  5:13   ` Randy Dunlap
  2007-06-28 16:36     ` Artem Bityutskiy
  0 siblings, 1 reply; 4+ messages in thread
From: Randy Dunlap @ 2007-06-28  5:13 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: akpm, linux-mtd

Artem Bityutskiy wrote:
> On Tue, 26 Jun 2007, Randy Dunlap wrote:
> 
>> From: Randy Dunlap <randy.dunlap@oracle.com>
>>
>> Eliminate one BUG() usage.  The callers of major_to_device() already
>> handle and report errors.  This is just another error to return.
> 
> Why is this just an error? It must never happen unles there is a bug in 
> the code. Or is there a campaign against BUG() calls?
> 
> Artem.

There's always a campaign against unneeded BUG() calls.
However, if you say this one is needed, then so be it.

However(2), ubi_cdev_ioctl() calls major_to_device() and allows it
to return an error [although major_to_device() currently cannot
return such an error]:

	ubi = major_to_device(imajor(inode));
	if (IS_ERR(ubi))
		return PTR_ERR(ubi);

so part of cdev.c allows and handles error returns from major_to_device().

All my patch does is allow and handle error returns from major_to_device()
in vol_cdev_open().  vol_cdev_open() already handles errors by returning
the error to its caller.

-- 
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

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

* Re: [PATCH -mm] UBI: one less BUG usage
  2007-06-28  5:13   ` Randy Dunlap
@ 2007-06-28 16:36     ` Artem Bityutskiy
  0 siblings, 0 replies; 4+ messages in thread
From: Artem Bityutskiy @ 2007-06-28 16:36 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: akpm, linux-mtd

On Wed, 27 Jun 2007, Randy Dunlap wrote:
> All my patch does is allow and handle error returns from major_to_device()
> in vol_cdev_open().  vol_cdev_open() already handles errors by returning
> the error to its caller.

Yes, I see the inconsistency, I'd prefer to remove that error check 
instead.

Artem.

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

end of thread, other threads:[~2007-06-28 16:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-26 22:30 [PATCH -mm] UBI: one less BUG usage Randy Dunlap
2007-06-27 21:47 ` Artem Bityutskiy
2007-06-28  5:13   ` Randy Dunlap
2007-06-28 16:36     ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox