Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6190102 authored by Marcel Siegert's avatar Marcel Siegert Committed by Mauro Carvalho Chehab
Browse files

V4L/DVB (5244): Dvbdev: fix illegal re-usage of fileoperations struct



Arjan van de Ven <arjan@infradead.org> reported an illegal re-usage of 
the fileoperations struct if more than one dvb device (e.g. frontend) is 
present. 

This patch fixes this issue.  

It allocates a new fileoperations struct each time a device is 
registered and copies the default template fileops.

Signed-off-by: default avatarMarcel Siegert <mws@linuxtv.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent e1af4980
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -199,6 +199,8 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
			const struct dvb_device *template, void *priv, int type)
{
	struct dvb_device *dvbdev;
	struct file_operations *dvbdevfops;

	int id;

	if (mutex_lock_interruptible(&dvbdev_register_lock))
@@ -218,12 +220,22 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
		return -ENOMEM;
	}

	dvbdevfops = kzalloc(sizeof(struct file_operations), GFP_KERNEL);

	if (!dvbdevfops){
		kfree (dvbdev);
		mutex_unlock(&dvbdev_register_lock);
		return -ENOMEM;
	}

	memcpy(dvbdev, template, sizeof(struct dvb_device));
	dvbdev->type = type;
	dvbdev->id = id;
	dvbdev->adapter = adap;
	dvbdev->priv = priv;
	dvbdev->fops = dvbdevfops;

	memcpy(dvbdev->fops, template->fops, sizeof(struct file_operations));
	dvbdev->fops->owner = adap->module;

	list_add_tail (&dvbdev->list_head, &adap->device_list);
@@ -251,6 +263,7 @@ void dvb_unregister_device(struct dvb_device *dvbdev)
					dvbdev->type, dvbdev->id)));

	list_del (&dvbdev->list_head);
	kfree (dvbdev->fops);
	kfree (dvbdev);
}
EXPORT_SYMBOL(dvb_unregister_device);