Skip to content

video: addition of __ASSERT to ensure proper arguments in api functions #90415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions drivers/video/ov7670.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,6 @@ static int ov7670_get_fmt(const struct device *dev, struct video_format *fmt)
{
struct ov7670_data *data = dev->data;

if (fmt == NULL) {
return -EINVAL;
}
memcpy(fmt, &data->fmt, sizeof(data->fmt));
return 0;
}
Expand Down
25 changes: 25 additions & 0 deletions drivers/video/video_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ void video_buffer_release(struct video_buffer *vbuf)
struct mem_block *block = NULL;
int i;

__ASSERT_NO_MSG(vbuf != NULL);

/* vbuf to block */
for (i = 0; i < ARRAY_SIZE(video_block); i++) {
if (video_block[i].data == vbuf->buffer) {
Expand All @@ -99,6 +101,10 @@ void video_buffer_release(struct video_buffer *vbuf)
int video_format_caps_index(const struct video_format_cap *fmts, const struct video_format *fmt,
size_t *idx)
{
__ASSERT_NO_MSG(fmts != NULL);
__ASSERT_NO_MSG(fmt != NULL);
__ASSERT_NO_MSG(idx != NULL);

for (int i = 0; fmts[i].pixelformat != 0; i++) {
if (fmts[i].pixelformat == fmt->pixelformat &&
IN_RANGE(fmt->width, fmts[i].width_min, fmts[i].width_max) &&
Expand All @@ -114,6 +120,10 @@ void video_closest_frmival_stepwise(const struct video_frmival_stepwise *stepwis
const struct video_frmival *desired,
struct video_frmival *match)
{
__ASSERT_NO_MSG(stepwise != NULL);
__ASSERT_NO_MSG(desired != NULL);
__ASSERT_NO_MSG(match != NULL);

uint64_t min = stepwise->min.numerator;
uint64_t max = stepwise->max.numerator;
uint64_t step = stepwise->step.numerator;
Expand All @@ -136,6 +146,9 @@ void video_closest_frmival_stepwise(const struct video_frmival_stepwise *stepwis

void video_closest_frmival(const struct device *dev, struct video_frmival_enum *match)
{
__ASSERT_NO_MSG(dev != NULL);
__ASSERT_NO_MSG(match != NULL);

struct video_frmival desired = match->discrete;
struct video_frmival_enum fie = {.format = match->format};
uint64_t best_diff_nsec = INT32_MAX;
Expand Down Expand Up @@ -207,6 +220,8 @@ int video_read_cci_reg(const struct i2c_dt_spec *i2c, uint32_t reg_addr, uint32_
uint8_t *data_ptr;
int ret;

__ASSERT_NO_MSG(i2c != NULL);
__ASSERT_NO_MSG(reg_data != NULL);
__ASSERT(addr_size > 0, "The address must have a address size flag");
__ASSERT(data_size > 0, "The address must have a data size flag");

Expand Down Expand Up @@ -246,6 +261,9 @@ static int video_write_reg_retry(const struct i2c_dt_spec *i2c, uint8_t *buf_w,
{
int ret;

__ASSERT_NO_MSG(i2c != NULL);
__ASSERT_NO_MSG(buf_w != NULL);

for (int i = 0;; i++) {
ret = i2c_write_dt(i2c, buf_w, size);
if (ret == 0) {
Expand All @@ -272,6 +290,7 @@ int video_write_cci_reg(const struct i2c_dt_spec *i2c, uint32_t reg_addr, uint32
uint8_t *data_ptr;
int ret;

__ASSERT_NO_MSG(i2c != NULL);
__ASSERT(addr_size > 0, "The address must have a address size flag");
__ASSERT(data_size > 0, "The address must have a data size flag");

Expand Down Expand Up @@ -326,6 +345,8 @@ int video_write_cci_multiregs(const struct i2c_dt_spec *i2c, const struct video_
{
int ret;

__ASSERT_NO_MSG(regs != NULL);

for (int i = 0; i < num_regs; i++) {
ret = video_write_cci_reg(i2c, regs[i].addr, regs[i].data);
if (ret < 0) {
Expand All @@ -341,6 +362,8 @@ int video_write_cci_multiregs8(const struct i2c_dt_spec *i2c, const struct video
{
int ret;

__ASSERT_NO_MSG(regs != NULL);

for (int i = 0; i < num_regs; i++) {
ret = video_write_cci_reg(i2c, regs[i].addr | VIDEO_REG_ADDR8_DATA8, regs[i].data);
if (ret < 0) {
Expand All @@ -356,6 +379,8 @@ int video_write_cci_multiregs16(const struct i2c_dt_spec *i2c, const struct vide
{
int ret;

__ASSERT_NO_MSG(regs != NULL);

for (int i = 0; i < num_regs; i++) {
ret = video_write_cci_reg(i2c, regs[i].addr | VIDEO_REG_ADDR16_DATA8, regs[i].data);
if (ret < 0) {
Expand Down
21 changes: 18 additions & 3 deletions drivers/video/video_ctrls.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@ int video_init_ctrl(struct video_ctrl *ctrl, const struct device *dev, uint32_t
uint32_t flags;
enum video_ctrl_type type;
struct video_ctrl *vc;
struct video_device *vdev = video_find_vdev(dev);
struct video_device *vdev;

__ASSERT_NO_MSG(dev != NULL);
__ASSERT_NO_MSG(ctrl != NULL);

vdev = video_find_vdev(dev);
if (!vdev) {
return -EINVAL;
}
Expand Down Expand Up @@ -261,6 +265,9 @@ int video_get_ctrl(const struct device *dev, struct video_control *control)
{
struct video_ctrl *ctrl = NULL;

__ASSERT_NO_MSG(dev != NULL);
__ASSERT_NO_MSG(control != NULL);

int ret = video_find_ctrl(dev, control->id, &ctrl);

if (ret) {
Expand Down Expand Up @@ -299,11 +306,15 @@ int video_get_ctrl(const struct device *dev, struct video_control *control)
int video_set_ctrl(const struct device *dev, struct video_control *control)
{
struct video_ctrl *ctrl = NULL;
int ret = video_find_ctrl(dev, control->id, &ctrl);
int ret;
uint8_t i = 0;
int32_t val = 0;
int64_t val64 = 0;

__ASSERT_NO_MSG(dev != NULL);
__ASSERT_NO_MSG(control != NULL);

ret = video_find_ctrl(dev, control->id, &ctrl);
if (ret) {
return ret;
}
Expand Down Expand Up @@ -516,6 +527,9 @@ int video_query_ctrl(const struct device *dev, struct video_ctrl_query *cq)
struct video_device *vdev;
struct video_ctrl *ctrl = NULL;

__ASSERT_NO_MSG(dev != NULL);
__ASSERT_NO_MSG(cq != NULL);

if (cq->id & VIDEO_CTRL_FLAG_NEXT_CTRL) {
vdev = video_find_vdev(dev);
cq->id &= ~VIDEO_CTRL_FLAG_NEXT_CTRL;
Expand Down Expand Up @@ -552,7 +566,8 @@ void video_print_ctrl(const struct device *const dev, const struct video_ctrl_qu
const char *type = NULL;
char typebuf[8];

__ASSERT(dev && cq, "Invalid arguments");
__ASSERT_NO_MSG(dev != NULL);
__ASSERT_NO_MSG(cq != NULL);

/* Get type of the control */
switch (cq->type) {
Expand Down
8 changes: 0 additions & 8 deletions drivers/video/video_esp32_dvp.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,6 @@ static int video_esp32_get_fmt(const struct device *dev, struct video_format *fm

LOG_DBG("Get format");

if (fmt == NULL) {
return -EINVAL;
}

ret = video_get_format(cfg->source_dev, fmt);
if (ret) {
LOG_ERR("Failed to get format from source");
Expand All @@ -280,10 +276,6 @@ static int video_esp32_set_fmt(const struct device *dev, struct video_format *fm
struct video_esp32_data *data = dev->data;
int ret;

if (fmt == NULL) {
return -EINVAL;
}

ret = video_set_format(cfg->source_dev, fmt);
if (ret < 0) {
return ret;
Expand Down
4 changes: 0 additions & 4 deletions drivers/video/video_mcux_csi.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ static int video_mcux_csi_get_fmt(const struct device *dev, struct video_format
{
const struct video_mcux_csi_config *config = dev->config;

if (fmt == NULL) {
return -EINVAL;
}

if (config->source_dev && !video_get_format(config->source_dev, fmt)) {
#if defined(CONFIG_VIDEO_MCUX_MIPI_CSI2RX)
video_pix_fmt_convert(fmt, true);
Expand Down
4 changes: 0 additions & 4 deletions drivers/video/video_mcux_mipi_csi2rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ static int mipi_csi2rx_get_fmt(const struct device *dev, struct video_format *fm
{
const struct mipi_csi2rx_config *config = dev->config;

if (fmt == NULL) {
return -EINVAL;
}

if (video_get_format(config->sensor_dev, fmt)) {
return -EIO;
}
Expand Down
8 changes: 0 additions & 8 deletions drivers/video/video_mcux_smartdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,6 @@ static int nxp_video_sdma_set_format(const struct device *dev, struct video_form
const struct nxp_video_sdma_config *config = dev->config;
int ret;

if (fmt == NULL) {
return -EINVAL;
}

if (!device_is_ready(config->sensor_dev)) {
LOG_ERR("Sensor device not ready");
return -ENODEV;
Expand Down Expand Up @@ -252,10 +248,6 @@ static int nxp_video_sdma_get_format(const struct device *dev, struct video_form
const struct nxp_video_sdma_config *config = dev->config;
int ret;

if (fmt == NULL) {
return -EINVAL;
}

if (!device_is_ready(config->sensor_dev)) {
LOG_ERR("Sensor device not ready");
return -ENODEV;
Expand Down
4 changes: 0 additions & 4 deletions drivers/video/video_stm32_dcmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,6 @@ static int video_stm32_dcmi_get_fmt(const struct device *dev, struct video_forma
const struct video_stm32_dcmi_config *config = dev->config;
int ret;

if (fmt == NULL) {
return -EINVAL;
}

/* Align DCMI format with the one provided by the sensor */
ret = video_get_format(config->sensor_dev, fmt);
if (ret < 0) {
Expand Down
4 changes: 0 additions & 4 deletions drivers/video/video_sw_generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,6 @@ static int video_sw_generator_set_frmival(const struct device *dev, struct video
{
struct video_sw_generator_data *data = dev->data;

if (frmival->denominator == 0 || frmival->numerator == 0) {
return -EINVAL;
}

data->frame_rate = CLAMP(DIV_ROUND_CLOSEST(frmival->denominator, frmival->numerator),
MIN_FRAME_RATE, MAX_FRAME_RATE);
frmival->numerator = 1;
Expand Down
Loading