PATCH] drivers/staging/dgnc/dgnc_mgmt.c add some goto statements

Francis Laniel laniel_francis at inventati.org
Tue Dec 20 10:49:41 UTC 2016


Hello.


As asked in the TODO file for this driver I added some goto statements to
handle errors.

I used Linus Torvalds tree, I compiled it and tested it with a virtual
machine, here is the proof :
[   42.394265] dgnc: module is from the staging directory, ...
[root at vm-nmv ~]# uname -r
4.9.0-11815-ge93b1cc-dirty

It is my first patch so I hope I did not break anything.


Good bye and thank you.

Signed-off-by: Francis Laniel <laniel_francis at inventati.org>
---
 drivers/staging/dgnc/dgnc_mgmt.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_mgmt.c b/drivers/staging/dgnc/
dgnc_mgmt.c
index 9d9b15d..6e41010 100644
--- a/drivers/staging/dgnc/dgnc_mgmt.c
+++ b/drivers/staging/dgnc/dgnc_mgmt.c
@@ -40,27 +40,34 @@ static int dgnc_mgmt_in_use[MAXMGMTDEVICES];
  */
 int dgnc_mgmt_open(struct inode *inode, struct file *file)
 {
+       int rc;
+
        unsigned long flags;
        unsigned int minor = iminor(inode);
 
        spin_lock_irqsave(&dgnc_global_lock, flags);
 
+       rc = 0;
+
        /* mgmt device */
        if (minor < MAXMGMTDEVICES) {
                /* Only allow 1 open at a time on mgmt device */
                if (dgnc_mgmt_in_use[minor]) {
-                       spin_unlock_irqrestore(&dgnc_global_lock, flags);
-                       return -EBUSY;
+                       rc = -EBUSY;
+
+                       goto end;
                }
                dgnc_mgmt_in_use[minor]++;
        } else {
-               spin_unlock_irqrestore(&dgnc_global_lock, flags);
-               return -ENXIO;
+               rc = -ENXIO;
+
+               goto end;
        }
 
+end:
        spin_unlock_irqrestore(&dgnc_global_lock, flags);
 
-       return 0;
+       return rc;
 }
 
 /*
@@ -110,6 +117,8 @@ long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
 
                memset(&ddi, 0, sizeof(ddi));
                ddi.dinfo_nboards = dgnc_num_boards;
+
+               /* Is it possible to use snprintf ? */
                sprintf(ddi.dinfo_version, "%s", DG_PART);
 
                spin_unlock_irqrestore(&dgnc_global_lock, flags);
-- 
2.9.3


More information about the devel mailing list