*: rely on checks now done by spa_pod_get_values()

Rely on spa_pod_get_values() to return no values if the size is too
small for the type.  This means that if there is a check that at least
one value is returned, checking that the size is large enough is
unnecessary.
This commit is contained in:
Demi Marie Obenour 2025-07-25 16:54:20 -04:00
parent 42098fd8c1
commit 5853e1150b
5 changed files with 7 additions and 13 deletions

View file

@ -2255,7 +2255,7 @@ static int vidioc_queryctrl(struct file *file, struct v4l2_queryctrl *arg)
// check type and populate range // check type and populate range
pod = spa_pod_get_values(type, &n_vals, &choice); pod = spa_pod_get_values(type, &n_vals, &choice);
if (spa_pod_is_int(pod)) { if (pod->type == SPA_TYPE_Int) {
if (n_vals < 4) if (n_vals < 4)
break; break;
arg->type = V4L2_CTRL_TYPE_INTEGER; arg->type = V4L2_CTRL_TYPE_INTEGER;
@ -2330,7 +2330,7 @@ static int vidioc_g_ctrl(struct file *file, struct v4l2_control *arg)
if (ctrl_id == arg->id) { if (ctrl_id == arg->id) {
// TODO: support getting true ctrl values instead of defaults // TODO: support getting true ctrl values instead of defaults
pod = spa_pod_get_values(type, &n_vals, &choice); pod = spa_pod_get_values(type, &n_vals, &choice);
if (spa_pod_is_int(pod)) { if (pod->type == SPA_TYPE_Int) {
if (n_vals < 4) if (n_vals < 4)
break; break;
int *v = SPA_POD_BODY(pod); int *v = SPA_POD_BODY(pod);

View file

@ -164,8 +164,7 @@ SPA_API_DEBUG_FORMAT int spa_debugc_format(struct spa_debug_context *ctx, int in
type = val->type; type = val->type;
size = val->size; size = val->size;
if (type < SPA_TYPE_None || type >= _SPA_TYPE_LAST || n_vals < 1 || if (type < SPA_TYPE_None || type >= _SPA_TYPE_LAST || n_vals < 1)
size < spa_pod_type_size(type))
continue; continue;
vals = SPA_POD_BODY(val); vals = SPA_POD_BODY(val);

View file

@ -82,7 +82,7 @@ spa_pod_filter_prop(struct spa_pod_builder *b,
v1 = spa_pod_get_values(&p1->value, &nalt1, &p1c); v1 = spa_pod_get_values(&p1->value, &nalt1, &p1c);
v2 = spa_pod_get_values(&p2->value, &nalt2, &p2c); v2 = spa_pod_get_values(&p2->value, &nalt2, &p2c);
/* empty choices */ /* empty or bogus choices */
if (nalt1 < 1 || nalt2 < 1) if (nalt1 < 1 || nalt2 < 1)
return -EINVAL; return -EINVAL;
@ -95,8 +95,6 @@ spa_pod_filter_prop(struct spa_pod_builder *b,
/* incompatible property types */ /* incompatible property types */
if (type != v2->type || size != v2->size || p1->key != p2->key) if (type != v2->type || size != v2->size || p1->key != p2->key)
return -EINVAL; return -EINVAL;
if (size < spa_pod_type_size(type))
return -EINVAL;
/* start with copying the property */ /* start with copying the property */
spa_pod_builder_prop(b, p1->key, p1->flags & p2->flags); spa_pod_builder_prop(b, p1->key, p1->flags & p2->flags);
@ -405,7 +403,7 @@ SPA_API_POD_FILTER int spa_pod_filter_object_make(struct spa_pod_object *pod)
struct spa_pod *v = spa_pod_get_values(&res->value, &nvals, &choice); struct spa_pod *v = spa_pod_get_values(&res->value, &nvals, &choice);
const void *vals = SPA_POD_BODY(v); const void *vals = SPA_POD_BODY(v);
if (v->size < spa_pod_type_size(v->type)) if (nvals < 1)
continue; continue;
if (spa_pod_compare_is_valid_choice(v->type, v->size, if (spa_pod_compare_is_valid_choice(v->type, v->size,

View file

@ -1209,10 +1209,7 @@ static struct spa_pod *transform_format(struct impl *this, struct port *port, co
uint32_t n_vals, choice, *id_vals; uint32_t n_vals, choice, *id_vals;
struct spa_pod *val = spa_pod_get_values(&prop->value, &n_vals, &choice); struct spa_pod *val = spa_pod_get_values(&prop->value, &n_vals, &choice);
if (n_vals < 1) if (n_vals < 1 || val->type != SPA_TYPE_Id)
return 0;
if (!spa_pod_is_id(val))
return 0; return 0;
id_vals = SPA_POD_BODY(val); id_vals = SPA_POD_BODY(val);

View file

@ -683,7 +683,7 @@ static int add_int(struct format_info *info, const char *k, struct spa_pod *para
return -ENOENT; return -ENOENT;
val = spa_pod_get_values(&prop->value, &n_values, &choice); val = spa_pod_get_values(&prop->value, &n_values, &choice);
if (!spa_pod_is_int(val)) if (val->type != SPA_TYPE_Int)
return -ENOTSUP; return -ENOTSUP;
if (n_values == 0) if (n_values == 0)