Эх сурвалжийг харах

V4L/DVB (3725): Fix mutex in dvb_register_device to work.

This mutex is meant to stop two devices getting the same ID. dvbdev_get_free_id() 
scans the list of already allocated devices to find a free id.
Unfortunately, since the mutex is unlocked before the card is added to the
above list, it is still possible for two of them to get the same id.
Its debatable whether this mutex lock is actually needed, but I'm unwilling
to just remove it in case something does depend on it.

Signed-off-by: Andrew de Quincey <adq_dvb@lidskialf.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Andrew de Quincey 19 жил өмнө
parent
commit
f47f4763cd

+ 2 - 2
drivers/media/dvb/dvb-core/dvbdev.c

@@ -219,8 +219,6 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
 		return -ENOMEM;
 		return -ENOMEM;
 	}
 	}
 
 
-	mutex_unlock(&dvbdev_register_lock);
-
 	memcpy(dvbdev, template, sizeof(struct dvb_device));
 	memcpy(dvbdev, template, sizeof(struct dvb_device));
 	dvbdev->type = type;
 	dvbdev->type = type;
 	dvbdev->id = id;
 	dvbdev->id = id;
@@ -231,6 +229,8 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
 
 
 	list_add_tail (&dvbdev->list_head, &adap->device_list);
 	list_add_tail (&dvbdev->list_head, &adap->device_list);
 
 
+	mutex_unlock(&dvbdev_register_lock);
+
 	devfs_mk_cdev(MKDEV(DVB_MAJOR, nums2minor(adap->num, type, id)),
 	devfs_mk_cdev(MKDEV(DVB_MAJOR, nums2minor(adap->num, type, id)),
 			S_IFCHR | S_IRUSR | S_IWUSR,
 			S_IFCHR | S_IRUSR | S_IWUSR,
 			"dvb/adapter%d/%s%d", adap->num, dnames[type], id);
 			"dvb/adapter%d/%s%d", adap->num, dnames[type], id);