device: Const-ify all device driver instance pointers

Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2020-04-30 20:33:38 +02:00 committed by Carles Cufí
commit e18fcbba5a
1426 changed files with 9356 additions and 8368 deletions

View file

@ -19,7 +19,8 @@
#include <logging/log.h>
LOG_MODULE_REGISTER(ADT7420, CONFIG_SENSOR_LOG_LEVEL);
static int adt7420_temp_reg_read(struct device *dev, uint8_t reg, int16_t *val)
static int adt7420_temp_reg_read(const struct device *dev, uint8_t reg,
int16_t *val)
{
struct adt7420_data *drv_data = dev->data;
const struct adt7420_dev_config *cfg = dev->config;
@ -34,7 +35,8 @@ static int adt7420_temp_reg_read(struct device *dev, uint8_t reg, int16_t *val)
return 0;
}
static int adt7420_temp_reg_write(struct device *dev, uint8_t reg, int16_t val)
static int adt7420_temp_reg_write(const struct device *dev, uint8_t reg,
int16_t val)
{
struct adt7420_data *drv_data = dev->data;
const struct adt7420_dev_config *cfg = dev->config;
@ -43,10 +45,10 @@ static int adt7420_temp_reg_write(struct device *dev, uint8_t reg, int16_t val)
return i2c_write(drv_data->i2c, buf, sizeof(buf), cfg->i2c_addr);
}
static int adt7420_attr_set(struct device *dev,
enum sensor_channel chan,
enum sensor_attribute attr,
const struct sensor_value *val)
static int adt7420_attr_set(const struct device *dev,
enum sensor_channel chan,
enum sensor_attribute attr,
const struct sensor_value *val)
{
struct adt7420_data *drv_data = dev->data;
const struct adt7420_dev_config *cfg = dev->config;
@ -110,7 +112,8 @@ static int adt7420_attr_set(struct device *dev,
return 0;
}
static int adt7420_sample_fetch(struct device *dev, enum sensor_channel chan)
static int adt7420_sample_fetch(const struct device *dev,
enum sensor_channel chan)
{
struct adt7420_data *drv_data = dev->data;
int16_t value;
@ -127,9 +130,9 @@ static int adt7420_sample_fetch(struct device *dev, enum sensor_channel chan)
return 0;
}
static int adt7420_channel_get(struct device *dev,
enum sensor_channel chan,
struct sensor_value *val)
static int adt7420_channel_get(const struct device *dev,
enum sensor_channel chan,
struct sensor_value *val)
{
struct adt7420_data *drv_data = dev->data;
int32_t value;
@ -154,7 +157,7 @@ static const struct sensor_driver_api adt7420_driver_api = {
#endif
};
static int adt7420_probe(struct device *dev)
static int adt7420_probe(const struct device *dev)
{
struct adt7420_data *drv_data = dev->data;
const struct adt7420_dev_config *cfg = dev->config;
@ -200,7 +203,7 @@ static int adt7420_probe(struct device *dev)
return 0;
}
static int adt7420_init(struct device *dev)
static int adt7420_init(const struct device *dev)
{
struct adt7420_data *drv_data = dev->data;
const struct adt7420_dev_config *cfg = dev->config;

View file

@ -59,16 +59,16 @@
#define ADT7420_TEMP_SCALE 15625
struct adt7420_data {
struct device *i2c;
const struct device *i2c;
int16_t sample;
#ifdef CONFIG_ADT7420_TRIGGER
struct device *gpio;
const struct device *gpio;
struct gpio_callback gpio_cb;
sensor_trigger_handler_t th_handler;
struct sensor_trigger th_trigger;
struct device *dev;
const struct device *dev;
#if defined(CONFIG_ADT7420_TRIGGER_OWN_THREAD)
K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_ADT7420_THREAD_STACK_SIZE);
@ -92,11 +92,11 @@ struct adt7420_dev_config {
};
#ifdef CONFIG_ADT7420_TRIGGER
int adt7420_trigger_set(struct device *dev,
int adt7420_trigger_set(const struct device *dev,
const struct sensor_trigger *trig,
sensor_trigger_handler_t handler);
int adt7420_init_interrupt(struct device *dev);
int adt7420_init_interrupt(const struct device *dev);
#endif /* CONFIG_ADT7420_TRIGGER */

View file

@ -16,7 +16,7 @@
#include <logging/log.h>
LOG_MODULE_DECLARE(ADT7420, CONFIG_SENSOR_LOG_LEVEL);
static void setup_int(struct device *dev,
static void setup_int(const struct device *dev,
bool enable)
{
struct adt7420_data *drv_data = dev->data;
@ -28,7 +28,7 @@ static void setup_int(struct device *dev,
gpio_pin_interrupt_configure(drv_data->gpio, cfg->int_pin, flags);
}
static void handle_int(struct device *dev)
static void handle_int(const struct device *dev)
{
struct adt7420_data *drv_data = dev->data;
@ -41,7 +41,7 @@ static void handle_int(struct device *dev)
#endif
}
static void process_int(struct device *dev)
static void process_int(const struct device *dev)
{
struct adt7420_data *drv_data = dev->data;
const struct adt7420_dev_config *cfg = dev->config;
@ -67,7 +67,7 @@ static void process_int(struct device *dev)
}
}
static void adt7420_gpio_callback(struct device *dev,
static void adt7420_gpio_callback(const struct device *dev,
struct gpio_callback *cb, uint32_t pins)
{
struct adt7420_data *drv_data =
@ -79,7 +79,7 @@ static void adt7420_gpio_callback(struct device *dev,
#if defined(CONFIG_ADT7420_TRIGGER_OWN_THREAD)
static void adt7420_thread(int dev_ptr, int unused)
{
struct device *dev = INT_TO_POINTER(dev_ptr);
const struct device *dev = INT_TO_POINTER(dev_ptr);
struct adt7420_data *drv_data = dev->data;
ARG_UNUSED(unused);
@ -100,7 +100,7 @@ static void adt7420_work_cb(struct k_work *work)
}
#endif
int adt7420_trigger_set(struct device *dev,
int adt7420_trigger_set(const struct device *dev,
const struct sensor_trigger *trig,
sensor_trigger_handler_t handler)
{
@ -131,7 +131,7 @@ int adt7420_trigger_set(struct device *dev,
return 0;
}
int adt7420_init_interrupt(struct device *dev)
int adt7420_init_interrupt(const struct device *dev)
{
struct adt7420_data *drv_data = dev->data;
const struct adt7420_dev_config *cfg = dev->config;