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.

iio: core: Refactor iio_device_claim_direct() implementation

In order to eventually unify the locking API, implement
iio_device_claim_direct() fully inline, with the use of
__iio_dev_mode_lock(), which takes care of sparse annotations.

Reviewed-by: David Lechner <dlechner@baylibre.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Kurt Borja <kuurtb@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Kurt Borja and committed by
Jonathan Cameron
c37ec9d5 88fd1f90

+28 -56
-44
drivers/iio/industrialio-core.c
··· 2202 2202 EXPORT_SYMBOL_GPL(__iio_dev_mode_unlock); 2203 2203 2204 2204 /** 2205 - * __iio_device_claim_direct - Keep device in direct mode 2206 - * @indio_dev: the iio_dev associated with the device 2207 - * 2208 - * If the device is in direct mode it is guaranteed to stay 2209 - * that way until __iio_device_release_direct() is called. 2210 - * 2211 - * Use with __iio_device_release_direct(). 2212 - * 2213 - * Drivers should only call iio_device_claim_direct(). 2214 - * 2215 - * Returns: true on success, false on failure. 2216 - */ 2217 - bool __iio_device_claim_direct(struct iio_dev *indio_dev) 2218 - { 2219 - struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 2220 - 2221 - mutex_lock(&iio_dev_opaque->mlock); 2222 - 2223 - if (iio_buffer_enabled(indio_dev)) { 2224 - mutex_unlock(&iio_dev_opaque->mlock); 2225 - return false; 2226 - } 2227 - return true; 2228 - } 2229 - EXPORT_SYMBOL_GPL(__iio_device_claim_direct); 2230 - 2231 - /** 2232 - * __iio_device_release_direct - releases claim on direct mode 2233 - * @indio_dev: the iio_dev associated with the device 2234 - * 2235 - * Release the claim. Device is no longer guaranteed to stay 2236 - * in direct mode. 2237 - * 2238 - * Drivers should only call iio_device_release_direct(). 2239 - * 2240 - * Use with __iio_device_claim_direct() 2241 - */ 2242 - void __iio_device_release_direct(struct iio_dev *indio_dev) 2243 - { 2244 - mutex_unlock(&to_iio_dev_opaque(indio_dev)->mlock); 2245 - } 2246 - EXPORT_SYMBOL_GPL(__iio_device_release_direct); 2247 - 2248 - /** 2249 2205 * iio_device_claim_buffer_mode - Keep device in buffer mode 2250 2206 * @indio_dev: the iio_dev associated with the device 2251 2207 *
+28 -12
include/linux/iio/iio.h
··· 664 664 665 665 void __iio_dev_mode_lock(struct iio_dev *indio_dev) __acquires(indio_dev); 666 666 void __iio_dev_mode_unlock(struct iio_dev *indio_dev) __releases(indio_dev); 667 - bool __iio_device_claim_direct(struct iio_dev *indio_dev); 668 - void __iio_device_release_direct(struct iio_dev *indio_dev); 669 667 670 668 /* 671 669 * Helper functions that allow claim and release of direct mode 672 670 * in a fashion that doesn't generate many false positives from sparse. 673 671 * Note this must remain static inline in the header so that sparse 674 - * can see the __acquire() marking. Revisit when sparse supports 675 - * __cond_acquires() 672 + * can see the __acquires() and __releases() annotations. 673 + */ 674 + 675 + /** 676 + * iio_device_claim_direct() - Keep device in direct mode 677 + * @indio_dev: the iio_dev associated with the device 678 + * 679 + * If the device is in direct mode it is guaranteed to stay 680 + * that way until iio_device_release_direct() is called. 681 + * 682 + * Use with iio_device_release_direct(). 683 + * 684 + * Returns: true on success, false on failure. 676 685 */ 677 686 static inline bool iio_device_claim_direct(struct iio_dev *indio_dev) 678 687 { 679 - if (!__iio_device_claim_direct(indio_dev)) 680 - return false; 688 + __iio_dev_mode_lock(indio_dev); 681 689 682 - __acquire(iio_dev); 690 + if (iio_buffer_enabled(indio_dev)) { 691 + __iio_dev_mode_unlock(indio_dev); 692 + return false; 693 + } 683 694 684 695 return true; 685 696 } 686 697 687 - static inline void iio_device_release_direct(struct iio_dev *indio_dev) 688 - { 689 - __iio_device_release_direct(indio_dev); 690 - __release(indio_dev); 691 - } 698 + /** 699 + * iio_device_release_direct() - Releases claim on direct mode 700 + * @indio_dev: the iio_dev associated with the device 701 + * 702 + * Release the claim. Device is no longer guaranteed to stay 703 + * in direct mode. 704 + * 705 + * Use with iio_device_claim_direct(). 706 + */ 707 + #define iio_device_release_direct(indio_dev) __iio_dev_mode_unlock(indio_dev) 692 708 693 709 int iio_device_claim_buffer_mode(struct iio_dev *indio_dev); 694 710 void iio_device_release_buffer_mode(struct iio_dev *indio_dev);