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

iio: acpi: Add iio_get_acpi_device_name_and_data() helper function

A few drivers duplicate the code to retrieve ACPI device instance name.
Some of them want an associated driver data as well.

In order of deduplication introduce the common helper functions.

Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://patch.msgid.link/20241024191200.229894-6-andriy.shevchenko@linux.intel.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Andy Shevchenko and committed by
Jonathan Cameron
dc60de4e d411e5b5

+47 -1
+37 -1
drivers/iio/industrialio-acpi.c
··· 2 2 /* IIO ACPI helper functions */ 3 3 4 4 #include <linux/acpi.h> 5 - #include <linux/dev_printk.h> 5 + #include <linux/device.h> 6 + #include <linux/export.h> 6 7 #include <linux/iio/iio.h> 7 8 #include <linux/sprintf.h> 8 9 ··· 88 87 return ret; 89 88 } 90 89 EXPORT_SYMBOL_GPL(iio_read_acpi_mount_matrix); 90 + 91 + /** 92 + * iio_get_acpi_device_name_and_data() - Return ACPI device instance name and driver data 93 + * @dev: Device structure 94 + * @data: Optional pointer to return driver data 95 + * 96 + * When device was enumerated by ACPI ID matching, the user might 97 + * want to set description for the physical chip. In such cases 98 + * the ACPI device instance name might be used. This call may be 99 + * performed to retrieve this information. 100 + * 101 + * NOTE: This helper function exists only for backward compatibility, 102 + * do not use in a new code! 103 + * 104 + * Returns: ACPI device instance name or %NULL. 105 + */ 106 + const char *iio_get_acpi_device_name_and_data(struct device *dev, const void **data) 107 + { 108 + const struct acpi_device_id *id; 109 + acpi_handle handle; 110 + 111 + handle = ACPI_HANDLE(dev); 112 + if (!handle) 113 + return NULL; 114 + 115 + id = acpi_match_device(dev->driver->acpi_match_table, dev); 116 + if (!id) 117 + return NULL; 118 + 119 + if (data) 120 + *data = (const void *)id->driver_data; 121 + 122 + return dev_name(dev); 123 + } 124 + EXPORT_SYMBOL_GPL(iio_get_acpi_device_name_and_data);
+10
include/linux/iio/iio.h
··· 831 831 bool iio_read_acpi_mount_matrix(struct device *dev, 832 832 struct iio_mount_matrix *orientation, 833 833 char *acpi_method); 834 + const char *iio_get_acpi_device_name_and_data(struct device *dev, const void **data); 834 835 #else 835 836 static inline bool iio_read_acpi_mount_matrix(struct device *dev, 836 837 struct iio_mount_matrix *orientation, ··· 839 838 { 840 839 return false; 841 840 } 841 + static inline const char * 842 + iio_get_acpi_device_name_and_data(struct device *dev, const void **data) 843 + { 844 + return NULL; 845 + } 842 846 #endif 847 + static inline const char *iio_get_acpi_device_name(struct device *dev) 848 + { 849 + return iio_get_acpi_device_name_and_data(dev, NULL); 850 + } 843 851 844 852 /** 845 853 * iio_get_current_scan_type - Get the current scan type for a channel