Commit faf17860 authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Jonathan Cameron
Browse files

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: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://patch.msgid.link/5729dc3cc3892ecf0d8ea28c5f7307b34e27493e.1725729801.git.christophe.jaillet@wanadoo.fr


Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 482447fd
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ enum axp813_adc_channel_v {
	AXP813_BATT_V,
};

static struct iio_map axp20x_maps[] = {
static const struct iio_map axp20x_maps[] = {
	{
		.consumer_dev_name = "axp20x-usb-power-supply",
		.consumer_channel = "vbus_v",
@@ -187,7 +187,7 @@ static struct iio_map axp20x_maps[] = {
	}, { /* sentinel */ }
};

static struct iio_map axp22x_maps[] = {
static const struct iio_map axp22x_maps[] = {
	{
		.consumer_dev_name = "axp20x-battery-power-supply",
		.consumer_channel = "batt_v",
@@ -1044,7 +1044,7 @@ struct axp_data {
	unsigned long			adc_en2_mask;
	int				(*adc_rate)(struct axp20x_adc_iio *info,
						    int rate);
	struct iio_map			*maps;
	const struct iio_map		*maps;
};

static const struct axp_data axp192_data = {
+1 −1
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ static const struct iio_chan_spec axp288_adc_channels[] = {
};

/* for consumer drivers */
static struct iio_map axp288_adc_default_maps[] = {
static const struct iio_map axp288_adc_default_maps[] = {
	IIO_MAP("TS_PIN", "axp288-batt", "axp288-batt-temp"),
	IIO_MAP("PMIC_TEMP", "axp288-pmic", "axp288-pmic-temp"),
	IIO_MAP("GPADC", "axp288-gpadc", "axp288-system-temp"),
+1 −1
Original line number Diff line number Diff line
@@ -291,7 +291,7 @@ static const struct iio_chan_spec da9150_gpadc_channels[] = {
};

/* Default maps used by da9150-charger */
static struct iio_map da9150_gpadc_default_maps[] = {
static const struct iio_map da9150_gpadc_default_maps[] = {
	{
		.consumer_dev_name = "da9150-charger",
		.consumer_channel = "CHAN_IBUS",
+1 −1
Original line number Diff line number Diff line
@@ -164,7 +164,7 @@ static const struct iio_chan_spec mrfld_adc_channels[] = {
	BCOVE_ADC_CHANNEL(IIO_TEMP,       8, "CH8", 0xC6),
};

static struct iio_map iio_maps[] = {
static const struct iio_map iio_maps[] = {
	IIO_MAP("CH0", "bcove-battery", "VBATRSLT"),
	IIO_MAP("CH1", "bcove-battery", "BATTID"),
	IIO_MAP("CH2", "bcove-battery", "IBATRSLT"),
+3 −3
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@

struct lp8788_adc {
	struct lp8788 *lp;
	struct iio_map *map;
	const struct iio_map *map;
	struct mutex lock;
};

@@ -149,7 +149,7 @@ static const struct iio_chan_spec lp8788_adc_channels[] = {
};

/* default maps used by iio consumer (lp8788-charger driver) */
static struct iio_map lp8788_default_iio_maps[] = {
static const struct iio_map lp8788_default_iio_maps[] = {
	{
		.consumer_dev_name = "lp8788-charger",
		.consumer_channel = "lp8788_vbatt_5p0",
@@ -168,7 +168,7 @@ static int lp8788_iio_map_register(struct device *dev,
				struct lp8788_platform_data *pdata,
				struct lp8788_adc *adc)
{
	struct iio_map *map;
	const struct iio_map *map;
	int ret;

	map = (!pdata || !pdata->adc_pdata) ?
Loading