staging: dgnc: don't forget to check if ->channels[i] is NULL in dgnc_tty_uninit()
authorGiedrius Statkevičius <giedrius.statkevicius@gmail.com>
Thu, 9 Apr 2015 23:42:30 +0000 (02:42 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 May 2015 07:24:00 +0000 (09:24 +0200)
Add a check if ->channels[i] is NULL because a NULL pointer may be dereferenced
in case one of the allocations failed

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/dgnc/dgnc_tty.c

index a8c88f829e424886b674ed6cc1783caadc284c71..6c9261cb88ecc73e6cba8ff37b445d86d6537bcc 100644 (file)
@@ -403,7 +403,9 @@ void dgnc_tty_uninit(struct dgnc_board *brd)
                dgnc_BoardsByMajor[brd->SerialDriver.major] = NULL;
                brd->dgnc_Serial_Major = 0;
                for (i = 0; i < brd->nasync; i++) {
-                       dgnc_remove_tty_sysfs(brd->channels[i]->ch_tun.un_sysfs);
+                       if (brd->channels[i])
+                               dgnc_remove_tty_sysfs(brd->channels[i]->
+                                                     ch_tun.un_sysfs);
                        tty_unregister_device(&brd->SerialDriver, i);
                }
                tty_unregister_driver(&brd->SerialDriver);
@@ -414,7 +416,9 @@ void dgnc_tty_uninit(struct dgnc_board *brd)
                dgnc_BoardsByMajor[brd->PrintDriver.major] = NULL;
                brd->dgnc_TransparentPrint_Major = 0;
                for (i = 0; i < brd->nasync; i++) {
-                       dgnc_remove_tty_sysfs(brd->channels[i]->ch_pun.un_sysfs);
+                       if (brd->channels[i])
+                               dgnc_remove_tty_sysfs(brd->channels[i]->
+                                                     ch_pun.un_sysfs);
                        tty_unregister_device(&brd->PrintDriver, i);
                }
                tty_unregister_driver(&brd->PrintDriver);