Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

media: v4l: subdev: Add a function to lock two sub-device states, use it

Add two new functions, v4l2_subdev_lock_states() and
v4l2_subdev_unclock_states(), to acquire and release the state of two
sub-devices. They differ from calling v4l2_subdev_{un,}lock_state() so
that if the two states share the same lock, the lock is acquired only
once.

Also use the new functions in v4l2_subdev_link_validate().

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Julien Massot <julien.massot@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

authored by

Sakari Ailus and committed by
Hans Verkuil
72364b91 cd2c7545

+44 -8
+4 -8
drivers/media/v4l2-core/v4l2-subdev.c
··· 1437 1437 1438 1438 states_locked = sink_state && source_state; 1439 1439 1440 - if (states_locked) { 1441 - v4l2_subdev_lock_state(sink_state); 1442 - v4l2_subdev_lock_state(source_state); 1443 - } 1440 + if (states_locked) 1441 + v4l2_subdev_lock_states(sink_state, source_state); 1444 1442 1445 1443 ret = v4l2_subdev_link_validate_locked(link, states_locked); 1446 1444 1447 - if (states_locked) { 1448 - v4l2_subdev_unlock_state(sink_state); 1449 - v4l2_subdev_unlock_state(source_state); 1450 - } 1445 + if (states_locked) 1446 + v4l2_subdev_unlock_states(sink_state, source_state); 1451 1447 1452 1448 return ret; 1453 1449 }
+40
include/media/v4l2-subdev.h
··· 1725 1725 } 1726 1726 1727 1727 /** 1728 + * v4l2_subdev_lock_states - Lock two sub-device states 1729 + * @state1: One subdevice state 1730 + * @state2: The other subdevice state 1731 + * 1732 + * Locks the state of two sub-devices. 1733 + * 1734 + * The states must be unlocked with v4l2_subdev_unlock_states() after use. 1735 + * 1736 + * This differs from calling v4l2_subdev_lock_state() on both states so that if 1737 + * the states share the same lock, the lock is acquired only once (so no 1738 + * deadlock occurs). The caller is responsible for ensuring the locks will 1739 + * always be acquired in the same order. 1740 + */ 1741 + static inline void v4l2_subdev_lock_states(struct v4l2_subdev_state *state1, 1742 + struct v4l2_subdev_state *state2) 1743 + { 1744 + mutex_lock(state1->lock); 1745 + if (state1->lock != state2->lock) 1746 + mutex_lock(state2->lock); 1747 + } 1748 + 1749 + /** 1750 + * v4l2_subdev_unlock_states() - Unlock two sub-device states 1751 + * @state1: One subdevice state 1752 + * @state2: The other subdevice state 1753 + * 1754 + * Unlocks the state of two sub-devices. 1755 + * 1756 + * This differs from calling v4l2_subdev_unlock_state() on both states so that 1757 + * if the states share the same lock, the lock is released only once. 1758 + */ 1759 + static inline void v4l2_subdev_unlock_states(struct v4l2_subdev_state *state1, 1760 + struct v4l2_subdev_state *state2) 1761 + { 1762 + mutex_unlock(state1->lock); 1763 + if (state1->lock != state2->lock) 1764 + mutex_unlock(state2->lock); 1765 + } 1766 + 1767 + /** 1728 1768 * v4l2_subdev_get_unlocked_active_state() - Checks that the active subdev state 1729 1769 * is unlocked and returns it 1730 1770 * @sd: The subdevice