media: dvbdev: fix error logic at dvb_register_device()
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Wed, 9 Jun 2021 12:32:29 +0000 (14:32 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Thu, 17 Jun 2021 07:25:31 +0000 (09:25 +0200)
As reported by smatch:

drivers/media/dvb-core/dvbdev.c: drivers/media/dvb-core/dvbdev.c:510 dvb_register_device() warn: '&dvbdev->list_head' not removed from list
drivers/media/dvb-core/dvbdev.c: drivers/media/dvb-core/dvbdev.c:530 dvb_register_device() warn: '&dvbdev->list_head' not removed from list
drivers/media/dvb-core/dvbdev.c: drivers/media/dvb-core/dvbdev.c:545 dvb_register_device() warn: '&dvbdev->list_head' not removed from list

The error logic inside dvb_register_device() doesn't remove
devices from the dvb_adapter_list in case of errors.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/dvb-core/dvbdev.c

index 3862ddc..795d9bf 100644 (file)
@@ -506,6 +506,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
                        break;
 
        if (minor == MAX_DVB_MINORS) {
+               list_del (&dvbdev->list_head);
                kfree(dvbdevfops);
                kfree(dvbdev);
                up_write(&minor_rwsem);
@@ -526,6 +527,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
                      __func__);
 
                dvb_media_device_free(dvbdev);
+               list_del (&dvbdev->list_head);
                kfree(dvbdevfops);
                kfree(dvbdev);
                mutex_unlock(&dvbdev_register_lock);
@@ -541,6 +543,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
                pr_err("%s: failed to create device dvb%d.%s%d (%ld)\n",
                       __func__, adap->num, dnames[type], id, PTR_ERR(clsdev));
                dvb_media_device_free(dvbdev);
+               list_del (&dvbdev->list_head);
                kfree(dvbdevfops);
                kfree(dvbdev);
                return PTR_ERR(clsdev);