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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@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@xxxxxxxxxxxxx>
---
 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
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux