Skip to content

Commit

Permalink
media: i2c: ov5647: Add checks for link frequency
Browse files Browse the repository at this point in the history
Added validation for the `link-frequency` property in the driver. The new checks ensure that:
- The link-frequency property is present in the device tree
- The number of link frequencies matches the ov5647_link_freqs array size
- The link frequencies in the device tree match the supported values in ov5647_link_freqs array

These checks help avoid misconfigurations and prevent runtime errors due to incorrect declarations

Signed-off-by: Dominik Bajec <[email protected]>
  • Loading branch information
Bajec committed Oct 22, 2024
1 parent 68d0631 commit 25c0edc
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions drivers/media/i2c/ov5647.c
Original file line number Diff line number Diff line change
Expand Up @@ -1352,13 +1352,15 @@ static int ov5647_init_controls(struct ov5647 *sensor, struct device *dev)
return sensor->ctrls.error;
}

static int ov5647_parse_dt(struct ov5647 *sensor, struct device_node *np)
static int ov5647_parse_dt(struct device *dev,
struct ov5647 *sensor,
struct device_node *np)
{
struct v4l2_fwnode_endpoint bus_cfg = {
.bus_type = V4L2_MBUS_CSI2_DPHY,
};
struct device_node *ep;
int ret;
int ret = -EINVAL;

ep = of_graph_get_next_endpoint(np, NULL);
if (!ep)
Expand All @@ -1371,6 +1373,23 @@ static int ov5647_parse_dt(struct ov5647 *sensor, struct device_node *np)
sensor->clock_ncont = bus_cfg.bus.mipi_csi2.flags &
V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK;

if (!bus_cfg.nr_of_link_frequencies) {
dev_err(dev, "link-frequency property not found in DT\n");
goto out;
}

if (bus_cfg.nr_of_link_frequencies != ARRAY_SIZE(ov5647_link_freqs)) {
dev_err(dev, "Link frequency missing in dtree\n");
goto out;
}

for (int i = 0; i < ARRAY_SIZE(ov5647_link_freqs); i++) {
if(bus_cfg.link_frequencies[i] != ov5647_link_freqs[i]){

Check failure on line 1387 in drivers/media/i2c/ov5647.c

View workflow job for this annotation

GitHub Actions / checkpatch review

ERROR: space required before the open brace '{'

Check failure on line 1387 in drivers/media/i2c/ov5647.c

View workflow job for this annotation

GitHub Actions / checkpatch review

ERROR: space required before the open parenthesis '('
dev_err(dev, "no supported link frequency found\n");
goto out;

Check failure on line 1389 in drivers/media/i2c/ov5647.c

View workflow job for this annotation

GitHub Actions / checkpatch review

ERROR: trailing whitespace
}
}

out:
of_node_put(ep);

Expand All @@ -1391,7 +1410,7 @@ static int ov5647_probe(struct i2c_client *client)
return -ENOMEM;

if (IS_ENABLED(CONFIG_OF) && np) {
ret = ov5647_parse_dt(sensor, np);
ret = ov5647_parse_dt(dev, sensor, np);
if (ret) {
dev_err(dev, "DT parsing error: %d\n", ret);
return ret;
Expand Down

0 comments on commit 25c0edc

Please sign in to comment.