Skip to contentSkip to conversation

UBI: one less BUG usage

PATCH In review Randy Dunlap 2 participants 4 messages Jun 26, 2007 – Jun 28, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 UBI: one less BUG usage

From: Randy Dunlap <[email protected]>

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

---
 drivers/mtd/ubi/cdev.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mtd/ubi/cdev.c +4 -1
@@ -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
#1 lore raw
Quoted 4 lines · Randy Dunlap

From: Randy Dunlap <[email protected]>

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.

#2 lore raw
Quoted 10 lines · Artem Bityutskiy
Quoted 4 lines · Randy Dunlap

From: Randy Dunlap <[email protected]>

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.

Signature · 2 lines
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***
#3 lore raw
Quoted 3 lines · Randy Dunlap

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.