[PATCH 2/3] staging: dgap: implement proper error handling in dgap_start()

2014-03-02 Thread Alexey Khoroshilov
dgap_start() ignored errors in class_create() and device_create().
The patch implements proper error handling.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov 
---
 drivers/staging/dgap/dgap.c | 22 --
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index 5271856..b4157d7 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -557,6 +557,7 @@ static int dgap_start(void)
 {
int rc = 0;
unsigned long flags;
+   struct device *device;
 
/*
 * make sure that the globals are
@@ -582,9 +583,18 @@ static int dgap_start(void)
return rc;
 
dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
-   device_create(dgap_class, NULL,
+   if (IS_ERR(dgap_class)) {
+   rc = PTR_ERR(dgap_class);
+   goto failed_class;
+   }
+
+   device = device_create(dgap_class, NULL,
MKDEV(DIGI_DGAP_MAJOR, 0),
NULL, "dgap_mgmt");
+   if (IS_ERR(device)) {
+   rc = PTR_ERR(device);
+   goto failed_device;
+   }
 
/*
 * Init any global tty stuff.
@@ -592,7 +602,7 @@ static int dgap_start(void)
rc = dgap_tty_preinit();
 
if (rc < 0)
-   return rc;
+   goto failed_tty;
 
/* Start the poller */
DGAP_LOCK(dgap_poll_lock, flags);
@@ -608,6 +618,14 @@ static int dgap_start(void)
dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
 
return rc;
+
+failed_tty:
+   device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
+failed_device:
+   class_destroy(dgap_class);
+failed_class:
+   unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
+   return rc;
 }
 
 /*
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/3] staging: dgap: implement proper error handling in dgap_start()

2014-03-02 Thread Alexey Khoroshilov
dgap_start() ignored errors in class_create() and device_create().
The patch implements proper error handling.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov khoroshi...@ispras.ru
---
 drivers/staging/dgap/dgap.c | 22 --
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index 5271856..b4157d7 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -557,6 +557,7 @@ static int dgap_start(void)
 {
int rc = 0;
unsigned long flags;
+   struct device *device;
 
/*
 * make sure that the globals are
@@ -582,9 +583,18 @@ static int dgap_start(void)
return rc;
 
dgap_class = class_create(THIS_MODULE, dgap_mgmt);
-   device_create(dgap_class, NULL,
+   if (IS_ERR(dgap_class)) {
+   rc = PTR_ERR(dgap_class);
+   goto failed_class;
+   }
+
+   device = device_create(dgap_class, NULL,
MKDEV(DIGI_DGAP_MAJOR, 0),
NULL, dgap_mgmt);
+   if (IS_ERR(device)) {
+   rc = PTR_ERR(device);
+   goto failed_device;
+   }
 
/*
 * Init any global tty stuff.
@@ -592,7 +602,7 @@ static int dgap_start(void)
rc = dgap_tty_preinit();
 
if (rc  0)
-   return rc;
+   goto failed_tty;
 
/* Start the poller */
DGAP_LOCK(dgap_poll_lock, flags);
@@ -608,6 +618,14 @@ static int dgap_start(void)
dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
 
return rc;
+
+failed_tty:
+   device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
+failed_device:
+   class_destroy(dgap_class);
+failed_class:
+   unregister_chrdev(DIGI_DGAP_MAJOR, dgap);
+   return rc;
 }
 
 /*
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/3] staging: dgap: implement proper error handling in dgap_start()

2014-02-23 Thread Alexey Khoroshilov
dgap_start() ignored errors in class_create() and device_create().
The patch implements proper error handling.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov 
---
 drivers/staging/dgap/dgap_driver.c | 42 +++---
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/dgap/dgap_driver.c 
b/drivers/staging/dgap/dgap_driver.c
index d7f1e999aaa4..136c879b560c 100644
--- a/drivers/staging/dgap/dgap_driver.c
+++ b/drivers/staging/dgap/dgap_driver.c
@@ -279,6 +279,7 @@ static int dgap_start(void)
 {
int rc = 0;
unsigned long flags;
+   struct device *device;
 
 /* make sure that the globals are init'd before we do anything else */
 dgap_init_globals();
@@ -303,12 +304,29 @@ static int dgap_start(void)
}
 
dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
-   device_create(dgap_class, NULL,
-   MKDEV(DIGI_DGAP_MAJOR, 0),
-   NULL, "dgap_mgmt");
-   device_create(dgap_class, NULL,
-   MKDEV(DIGI_DGAP_MAJOR, 1),
-   NULL, "dgap_downld");
+   if (IS_ERR(dgap_class)) {
+   rc = PTR_ERR(dgap_class);
+   APR(("Can't create dgap_mgmt class (%d)\n", rc));
+   goto failed_class;
+   }
+
+   device = device_create(dgap_class, NULL,
+   MKDEV(DIGI_DGAP_MAJOR, 0),
+   NULL, "dgap_mgmt");
+   if (IS_ERR(device)) {
+   rc = PTR_ERR(device);
+   APR(("Can't create device (%d)\n", rc));
+   goto failed_device0;
+   }
+
+   device = device_create(dgap_class, NULL,
+   MKDEV(DIGI_DGAP_MAJOR, 1),
+   NULL, "dgap_downld");
+   if (IS_ERR(device)) {
+   rc = PTR_ERR(device);
+   APR(("Can't create device (%d)\n", rc));
+   goto failed_device1;
+   }
 
/*
 * Init any global tty stuff.
@@ -316,7 +334,7 @@ static int dgap_start(void)
rc = dgap_tty_preinit();
if (rc < 0) {
APR(("tty preinit - not enough memory (%d)\n", rc));
-   return(rc); 
+   goto failed_tty;
}
 
/* Start the poller */
@@ -333,6 +351,16 @@ static int dgap_start(void)
dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
 
return (rc);
+
+failed_tty:
+   device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 1));
+failed_device1:
+   device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
+failed_device0:
+   class_destroy(dgap_class);
+failed_class:
+   unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
+   return (rc);
 }
 
 
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/3] staging: dgap: implement proper error handling in dgap_start()

2014-02-23 Thread Alexey Khoroshilov
dgap_start() ignored errors in class_create() and device_create().
The patch implements proper error handling.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov khoroshi...@ispras.ru
---
 drivers/staging/dgap/dgap_driver.c | 42 +++---
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/dgap/dgap_driver.c 
b/drivers/staging/dgap/dgap_driver.c
index d7f1e999aaa4..136c879b560c 100644
--- a/drivers/staging/dgap/dgap_driver.c
+++ b/drivers/staging/dgap/dgap_driver.c
@@ -279,6 +279,7 @@ static int dgap_start(void)
 {
int rc = 0;
unsigned long flags;
+   struct device *device;
 
 /* make sure that the globals are init'd before we do anything else */
 dgap_init_globals();
@@ -303,12 +304,29 @@ static int dgap_start(void)
}
 
dgap_class = class_create(THIS_MODULE, dgap_mgmt);
-   device_create(dgap_class, NULL,
-   MKDEV(DIGI_DGAP_MAJOR, 0),
-   NULL, dgap_mgmt);
-   device_create(dgap_class, NULL,
-   MKDEV(DIGI_DGAP_MAJOR, 1),
-   NULL, dgap_downld);
+   if (IS_ERR(dgap_class)) {
+   rc = PTR_ERR(dgap_class);
+   APR((Can't create dgap_mgmt class (%d)\n, rc));
+   goto failed_class;
+   }
+
+   device = device_create(dgap_class, NULL,
+   MKDEV(DIGI_DGAP_MAJOR, 0),
+   NULL, dgap_mgmt);
+   if (IS_ERR(device)) {
+   rc = PTR_ERR(device);
+   APR((Can't create device (%d)\n, rc));
+   goto failed_device0;
+   }
+
+   device = device_create(dgap_class, NULL,
+   MKDEV(DIGI_DGAP_MAJOR, 1),
+   NULL, dgap_downld);
+   if (IS_ERR(device)) {
+   rc = PTR_ERR(device);
+   APR((Can't create device (%d)\n, rc));
+   goto failed_device1;
+   }
 
/*
 * Init any global tty stuff.
@@ -316,7 +334,7 @@ static int dgap_start(void)
rc = dgap_tty_preinit();
if (rc  0) {
APR((tty preinit - not enough memory (%d)\n, rc));
-   return(rc); 
+   goto failed_tty;
}
 
/* Start the poller */
@@ -333,6 +351,16 @@ static int dgap_start(void)
dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
 
return (rc);
+
+failed_tty:
+   device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 1));
+failed_device1:
+   device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
+failed_device0:
+   class_destroy(dgap_class);
+failed_class:
+   unregister_chrdev(DIGI_DGAP_MAJOR, dgap);
+   return (rc);
 }
 
 
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/