drivers: i2s: Add missing const qualifiers

The i2s_config structure passed to the i2s_configure() function is
not supposed to be modified by the driver. Similarly, the structure
returned by the i2s_config_get() function is not supposed to be
modified outside the driver.
Decorate the pointers to those structures with the const qualifier
and correct one driver that actually modified the structure passed
to i2s_configure().

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
This commit is contained in:
Andrzej Głąbek 2021-04-13 14:21:00 +02:00 committed by Anas Nashif
commit 7fcf78073b
8 changed files with 33 additions and 29 deletions

View file

@ -227,7 +227,7 @@ static void i2s_dma_rx_callback(const struct device *dma_dev, void *arg,
}
static int i2s_cavs_configure(const struct device *dev, enum i2s_dir dir,
struct i2s_config *i2s_cfg)
const struct i2s_config *i2s_cfg)
{
const struct i2s_cavs_config *const dev_cfg = DEV_CFG(dev);
struct i2s_cavs_dev_data *const dev_data = DEV_DATA(dev);

View file

@ -16,8 +16,9 @@ int z_impl_i2s_buf_read(const struct device *dev, void *buf, size_t *size)
ret = i2s_read((const struct device *)dev, &mem_block, size);
if (!ret) {
struct i2s_config *rx_cfg =
i2s_config_get((const struct device *)dev, I2S_DIR_RX);
const struct i2s_config *rx_cfg;
rx_cfg = i2s_config_get((const struct device *)dev, I2S_DIR_RX);
memcpy(buf, mem_block, *size);
k_mem_slab_free(rx_cfg->mem_slab, &mem_block);
@ -29,7 +30,7 @@ int z_impl_i2s_buf_read(const struct device *dev, void *buf, size_t *size)
int z_impl_i2s_buf_write(const struct device *dev, void *buf, size_t size)
{
int ret;
struct i2s_config *tx_cfg;
const struct i2s_config *tx_cfg;
void *mem_block;
tx_cfg = i2s_config_get((const struct device *)dev, I2S_DIR_TX);

View file

@ -11,7 +11,7 @@
static inline int z_vrfy_i2s_configure(const struct device *dev,
enum i2s_dir dir,
struct i2s_config *cfg_ptr)
const struct i2s_config *cfg_ptr)
{
struct i2s_config config;
int ret = -EINVAL;
@ -20,7 +20,7 @@ static inline int z_vrfy_i2s_configure(const struct device *dev,
goto out;
}
Z_OOPS(z_user_from_copy(&config, (void *)cfg_ptr,
Z_OOPS(z_user_from_copy(&config, (const void *)cfg_ptr,
sizeof(struct i2s_config)));
/* Check that the k_mem_slab provided is a valid pointer and that
@ -55,14 +55,13 @@ static inline int z_vrfy_i2s_buf_read(const struct device *dev,
ret = i2s_read((const struct device *)dev, &mem_block, &data_size);
if (!ret) {
struct i2s_config *rx_cfg;
const struct i2s_config *rx_cfg;
int copy_success;
/* Presumed to be configured otherwise the i2s_read() call
* would have failed.
*/
rx_cfg = i2s_config_get((const struct device *)dev,
I2S_DIR_RX);
rx_cfg = i2s_config_get((const struct device *)dev, I2S_DIR_RX);
copy_success = z_user_to_copy((void *)buf, mem_block,
data_size);
@ -81,7 +80,7 @@ static inline int z_vrfy_i2s_buf_write(const struct device *dev,
void *buf, size_t size)
{
int ret;
struct i2s_config *tx_cfg;
const struct i2s_config *tx_cfg;
void *mem_block;
Z_OOPS(Z_SYSCALL_DRIVER_I2S(dev, write));

View file

@ -334,7 +334,7 @@ static int i2s_litex_initialize(const struct device *dev)
}
static int i2s_litex_configure(const struct device *dev, enum i2s_dir dir,
struct i2s_config *i2s_cfg)
const struct i2s_config *i2s_cfg)
{
struct i2s_litex_data *const dev_data = DEV_DATA(dev);
const struct i2s_litex_cfg *const cfg = DEV_CFG(dev);
@ -393,7 +393,9 @@ static int i2s_litex_configure(const struct device *dev, enum i2s_dir dir,
"only %"
"i bytes of data are valid ",
req_buf_s);
i2s_cfg->block_size = req_buf_s;
/* The block_size field will be corrected to req_buf_s in the
* structure copied as stream configuration (see below).
*/
}
int dev_sample_width = i2s_get_sample_width(cfg->base);
@ -434,6 +436,8 @@ static int i2s_litex_configure(const struct device *dev, enum i2s_dir dir,
#endif
memcpy(&stream->cfg, i2s_cfg, sizeof(struct i2s_config));
stream->cfg.block_size = req_buf_s;
stream->state = I2S_STATE_READY;
return 0;
}

View file

@ -181,7 +181,7 @@ static int i2s_stm32_set_clock(const struct device *dev,
}
static int i2s_stm32_configure(const struct device *dev, enum i2s_dir dir,
struct i2s_config *i2s_cfg)
const struct i2s_config *i2s_cfg)
{
const struct i2s_stm32_cfg *const cfg = DEV_CFG(dev);
struct i2s_stm32_data *const dev_data = DEV_DATA(dev);

View file

@ -48,7 +48,7 @@ struct i2s_mcux_data {
static int i2s_mcux_flexcomm_cfg_convert(uint32_t base_frequency,
enum i2s_dir dir,
struct i2s_config *i2s_cfg,
const struct i2s_config *i2s_cfg,
i2s_config_t *fsl_cfg)
{
if (dir == I2S_DIR_RX) {
@ -149,8 +149,8 @@ static int i2s_mcux_flexcomm_cfg_convert(uint32_t base_frequency,
return 0;
}
static struct i2s_config *i2s_mcux_config_get(const struct device *dev,
enum i2s_dir dir)
static const struct i2s_config *i2s_mcux_config_get(const struct device *dev,
enum i2s_dir dir)
{
struct i2s_mcux_data *dev_data = dev->data;
struct stream *stream;
@ -169,7 +169,7 @@ static struct i2s_config *i2s_mcux_config_get(const struct device *dev,
}
static int i2s_mcux_configure(const struct device *dev, enum i2s_dir dir,
struct i2s_config *i2s_cfg)
const struct i2s_config *i2s_cfg)
{
const struct i2s_mcux_config *cfg = dev->config;
struct i2s_mcux_data *dev_data = dev->data;

View file

@ -311,7 +311,7 @@ tx_disable:
}
static int set_rx_data_format(const struct i2s_sam_dev_cfg *const dev_cfg,
struct i2s_config *i2s_cfg)
const struct i2s_config *i2s_cfg)
{
Ssc *const ssc = dev_cfg->regs;
const bool pin_rk_en = IS_ENABLED(CONFIG_I2S_SAM_SSC_0_PIN_RK_EN);
@ -404,7 +404,7 @@ static int set_rx_data_format(const struct i2s_sam_dev_cfg *const dev_cfg,
}
static int set_tx_data_format(const struct i2s_sam_dev_cfg *const dev_cfg,
struct i2s_config *i2s_cfg)
const struct i2s_config *i2s_cfg)
{
Ssc *const ssc = dev_cfg->regs;
uint8_t word_size_bits = i2s_cfg->word_size;
@ -515,8 +515,8 @@ static int bit_clock_set(Ssc *const ssc, uint32_t bit_clk_freq)
return 0;
}
static struct i2s_config *i2s_sam_config_get(const struct device *dev,
enum i2s_dir dir)
static const struct i2s_config *i2s_sam_config_get(const struct device *dev,
enum i2s_dir dir)
{
struct i2s_sam_dev_data *const dev_data = DEV_DATA(dev);
struct stream *stream;
@ -535,7 +535,7 @@ static struct i2s_config *i2s_sam_config_get(const struct device *dev,
}
static int i2s_sam_configure(const struct device *dev, enum i2s_dir dir,
struct i2s_config *i2s_cfg)
const struct i2s_config *i2s_cfg)
{
const struct i2s_sam_dev_cfg *const dev_cfg = DEV_CFG(dev);
struct i2s_sam_dev_data *const dev_data = DEV_DATA(dev);