iio: addac: ad74xxx: Constify struct iio_chan_spec
Subsystems (5)
Kernel janitors IIO Analog Devices IIO drivers Analog devices inc AD74413R driver +1 more subsystems
PATCH 1/1 iio: addac: ad74xxx: Constify struct iio_chan_spec
'struct iio_chan_spec' are not modified in these drivers.
Constifying this structure moves some data to a read-only section, so increase overall security.
On a x86_64, with allmodconfig:
Before:
======
text data bss dec hex filename 35749 5879 384 42012 a41c drivers/iio/addac/ad74115.o 32242 3297 384 35923 8c53 drivers/iio/addac/ad74413r.o
After:
=====
text data bss dec hex filename 39109 2519 384 42012 a41c drivers/iio/addac/ad74115.o 33842 1697 384 35923 8c53 drivers/iio/addac/ad74413r.o
Signed-off-by Christophe JAILLET <[email protected]>
---
Compile tested only
--- drivers/iio/addac/ad74115.c | 18 +++++++++--------- drivers/iio/addac/ad74413r.c | 21 +++++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-)
drivers/iio/addac/ad74115.c +9 -9
@@ -191,7 +191,7 @@ enum ad74115_gpio_mode { };struct ad74115_channels { -struct iio_chan_spec *channels; +const struct iio_chan_spec *channels;unsigned int num_channels; };
@@ -1295,46 +1295,46 @@ static const struct iio_info ad74115_info = {_AD74115_ADC_CHANNEL (_type, index,BIT (IIO_CHAN_INFO_SCALE ) \ | BIT(IIO_CHAN_INFO_OFFSET)) -static struct iio_chan_spec ad74115_voltage_input_channels[] = { +static const struct iio_chan_spec ad74115_voltage_input_channels[] = {AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV1 ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV2 ), }; -static struct iio_chan_spec ad74115_voltage_output_channels[] = { +static const struct iio_chan_spec ad74115_voltage_output_channels[] = {AD74115_DAC_CHANNEL (IIO_VOLTAGE ,AD74115_DAC_CH_MAIN ),AD74115_ADC_CHANNEL (IIO_CURRENT ,AD74115_ADC_CH_CONV1 ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV2 ), }; -static struct iio_chan_spec ad74115_current_input_channels[] = { +static const struct iio_chan_spec ad74115_current_input_channels[] = {AD74115_ADC_CHANNEL (IIO_CURRENT ,AD74115_ADC_CH_CONV1 ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV2 ), }; -static struct iio_chan_spec ad74115_current_output_channels[] = { +static const struct iio_chan_spec ad74115_current_output_channels[] = {AD74115_DAC_CHANNEL (IIO_CURRENT ,AD74115_DAC_CH_MAIN ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV1 ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV2 ), }; -static struct iio_chan_spec ad74115_2_wire_resistance_input_channels[] = { +static const struct iio_chan_spec ad74115_2_wire_resistance_input_channels[] = {_AD74115_ADC_CHANNEL (IIO_RESISTANCE ,AD74115_ADC_CH_CONV1 ,BIT (IIO_CHAN_INFO_PROCESSED )),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV2 ), }; -static struct iio_chan_spec ad74115_3_4_wire_resistance_input_channels[] = { +static const struct iio_chan_spec ad74115_3_4_wire_resistance_input_channels[] = {AD74115_ADC_CHANNEL (IIO_RESISTANCE ,AD74115_ADC_CH_CONV1 ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV2 ), }; -static struct iio_chan_spec ad74115_digital_input_logic_channels[] = { +static const struct iio_chan_spec ad74115_digital_input_logic_channels[] = {AD74115_DAC_CHANNEL (IIO_VOLTAGE ,AD74115_DAC_CH_COMPARATOR ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV1 ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV2 ), }; -static struct iio_chan_spec ad74115_digital_input_loop_channels[] = { +static const struct iio_chan_spec ad74115_digital_input_loop_channels[] = {AD74115_DAC_CHANNEL (IIO_CURRENT ,AD74115_DAC_CH_MAIN ),AD74115_DAC_CHANNEL (IIO_VOLTAGE ,AD74115_DAC_CH_COMPARATOR ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV1 ),
drivers/iio/addac/ad74413r.c +11 -10
@@ -45,8 +45,8 @@ struct ad74413r_channel_config { };struct ad74413r_channels { -struct iio_chan_spec *channels; -unsigned int num_channels; +const struct iio_chan_spec *channels; +unsigned int num_channels; };struct ad74413r_state {
@@ -1138,34 +1138,34 @@ static const struct iio_info ad74413r_info = {AD74413R_ADC_CHANNEL (IIO_CURRENT ,BIT (IIO_CHAN_INFO_SCALE ) \ | BIT(IIO_CHAN_INFO_OFFSET)) -static struct iio_chan_spec ad74413r_voltage_output_channels[] = { +static const struct iio_chan_spec ad74413r_voltage_output_channels[] = {AD74413R_DAC_CHANNEL (IIO_VOLTAGE ,BIT (IIO_CHAN_INFO_SCALE )),AD74413R_ADC_CURRENT_CHANNEL , }; -static struct iio_chan_spec ad74413r_current_output_channels[] = { +static const struct iio_chan_spec ad74413r_current_output_channels[] = {AD74413R_DAC_CHANNEL (IIO_CURRENT ,BIT (IIO_CHAN_INFO_SCALE )),AD74413R_ADC_VOLTAGE_CHANNEL , }; -static struct iio_chan_spec ad74413r_voltage_input_channels[] = { +static const struct iio_chan_spec ad74413r_voltage_input_channels[] = {AD74413R_ADC_VOLTAGE_CHANNEL , }; -static struct iio_chan_spec ad74413r_current_input_channels[] = { +static const struct iio_chan_spec ad74413r_current_input_channels[] = {AD74413R_ADC_CURRENT_CHANNEL , }; -static struct iio_chan_spec ad74413r_current_input_loop_channels[] = { +static const struct iio_chan_spec ad74413r_current_input_loop_channels[] = {AD74413R_DAC_CHANNEL (IIO_CURRENT ,BIT (IIO_CHAN_INFO_SCALE )),AD74413R_ADC_CURRENT_CHANNEL , }; -static struct iio_chan_spec ad74413r_resistance_input_channels[] = { +static const struct iio_chan_spec ad74413r_resistance_input_channels[] = {AD74413R_ADC_CHANNEL (IIO_RESISTANCE ,BIT (IIO_CHAN_INFO_PROCESSED )), }; -static struct iio_chan_spec ad74413r_digital_input_channels[] = { +static const struct iio_chan_spec ad74413r_digital_input_channels[] = {AD74413R_ADC_VOLTAGE_CHANNEL , };
@@ -1270,7 +1270,8 @@ static int ad74413r_setup_channels(struct iio_dev *indio_dev) {struct ad74413r_state *st =iio_priv (indio_dev);struct ad74413r_channel_config *config; -struct iio_chan_spec *channels, *chans; +const struct iio_chan_spec *chans; +struct iio_chan_spec *channels;unsigned int i, num_chans, chan_i;int ret;
Signature · 1 line
2.46.0
Re: [PATCH] iio: addac: ad74xxx: Constify struct iio_chan_spec
Quoted 12 lines · On Sat, 7 Sep 2024 15:51:07 +0200 Christophe JAILLET…
'struct
iio_chan_spec' are not modified in these drivers.Constifying this structure moves some data to a read-only section, so increase overall security.
On a
x86_64, with allmodconfig:
Before:
======text data bss dec hex filename 35749 5879 384 42012 a41c drivers/iio/addac/ad74115.o 32242 3297 384 35923 8c53 drivers/iio/addac/ad74413r.o
Quoted 7 lines
After:
=====text data bss dec hex filename 39109 2519 384 42012 a41c drivers/iio/addac/ad74115.o 33842 1697 384 35923 8c53 drivers/iio/addac/ad74413r.oSigned-off-by Christophe JAILLET <[email protected]>
Looks obviously correct. Hopefully looks are not being deceiving.
Applied. Note this is probably next cycle material now given timing. Jonathan
Quoted 142 lines
---
Compile tested only--- drivers/iio/addac/ad74115.c | 18 +++++++++--------- drivers/iio/addac/ad74413r.c | 21 +++++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-)drivers/iio/addac/ad74115.c +9
-9@@ -191,7 +191,7 @@ enum ad74115_gpio_mode { };struct ad74115_channels { -struct iio_chan_spec *channels; +const struct iio_chan_spec *channels;unsigned int num_channels; };@@ -1295,46 +1295,46 @@ static const struct iio_info ad74115_info = {_AD74115_ADC_CHANNEL (_type, index,BIT (IIO_CHAN_INFO_SCALE ) \ | BIT(IIO_CHAN_INFO_OFFSET)) -static struct iio_chan_spec ad74115_voltage_input_channels[] = { +static const struct iio_chan_spec ad74115_voltage_input_channels[] = {AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV1 ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV2 ), }; -static struct iio_chan_spec ad74115_voltage_output_channels[] = { +static const struct iio_chan_spec ad74115_voltage_output_channels[] = {AD74115_DAC_CHANNEL (IIO_VOLTAGE ,AD74115_DAC_CH_MAIN ),AD74115_ADC_CHANNEL (IIO_CURRENT ,AD74115_ADC_CH_CONV1 ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV2 ), }; -static struct iio_chan_spec ad74115_current_input_channels[] = { +static const struct iio_chan_spec ad74115_current_input_channels[] = {AD74115_ADC_CHANNEL (IIO_CURRENT ,AD74115_ADC_CH_CONV1 ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV2 ), }; -static struct iio_chan_spec ad74115_current_output_channels[] = { +static const struct iio_chan_spec ad74115_current_output_channels[] = {AD74115_DAC_CHANNEL (IIO_CURRENT ,AD74115_DAC_CH_MAIN ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV1 ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV2 ), }; -static struct iio_chan_spec ad74115_2_wire_resistance_input_channels[] = { +static const struct iio_chan_spec ad74115_2_wire_resistance_input_channels[] = {_AD74115_ADC_CHANNEL (IIO_RESISTANCE ,AD74115_ADC_CH_CONV1 ,BIT (IIO_CHAN_INFO_PROCESSED )),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV2 ), }; -static struct iio_chan_spec ad74115_3_4_wire_resistance_input_channels[] = { +static const struct iio_chan_spec ad74115_3_4_wire_resistance_input_channels[] = {AD74115_ADC_CHANNEL (IIO_RESISTANCE ,AD74115_ADC_CH_CONV1 ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV2 ), }; -static struct iio_chan_spec ad74115_digital_input_logic_channels[] = { +static const struct iio_chan_spec ad74115_digital_input_logic_channels[] = {AD74115_DAC_CHANNEL (IIO_VOLTAGE ,AD74115_DAC_CH_COMPARATOR ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV1 ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV2 ), }; -static struct iio_chan_spec ad74115_digital_input_loop_channels[] = { +static const struct iio_chan_spec ad74115_digital_input_loop_channels[] = {AD74115_DAC_CHANNEL (IIO_CURRENT ,AD74115_DAC_CH_MAIN ),AD74115_DAC_CHANNEL (IIO_VOLTAGE ,AD74115_DAC_CH_COMPARATOR ),AD74115_ADC_CHANNEL (IIO_VOLTAGE ,AD74115_ADC_CH_CONV1 ),drivers/iio/addac/ad74413r.c +11
-10@@ -45,8 +45,8 @@ struct ad74413r_channel_config { };struct ad74413r_channels { -struct iio_chan_spec *channels; -unsigned int num_channels; +const struct iio_chan_spec *channels; +unsigned int num_channels; };struct ad74413r_state {@@ -1138,34 +1138,34 @@ static const struct iio_info ad74413r_info = {AD74413R_ADC_CHANNEL (IIO_CURRENT ,BIT (IIO_CHAN_INFO_SCALE ) \ | BIT(IIO_CHAN_INFO_OFFSET)) -static struct iio_chan_spec ad74413r_voltage_output_channels[] = { +static const struct iio_chan_spec ad74413r_voltage_output_channels[] = {AD74413R_DAC_CHANNEL (IIO_VOLTAGE ,BIT (IIO_CHAN_INFO_SCALE )),AD74413R_ADC_CURRENT_CHANNEL , }; -static struct iio_chan_spec ad74413r_current_output_channels[] = { +static const struct iio_chan_spec ad74413r_current_output_channels[] = {AD74413R_DAC_CHANNEL (IIO_CURRENT ,BIT (IIO_CHAN_INFO_SCALE )),AD74413R_ADC_VOLTAGE_CHANNEL , }; -static struct iio_chan_spec ad74413r_voltage_input_channels[] = { +static const struct iio_chan_spec ad74413r_voltage_input_channels[] = {AD74413R_ADC_VOLTAGE_CHANNEL , }; -static struct iio_chan_spec ad74413r_current_input_channels[] = { +static const struct iio_chan_spec ad74413r_current_input_channels[] = {AD74413R_ADC_CURRENT_CHANNEL , }; -static struct iio_chan_spec ad74413r_current_input_loop_channels[] = { +static const struct iio_chan_spec ad74413r_current_input_loop_channels[] = {AD74413R_DAC_CHANNEL (IIO_CURRENT ,BIT (IIO_CHAN_INFO_SCALE )),AD74413R_ADC_CURRENT_CHANNEL , }; -static struct iio_chan_spec ad74413r_resistance_input_channels[] = { +static const struct iio_chan_spec ad74413r_resistance_input_channels[] = {AD74413R_ADC_CHANNEL (IIO_RESISTANCE ,BIT (IIO_CHAN_INFO_PROCESSED )), }; -static struct iio_chan_spec ad74413r_digital_input_channels[] = { +static const struct iio_chan_spec ad74413r_digital_input_channels[] = {AD74413R_ADC_VOLTAGE_CHANNEL , };@@ -1270,7 +1270,8 @@ static int ad74413r_setup_channels(struct iio_dev *indio_dev) {struct ad74413r_state *st =iio_priv (indio_dev);struct ad74413r_channel_config *config; -struct iio_chan_spec *channels, *chans; +const struct iio_chan_spec *chans; +struct iio_chan_spec *channels;unsigned int i, num_chans, chan_i;int ret;