Lines Matching defs:state

31 	struct netlink_policy_dump_state *state = *statep;
37 for (i = 0; i < state->n_alloc; i++) {
38 if (state->policies[i].policy == policy &&
39 state->policies[i].maxtype == maxtype)
42 if (!state->policies[i].policy) {
43 state->policies[i].policy = policy;
44 state->policies[i].maxtype = maxtype;
49 n_alloc = state->n_alloc + INITIAL_POLICIES_ALLOC;
50 state = krealloc(state, struct_size(state, policies, n_alloc),
52 if (!state)
55 memset(&state->policies[state->n_alloc], 0,
56 flex_array_size(state, policies, n_alloc - state->n_alloc));
58 state->policies[state->n_alloc].policy = policy;
59 state->policies[state->n_alloc].maxtype = maxtype;
60 state->n_alloc = n_alloc;
61 *statep = state;
68 * @state: the policy dump state
72 * Returns: the index of the given policy in the dump state
81 int netlink_policy_dump_get_policy_idx(struct netlink_policy_dump_state *state,
90 for (i = 0; i < state->n_alloc; i++) {
91 if (state->policies[i].policy == policy &&
92 state->policies[i].maxtype == maxtype)
102 struct netlink_policy_dump_state *state;
104 state = kzalloc(struct_size(state, policies, INITIAL_POLICIES_ALLOC),
106 if (!state)
108 state->n_alloc = INITIAL_POLICIES_ALLOC;
110 return state;
115 * @pstate: state to add to, may be reallocated, must be %NULL the first time
121 * Call this to allocate a policy dump state, and to add policies to it. This
124 * Note: on failures, any previously allocated state is freed.
130 struct netlink_policy_dump_state *state = *pstate;
134 if (!state) {
135 state = alloc_state();
136 if (IS_ERR(state))
137 return PTR_ERR(state);
145 err = add_policy(&state, policy, maxtype);
150 policy_idx < state->n_alloc && state->policies[policy_idx].policy;
155 policy = state->policies[policy_idx].policy;
158 type <= state->policies[policy_idx].maxtype;
163 err = add_policy(&state,
175 *pstate = state;
183 netlink_policy_dump_free(state);
185 *pstate = state;
190 netlink_policy_dump_finished(struct netlink_policy_dump_state *state)
192 return state->policy_idx >= state->n_alloc ||
193 !state->policies[state->policy_idx].policy;
198 * @state: the policy dump state
202 * Note: this frees the dump state when finishing
204 bool netlink_policy_dump_loop(struct netlink_policy_dump_state *state)
206 return !netlink_policy_dump_finished(state);
251 __netlink_policy_dump_write_attr(struct netlink_policy_dump_state *state,
277 if (state && pt->nested_policy && pt->len &&
279 netlink_policy_dump_get_policy_idx(state,
417 * @state: the policy dump state
422 struct netlink_policy_dump_state *state)
432 pt = &state->policies[state->policy_idx].policy[state->attr_idx];
434 policy = nla_nest_start(skb, state->policy_idx);
438 err = __netlink_policy_dump_write_attr(state, skb, pt, state->attr_idx);
447 /* finish and move state to next attribute */
451 state->attr_idx += 1;
452 if (state->attr_idx > state->policies[state->policy_idx].maxtype) {
453 state->attr_idx = 0;
454 state->policy_idx++;
458 if (netlink_policy_dump_finished(state))
471 * netlink_policy_dump_free - free policy dump state
472 * @state: the policy dump state to free
474 * Call this from the done() method to ensure dump state is freed.
476 void netlink_policy_dump_free(struct netlink_policy_dump_state *state)
478 kfree(state);