-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
drivers: video: gc2145: Include set_resolution() in the format caps check #78731
drivers: video: gc2145: Include set_resolution() in the format caps check #78731
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, it is perfectly reasonable grouping the I/O operations only after making sure the the format is supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK, though if you are up for another round... in Zephyr usually failures are handled in the if
s, and the function returns at the end if everything is OK. You could refactor set_fmt
so that if it does not find a match it returns an error.
@pillo79 ,
@pillo79 , most of these drivers were written and their logic got oversight after merging, is there a proposal of refactoring them to make them consistent of the Zephyr standard, I have backlog here that I plan to start once I finish my work with the Arduino Nicla, and refactor one driver by one. |
Sure, that's great and that's why I approved in the first place 🙂 |
Kind of, maybe the first step is to agree on a "ideal format". I was tempted to start with the GC2145 as it got a review round directly from a TSC member here: The first sensors were contributed a long time ago, and it is good practice to pick existing drivers to write new ones. |
While applying the format, the pixel format and drv_data->fmt were set immediately, and the resolution was set only if it had a matching entry on the "caps". This commit makes sure the requested format matches the caps before applying the format as well as drv_data->fmt. This does not guards against partial failure (i.e. only pixelformat set and not resolution). Signed-off-by: Josuah Demangeon <[email protected]>
After the error code is checked to be zero, it is possible to return 0 explicitly to help with readability. Also, when available, forward the return code from the failing function instead of a locally chosen error code like -EIO. Signed-off-by: Josuah Demangeon <[email protected]>
207952e
to
f2745c9
Compare
f2745c9
to
08e7097
Compare
Force push: the new driver passes the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK - though the new for
is quirky 🙂
Up to you if you wish to amend with something like my comment.
drivers/video/gc2145.c
Outdated
for (int i = 0;; i++) { | ||
if (i == ARRAY_SIZE(fmts)) { | ||
LOG_ERR("Image format not supported\n"); | ||
return -ENOTSUP; | ||
} | ||
if (fmts[i].width_min == fmt->width && fmts[i].height_min == fmt->height && | ||
fmts[i].pixelformat == fmt->pixelformat) { | ||
res = (enum resolutions)i; | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think a more common way to write this would be:
enum resolutions res = RESOLUTIONS_MAX;
for (int i = 0; i < ARRAY_SIZE(fmts); i++) {
if (fmts[i].width_min == fmt->width && fmts[i].height_min == fmt->height &&
fmts[i].pixelformat == fmt->pixelformat) {
res = (enum resolutions)i;
break;
}
}
if (res == RESOLUTIONS_MAX) {
LOG_ERR("Image format not supported\n");
return -ENOTSUP;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then there is the more obvious for (i = 0; i < N; i++)
idiom standing out.
I appreciate the teachings. :)
08e7097
to
e193133
Compare
This aims to make the code more linear by having the for loop validates the input format rather than search for a match. Signed-off-by: Josuah Demangeon <[email protected]>
e193133
to
ea5086f
Compare
The current GalxyCore GC2145 does not guard against a wrong pixelformat passed.
This usually never happens and might be caught by the
gc2145_set_output_format()
anyway, but this permits to only setdrv_data->fmt
if the format is valid.A very minor change!