syscommon_resman_set_resource_control(int resource_id, u_int64_t ctrl_id, const void *data)
{
const struct syscommon_resman_resource_control *ctrl;
- int ctrl_index = RESOURCE_CTRL_INDEX(ctrl_id);
+ int ctrl_index;
int ret;
- struct syscommon_resman_resource *resource = find_resource(resource_id);
+ struct syscommon_resman_resource *resource;
+
+ if (ctrl_id == 0)
+ return -EINVAL;
- if (!resource || ctrl_index < 0 || ctrl_index >= resource->num_ctrls)
+ resource = find_resource(resource_id);
+ if (!resource)
+ return -EINVAL;
+
+ ctrl_index = RESOURCE_CTRL_INDEX(ctrl_id);
+ if (ctrl_index >= resource->num_ctrls)
return -EINVAL;
ctrl = &resource->ctrls[ctrl_index];
syscommon_resman_get_resource_control_name(int resource_id, u_int64_t ctrl_id)
{
const struct syscommon_resman_resource_control *ctrl;
- int ctrl_index = RESOURCE_CTRL_INDEX(ctrl_id);
- struct syscommon_resman_resource *resource = find_resource(resource_id);
+ int ctrl_index;
+ struct syscommon_resman_resource *resource;
- if (!resource || ctrl_index < 0 || ctrl_index >= resource->num_ctrls)
+ if (ctrl_id == 0)
+ return NULL;
+
+ resource = find_resource(resource_id);
+ if (!resource)
+ return NULL;
+
+ ctrl_index = RESOURCE_CTRL_INDEX(ctrl_id);
+ if (ctrl_index >= resource->num_ctrls)
return NULL;
ctrl = &resource->ctrls[ctrl_index];
static int
update_resource_attr(struct syscommon_resman_resource *resource, u_int64_t attr_id)
{
- int attr_index = RESOURCE_ATTR_INDEX(attr_id);
+ int attr_index;
const struct syscommon_resman_resource_attribute *attr = NULL;
struct syscommon_resman_resource_attribute_value *attr_value = NULL;
int ret;
- if (!resource || attr_index < 0 || attr_index >= resource->num_attrs)
+ if (!resource || attr_id == 0)
+ return -EINVAL;
+
+ attr_index = RESOURCE_ATTR_INDEX(attr_id);
+ if (attr_index >= resource->num_attrs)
return -EINVAL;
attr = &resource->attrs[attr_index];
static int
monitor_update_resource_attr(struct syscommon_resman_resource *resource, u_int64_t attr_id)
{
- int attr_index = RESOURCE_ATTR_INDEX(attr_id);
+ int attr_index;
const struct syscommon_resman_resource_attribute *attr = NULL;
struct syscommon_resman_resource_attribute_value *attr_value = NULL;
int ret;
- if (!resource || attr_index < 0 || attr_index >= resource->num_attrs)
+ if (!resource || attr_id == 0)
+ return -EINVAL;
+
+ attr_index = RESOURCE_ATTR_INDEX(attr_id);
+ if (attr_index >= resource->num_attrs)
return -EINVAL;
attr = &resource->attrs[attr_index];
static const struct syscommon_resman_resource_attribute *
get_resource_attr(struct syscommon_resman_resource *resource, u_int64_t attr_id)
{
- int attr_index = RESOURCE_ATTR_INDEX(attr_id);
+ int attr_index;
+
+ if (!resource || attr_id == 0)
+ return NULL;
- if (!resource || attr_index < 0 || attr_index >= resource->num_attrs)
+ attr_index = RESOURCE_ATTR_INDEX(attr_id);
+ if (attr_index >= resource->num_attrs)
return NULL;
return &resource->attrs[attr_index];
return get_resource_attr(resource, attr_id);
}
-
static struct syscommon_resman_resource_attribute_value *
get_resource_attr_value(struct syscommon_resman_resource *resource, u_int64_t attr_id)
{
- int attr_index = RESOURCE_ATTR_INDEX(attr_id);
+ int attr_index;
+
+ if (!resource || attr_id == 0)
+ return NULL;
- if (!resource || attr_index < 0 || attr_index >= resource->num_attrs)
+ attr_index = RESOURCE_ATTR_INDEX(attr_id);
+ if (attr_index >= resource->num_attrs)
return NULL;
return &resource->attrs_value[attr_index];
static int is_resource_attr_supported(struct syscommon_resman_resource *resource, u_int64_t attr_id, bool *supported)
{
const struct syscommon_resman_resource_attribute *attr = NULL;
- int attr_index = RESOURCE_ATTR_INDEX(attr_id);
+ int attr_index;
int ret;
bool is_supported = false;
struct attribute_is_supported_ops ops = { 0 , };
- if (!resource || attr_index < 0 || attr_index >= resource->num_attrs) {
+ if (!supported)
+ return -EINVAL;
+
+ if (!resource || attr_id == 0) {
+ *supported = false;
+ return -EINVAL;
+ }
+
+ attr_index = RESOURCE_ATTR_INDEX(attr_id);
+ if (attr_index >= resource->num_attrs) {
*supported = false;
return -EINVAL;
}