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

iio: Add dev_to_iio_dev() helper function

This patch adds a helper function for retriving a iio_dev struct from a device
struct. Currently we open-code this in two different ways. One is using
dev_get_drvdata on the device and the other is using container_of. The new
helper function uses the container_of solution as it creates slightly smaller
code and also will eventually free up the drvdata pointer for usage by invidual
drivers.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Lars-Peter Clausen and committed by
Greg Kroah-Hartman
7a7913f1 7086e6e5

+11
+11
include/linux/iio/iio.h
··· 427 427 put_device(&indio_dev->dev); 428 428 }; 429 429 430 + /** 431 + * dev_to_iio_dev() - Get IIO device struct from a device struct 432 + * @dev: The device embedded in the IIO device 433 + * 434 + * Note: The device must be a IIO device, otherwise the result is undefined. 435 + */ 436 + static inline struct iio_dev *dev_to_iio_dev(struct device *dev) 437 + { 438 + return container_of(dev, struct iio_dev, dev); 439 + } 440 + 430 441 /* Can we make this smaller? */ 431 442 #define IIO_ALIGN L1_CACHE_BYTES 432 443 /**