Browse Source

drivers: sensor: bmp581: add const qualifier when casting

Add the 'const' qualifier when casting 'dev->config' to 'struct
bmp581_config *' to preserve const-correctness and fix SonarQube warning :

 "A cast shall not remove any const or volatile qualification from the
 type of a pointer or reference."

This improves maintainability by respecting the const contract and resolve
static analysis issues.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
pull/92661/merge
Gaetan Perrot 6 days ago committed by Daniel DeGrasse
parent
commit
de1fa4776b
  1. 16
      drivers/sensor/bosch/bmp581/bmp581.c

16
drivers/sensor/bosch/bmp581/bmp581.c

@ -105,14 +105,14 @@ static int set_power_mode(enum bmp5_powermode powermode, const struct device *de @@ -105,14 +105,14 @@ static int set_power_mode(enum bmp5_powermode powermode, const struct device *de
static int get_power_mode(enum bmp5_powermode *powermode, const struct device *dev)
{
struct bmp581_config *conf;
const struct bmp581_config *conf;
int ret = BMP5_OK;
CHECKIF(powermode == NULL || dev == NULL) {
return -EINVAL;
}
conf = (struct bmp581_config *)dev->config;
conf = (const struct bmp581_config *)dev->config;
uint8_t reg = 0;
uint8_t raw_power_mode = 0;
@ -187,26 +187,26 @@ static int power_up_check(const struct device *dev) @@ -187,26 +187,26 @@ static int power_up_check(const struct device *dev)
static int get_interrupt_status(uint8_t *int_status, const struct device *dev)
{
struct bmp581_config *conf;
const struct bmp581_config *conf;
CHECKIF(int_status == NULL || dev == NULL) {
return -EINVAL;
}
conf = (struct bmp581_config *)dev->config;
conf = (const struct bmp581_config *)dev->config;
return i2c_reg_read_byte_dt(&conf->i2c, BMP5_REG_INT_STATUS, int_status);
}
static int get_nvm_status(uint8_t *nvm_status, const struct device *dev)
{
struct bmp581_config *conf;
const struct bmp581_config *conf;
CHECKIF(nvm_status == NULL || dev == NULL) {
return -EINVAL;
}
conf = (struct bmp581_config *)dev->config;
conf = (const struct bmp581_config *)dev->config;
return i2c_reg_read_byte_dt(&conf->i2c, BMP5_REG_STATUS, nvm_status);
}
@ -236,7 +236,7 @@ static int validate_chip_id(struct bmp581_data *drv) @@ -236,7 +236,7 @@ static int validate_chip_id(struct bmp581_data *drv)
static int get_osr_odr_press_config(struct bmp581_osr_odr_press_config *osr_odr_press_cfg,
const struct device *dev)
{
struct bmp581_config *conf;
const struct bmp581_config *conf;
/* Variable to store the function result */
int8_t rslt = 0;
@ -248,7 +248,7 @@ static int get_osr_odr_press_config(struct bmp581_osr_odr_press_config *osr_odr_ @@ -248,7 +248,7 @@ static int get_osr_odr_press_config(struct bmp581_osr_odr_press_config *osr_odr_
return -EINVAL;
}
conf = (struct bmp581_config *)dev->config;
conf = (const struct bmp581_config *)dev->config;
/* Get OSR and ODR configuration in burst read */
rslt = i2c_burst_read_dt(&conf->i2c, BMP5_REG_OSR_CONFIG, reg_data, 2);

Loading…
Cancel
Save