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: Match iio_device_claim_*() semantics and implementation

Implement iio_device_claim_buffer_mode() fully inline with the use of
__iio_dev_mode_lock(), which takes care of sparse annotations.

To completely match iio_device_claim_direct() semantics, we need to
also change iio_device_claim_buffer_mode() return semantics to usual
true/false conditional lock semantics.

Additionally, to avoid silently breaking out-of-tree drivers, rename
iio_device_claim_buffer_mode() to iio_device_claim_try_buffer_mode().

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
2daee817 c37ec9d5

+39 -57
+1 -1
drivers/iio/adc/ade9000.c
··· 964 964 struct iio_dev *indio_dev = data; 965 965 966 966 /* Handle data ready interrupt from C4/EVENT/DREADY pin */ 967 - if (!iio_device_claim_buffer_mode(indio_dev)) { 967 + if (iio_device_try_claim_buffer_mode(indio_dev)) { 968 968 ade9000_iio_push_buffer(indio_dev); 969 969 iio_device_release_buffer_mode(indio_dev); 970 970 }
+1 -4
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
··· 188 188 /* 189 189 * Ignore samples if the buffer is not set: it is needed if the ODR is 190 190 * set but the buffer is not enabled yet. 191 - * 192 - * Note: iio_device_claim_buffer_mode() returns -EBUSY if the buffer 193 - * is not enabled. 194 191 */ 195 - if (iio_device_claim_buffer_mode(indio_dev) < 0) 192 + if (!iio_device_try_claim_buffer_mode(indio_dev)) 196 193 return 0; 197 194 198 195 out = (s16 *)st->samples;
+1 -7
drivers/iio/health/max30100.c
··· 417 417 * Temperature reading can only be acquired while engine 418 418 * is running 419 419 */ 420 - if (iio_device_claim_buffer_mode(indio_dev)) { 421 - /* 422 - * Replacing -EBUSY or other error code 423 - * returned by iio_device_claim_buffer_mode() 424 - * because user space may rely on the current 425 - * one. 426 - */ 420 + if (!iio_device_try_claim_buffer_mode(indio_dev)) { 427 421 ret = -EAGAIN; 428 422 } else { 429 423 ret = max30100_get_temp(data, val);
+1 -1
drivers/iio/health/max30102.c
··· 476 476 * shutdown; leave shutdown briefly when buffer not running 477 477 */ 478 478 any_mode_retry: 479 - if (iio_device_claim_buffer_mode(indio_dev)) { 479 + if (!iio_device_try_claim_buffer_mode(indio_dev)) { 480 480 /* 481 481 * This one is a *bit* hacky. If we cannot claim buffer 482 482 * mode, then try direct mode so that we make sure
+1 -41
drivers/iio/industrialio-core.c
··· 2183 2183 * 2184 2184 * There are very few cases where a driver actually needs to lock the current 2185 2185 * mode unconditionally. It's recommended to use iio_device_claim_direct() or 2186 - * iio_device_claim_buffer_mode() pairs or related helpers instead. 2186 + * iio_device_try_claim_buffer_mode() pairs or related helpers instead. 2187 2187 */ 2188 2188 void __iio_dev_mode_lock(struct iio_dev *indio_dev) 2189 2189 { ··· 2200 2200 mutex_unlock(&to_iio_dev_opaque(indio_dev)->mlock); 2201 2201 } 2202 2202 EXPORT_SYMBOL_GPL(__iio_dev_mode_unlock); 2203 - 2204 - /** 2205 - * iio_device_claim_buffer_mode - Keep device in buffer mode 2206 - * @indio_dev: the iio_dev associated with the device 2207 - * 2208 - * If the device is in buffer mode it is guaranteed to stay 2209 - * that way until iio_device_release_buffer_mode() is called. 2210 - * 2211 - * Use with iio_device_release_buffer_mode(). 2212 - * 2213 - * Returns: 0 on success, -EBUSY on failure. 2214 - */ 2215 - int iio_device_claim_buffer_mode(struct iio_dev *indio_dev) 2216 - { 2217 - struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 2218 - 2219 - mutex_lock(&iio_dev_opaque->mlock); 2220 - 2221 - if (iio_buffer_enabled(indio_dev)) 2222 - return 0; 2223 - 2224 - mutex_unlock(&iio_dev_opaque->mlock); 2225 - return -EBUSY; 2226 - } 2227 - EXPORT_SYMBOL_GPL(iio_device_claim_buffer_mode); 2228 - 2229 - /** 2230 - * iio_device_release_buffer_mode - releases claim on buffer mode 2231 - * @indio_dev: the iio_dev associated with the device 2232 - * 2233 - * Release the claim. Device is no longer guaranteed to stay 2234 - * in buffer mode. 2235 - * 2236 - * Use with iio_device_claim_buffer_mode(). 2237 - */ 2238 - void iio_device_release_buffer_mode(struct iio_dev *indio_dev) 2239 - { 2240 - mutex_unlock(&to_iio_dev_opaque(indio_dev)->mlock); 2241 - } 2242 - EXPORT_SYMBOL_GPL(iio_device_release_buffer_mode); 2243 2203 2244 2204 /** 2245 2205 * iio_device_get_current_mode() - helper function providing read-only access to
+1 -1
drivers/iio/light/opt4060.c
··· 304 304 struct opt4060_chip *chip = iio_priv(indio_dev); 305 305 int ret = 0; 306 306 any_mode_retry: 307 - if (iio_device_claim_buffer_mode(indio_dev)) { 307 + if (!iio_device_try_claim_buffer_mode(indio_dev)) { 308 308 /* 309 309 * This one is a *bit* hacky. If we cannot claim buffer mode, 310 310 * then try direct mode so that we make sure things cannot
+33 -2
include/linux/iio/iio.h
··· 706 706 */ 707 707 #define iio_device_release_direct(indio_dev) __iio_dev_mode_unlock(indio_dev) 708 708 709 - int iio_device_claim_buffer_mode(struct iio_dev *indio_dev); 710 - void iio_device_release_buffer_mode(struct iio_dev *indio_dev); 709 + /** 710 + * iio_device_try_claim_buffer_mode() - Keep device in buffer mode 711 + * @indio_dev: the iio_dev associated with the device 712 + * 713 + * If the device is in buffer mode it is guaranteed to stay 714 + * that way until iio_device_release_buffer_mode() is called. 715 + * 716 + * Use with iio_device_release_buffer_mode(). 717 + * 718 + * Returns: true on success, false on failure. 719 + */ 720 + static inline bool iio_device_try_claim_buffer_mode(struct iio_dev *indio_dev) 721 + { 722 + __iio_dev_mode_lock(indio_dev); 723 + 724 + if (!iio_buffer_enabled(indio_dev)) { 725 + __iio_dev_mode_unlock(indio_dev); 726 + return false; 727 + } 728 + 729 + return true; 730 + } 731 + 732 + /** 733 + * iio_device_release_buffer_mode() - releases claim on buffer mode 734 + * @indio_dev: the iio_dev associated with the device 735 + * 736 + * Release the claim. Device is no longer guaranteed to stay 737 + * in buffer mode. 738 + * 739 + * Use with iio_device_try_claim_buffer_mode(). 740 + */ 741 + #define iio_device_release_buffer_mode(indio_dev) __iio_dev_mode_unlock(indio_dev) 711 742 712 743 extern const struct bus_type iio_bus_type; 713 744