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

Commit 26291233 authored by James Hogan's avatar James Hogan Committed by Mauro Carvalho Chehab
Browse files

[media] rc-main: fix missing unlock if no devno left



While playing with make coccicheck I noticed this message:
drivers/media/rc/rc-main.c:1245:3-9: preceding lock on line 1238

It was introduced by commit 587d1b06 ([media] rc-core: reuse device
numbers) which returns -ENOMEM after a mutex_lock without first
unlocking it when there are no more device numbers left. The added code
doesn't depend on the device lock, so move it before the lock is taken.

Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
parent cdcb12e7
Loading
Loading
Loading
Loading
+8 −8
Original line number Original line Diff line number Diff line
@@ -1286,14 +1286,6 @@ int rc_register_device(struct rc_dev *dev)
	if (dev->close)
	if (dev->close)
		dev->input_dev->close = ir_close;
		dev->input_dev->close = ir_close;


	/*
	 * Take the lock here, as the device sysfs node will appear
	 * when device_add() is called, which may trigger an ir-keytable udev
	 * rule, which will in turn call show_protocols and access
	 * dev->enabled_protocols before it has been initialized.
	 */
	mutex_lock(&dev->lock);

	do {
	do {
		devno = find_first_zero_bit(ir_core_dev_number,
		devno = find_first_zero_bit(ir_core_dev_number,
					    IRRCV_NUM_DEVICES);
					    IRRCV_NUM_DEVICES);
@@ -1302,6 +1294,14 @@ int rc_register_device(struct rc_dev *dev)
			return -ENOMEM;
			return -ENOMEM;
	} while (test_and_set_bit(devno, ir_core_dev_number));
	} while (test_and_set_bit(devno, ir_core_dev_number));


	/*
	 * Take the lock here, as the device sysfs node will appear
	 * when device_add() is called, which may trigger an ir-keytable udev
	 * rule, which will in turn call show_protocols and access
	 * dev->enabled_protocols before it has been initialized.
	 */
	mutex_lock(&dev->lock);

	dev->devno = devno;
	dev->devno = devno;
	dev_set_name(&dev->dev, "rc%ld", dev->devno);
	dev_set_name(&dev->dev, "rc%ld", dev->devno);
	dev_set_drvdata(&dev->dev, dev);
	dev_set_drvdata(&dev->dev, dev);