UBI: one less BUG usage
Subsystems (2)
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_devicfor (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 *iint 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
Quoted 4 lines · Randy Dunlap
From: Randy Dunlap <[email protected]>
Eliminate one
BUG()usage. The callers ofmajor_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.
Quoted 10 lines · Artem Bityutskiy
Quoted 4 lines · Randy Dunlap
From: Randy Dunlap <[email protected]>
Eliminate one
BUG()usage. The callers ofmajor_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 ***
Quoted 3 lines · Randy Dunlap
All my patch does is allow and handle error returns from
major_to_device()invol_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.