From: Devendra Naga <devendranaga4@xxxxxxxxx> The class_create function can return a pointer with an error code stuffed inside it if it fails. Handled it to make sure device_register doesn't get an invalid pointer. Also removed assignment of rc to 0 in the beginning of function because it gets changed after the call to register_chrdev function. Signed-off-by: Devendra Naga <devendranaga4@xxxxxxxxx> --- drivers/staging/dgnc/dgnc_driver.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/staging/dgnc/dgnc_driver.c b/drivers/staging/dgnc/dgnc_driver.c index 2154665..72bfb29 100644 --- a/drivers/staging/dgnc/dgnc_driver.c +++ b/drivers/staging/dgnc/dgnc_driver.c @@ -248,7 +248,7 @@ module_exit(dgnc_cleanup_module); */ static int dgnc_start(void) { - int rc = 0; + int rc; unsigned long flags; /* make sure that the globals are init'd before we do anything else */ @@ -271,6 +271,12 @@ static int dgnc_start(void) dgnc_Major = rc; dgnc_class = class_create(THIS_MODULE, "dgnc_mgmt"); + if (IS_ERR(dgnc_class)) { + rc = PTR_ERR(dgnc_class); + APR(("Can't creat dgnc class (%d)\n", rc)); + goto bad; + } + device_create(dgnc_class, NULL, MKDEV(dgnc_Major, 0), NULL, "dgnc_mgmt"); @@ -297,6 +303,10 @@ static int dgnc_start(void) add_timer(&dgnc_poll_timer); return rc; + +bad: + unregister_chrdev(dgnc_Major, "dgnc"); + return rc; } /* returns count (>= 0), or negative on error */ -- 1.7.9.5 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel