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

iio: adc: Constify struct iio_map

'struct iio_map' are not modified in these drivers.

Constifying this structure moves some data to a read-only section, so
increase overall security.

In order to do it, the prototype of iio_map_array_register() and
devm_iio_map_array_register(), and a few structures that hold a
"struct iio_map *" need to be adjusted.

On a x86_64, with allmodconfig, as an example:
Before:
======
text data bss dec hex filename
21086 760 0 21846 5556 drivers/iio/adc/axp20x_adc.o

After:
=====
text data bss dec hex filename
21470 360 0 21830 5546 drivers/iio/adc/axp20x_adc.o
33842 1697 384 35923 8c53 drivers/iio/addac/ad74413r.o

--
Compile tested only

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://patch.msgid.link/5729dc3cc3892ecf0d8ea28c5f7307b34e27493e.1725729801.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Christophe JAILLET and committed by
Jonathan Cameron
faf17860 482447fd

+19 -17
+3 -3
drivers/iio/adc/axp20x_adc.c
··· 155 155 AXP813_BATT_V, 156 156 }; 157 157 158 - static struct iio_map axp20x_maps[] = { 158 + static const struct iio_map axp20x_maps[] = { 159 159 { 160 160 .consumer_dev_name = "axp20x-usb-power-supply", 161 161 .consumer_channel = "vbus_v", ··· 187 187 }, { /* sentinel */ } 188 188 }; 189 189 190 - static struct iio_map axp22x_maps[] = { 190 + static const struct iio_map axp22x_maps[] = { 191 191 { 192 192 .consumer_dev_name = "axp20x-battery-power-supply", 193 193 .consumer_channel = "batt_v", ··· 1044 1044 unsigned long adc_en2_mask; 1045 1045 int (*adc_rate)(struct axp20x_adc_iio *info, 1046 1046 int rate); 1047 - struct iio_map *maps; 1047 + const struct iio_map *maps; 1048 1048 }; 1049 1049 1050 1050 static const struct axp_data axp192_data = {
+1 -1
drivers/iio/adc/axp288_adc.c
··· 103 103 }; 104 104 105 105 /* for consumer drivers */ 106 - static struct iio_map axp288_adc_default_maps[] = { 106 + static const struct iio_map axp288_adc_default_maps[] = { 107 107 IIO_MAP("TS_PIN", "axp288-batt", "axp288-batt-temp"), 108 108 IIO_MAP("PMIC_TEMP", "axp288-pmic", "axp288-pmic-temp"), 109 109 IIO_MAP("GPADC", "axp288-gpadc", "axp288-system-temp"),
+1 -1
drivers/iio/adc/da9150-gpadc.c
··· 291 291 }; 292 292 293 293 /* Default maps used by da9150-charger */ 294 - static struct iio_map da9150_gpadc_default_maps[] = { 294 + static const struct iio_map da9150_gpadc_default_maps[] = { 295 295 { 296 296 .consumer_dev_name = "da9150-charger", 297 297 .consumer_channel = "CHAN_IBUS",
+1 -1
drivers/iio/adc/intel_mrfld_adc.c
··· 164 164 BCOVE_ADC_CHANNEL(IIO_TEMP, 8, "CH8", 0xC6), 165 165 }; 166 166 167 - static struct iio_map iio_maps[] = { 167 + static const struct iio_map iio_maps[] = { 168 168 IIO_MAP("CH0", "bcove-battery", "VBATRSLT"), 169 169 IIO_MAP("CH1", "bcove-battery", "BATTID"), 170 170 IIO_MAP("CH2", "bcove-battery", "IBATRSLT"),
+3 -3
drivers/iio/adc/lp8788_adc.c
··· 26 26 27 27 struct lp8788_adc { 28 28 struct lp8788 *lp; 29 - struct iio_map *map; 29 + const struct iio_map *map; 30 30 struct mutex lock; 31 31 }; 32 32 ··· 149 149 }; 150 150 151 151 /* default maps used by iio consumer (lp8788-charger driver) */ 152 - static struct iio_map lp8788_default_iio_maps[] = { 152 + static const struct iio_map lp8788_default_iio_maps[] = { 153 153 { 154 154 .consumer_dev_name = "lp8788-charger", 155 155 .consumer_channel = "lp8788_vbatt_5p0", ··· 168 168 struct lp8788_platform_data *pdata, 169 169 struct lp8788_adc *adc) 170 170 { 171 - struct iio_map *map; 171 + const struct iio_map *map; 172 172 int ret; 173 173 174 174 map = (!pdata || !pdata->adc_pdata) ?
+1 -1
drivers/iio/adc/mp2629_adc.c
··· 52 52 MP2629_ADC_CHAN(INPUT_CURRENT, IIO_CURRENT) 53 53 }; 54 54 55 - static struct iio_map mp2629_adc_maps[] = { 55 + static const struct iio_map mp2629_adc_maps[] = { 56 56 MP2629_MAP(BATT_VOLT, "batt-volt"), 57 57 MP2629_MAP(SYSTEM_VOLT, "system-volt"), 58 58 MP2629_MAP(INPUT_VOLT, "input-volt"),
+1 -1
drivers/iio/adc/rn5t618-adc.c
··· 185 185 RN5T618_ADC_CHANNEL(AIN0, IIO_VOLTAGE, "AIN0") 186 186 }; 187 187 188 - static struct iio_map rn5t618_maps[] = { 188 + static const struct iio_map rn5t618_maps[] = { 189 189 IIO_MAP("VADP", "rn5t618-power", "vadp"), 190 190 IIO_MAP("VUSB", "rn5t618-power", "vusb"), 191 191 { /* sentinel */ }
+1 -1
drivers/iio/adc/sun4i-gpadc-iio.c
··· 114 114 .datasheet_name = _name, \ 115 115 } 116 116 117 - static struct iio_map sun4i_gpadc_hwmon_maps[] = { 117 + static const struct iio_map sun4i_gpadc_hwmon_maps[] = { 118 118 { 119 119 .adc_channel_label = "temp_adc", 120 120 .consumer_dev_name = "iio_hwmon.0",
+4 -3
drivers/iio/inkern.c
··· 20 20 21 21 struct iio_map_internal { 22 22 struct iio_dev *indio_dev; 23 - struct iio_map *map; 23 + const struct iio_map *map; 24 24 struct list_head l; 25 25 }; 26 26 ··· 42 42 return ret; 43 43 } 44 44 45 - int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *maps) 45 + int iio_map_array_register(struct iio_dev *indio_dev, const struct iio_map *maps) 46 46 { 47 47 struct iio_map_internal *mapi; 48 48 int i = 0; ··· 86 86 iio_map_array_unregister(indio_dev); 87 87 } 88 88 89 - int devm_iio_map_array_register(struct device *dev, struct iio_dev *indio_dev, struct iio_map *maps) 89 + int devm_iio_map_array_register(struct device *dev, struct iio_dev *indio_dev, 90 + const struct iio_map *maps) 90 91 { 91 92 int ret; 92 93
+3 -2
include/linux/iio/driver.h
··· 18 18 * @map: array of mappings specifying association of channel with client 19 19 */ 20 20 int iio_map_array_register(struct iio_dev *indio_dev, 21 - struct iio_map *map); 21 + const struct iio_map *map); 22 22 23 23 /** 24 24 * iio_map_array_unregister() - tell the core to remove consumer mappings for ··· 38 38 * handle de-registration of the IIO map object when the device's refcount goes to 39 39 * zero. 40 40 */ 41 - int devm_iio_map_array_register(struct device *dev, struct iio_dev *indio_dev, struct iio_map *maps); 41 + int devm_iio_map_array_register(struct device *dev, struct iio_dev *indio_dev, 42 + const struct iio_map *maps); 42 43 43 44 #endif