[ammarfaizi2-block:google/android/kernel/common/android-4.14-stable 241/9999] kernel/bpf/cgroup.c:195:6: warning: variable 'old_flags' set but not used

From: kernel test robot
Date: Thu Mar 10 2022 - 12:16:23 EST


tree: https://github.com/ammarfaizi2/linux-block google/android/kernel/common/android-4.14-stable
head: cb5d0103b1f8fc3aa997a696472fd774c67a1b1f
commit: 9e61c87b1f47b4dc3d48de83d85e9f17c320f91e [241/9999] UPSTREAM: bpf: multi program support for cgroup+bpf
config: i386-randconfig-a012 (https://download.01.org/0day-ci/archive/20220311/202203110118.cEBHu9dR-lkp@xxxxxxxxx/config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce (this is a W=1 build):
# https://github.com/ammarfaizi2/linux-block/commit/9e61c87b1f47b4dc3d48de83d85e9f17c320f91e
git remote add ammarfaizi2-block https://github.com/ammarfaizi2/linux-block
git fetch --no-tags ammarfaizi2-block google/android/kernel/common/android-4.14-stable
git checkout 9e61c87b1f47b4dc3d48de83d85e9f17c320f91e
# save the config file to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash kernel/bpf/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>

All warnings (new ones prefixed by >>):

kernel/bpf/cgroup.c: In function '__cgroup_bpf_attach':
>> kernel/bpf/cgroup.c:195:6: warning: variable 'old_flags' set but not used [-Wunused-but-set-variable]
u32 old_flags;
^~~~~~~~~


vim +/old_flags +195 kernel/bpf/cgroup.c

177
178 /**
179 * __cgroup_bpf_attach() - Attach the program to a cgroup, and
180 * propagate the change to descendants
181 * @cgrp: The cgroup which descendants to traverse
182 * @prog: A program to attach
183 * @type: Type of attach operation
184 *
185 * Must be called with cgroup_mutex held.
186 */
187 int __cgroup_bpf_attach(struct cgroup *cgrp, struct bpf_prog *prog,
188 enum bpf_attach_type type, u32 flags)
189 {
190 struct list_head *progs = &cgrp->bpf.progs[type];
191 struct bpf_prog *old_prog = NULL;
192 struct cgroup_subsys_state *css;
193 struct bpf_prog_list *pl;
194 bool pl_was_allocated;
> 195 u32 old_flags;
196 int err;
197
198 if ((flags & BPF_F_ALLOW_OVERRIDE) && (flags & BPF_F_ALLOW_MULTI))
199 /* invalid combination */
200 return -EINVAL;
201
202 if (!hierarchy_allows_attach(cgrp, type, flags))
203 return -EPERM;
204
205 if (!list_empty(progs) && cgrp->bpf.flags[type] != flags)
206 /* Disallow attaching non-overridable on top
207 * of existing overridable in this cgroup.
208 * Disallow attaching multi-prog if overridable or none
209 */
210 return -EPERM;
211
212 if (prog_list_length(progs) >= BPF_CGROUP_MAX_PROGS)
213 return -E2BIG;
214
215 if (flags & BPF_F_ALLOW_MULTI) {
216 list_for_each_entry(pl, progs, node)
217 if (pl->prog == prog)
218 /* disallow attaching the same prog twice */
219 return -EINVAL;
220
221 pl = kmalloc(sizeof(*pl), GFP_KERNEL);
222 if (!pl)
223 return -ENOMEM;
224 pl_was_allocated = true;
225 pl->prog = prog;
226 list_add_tail(&pl->node, progs);
227 } else {
228 if (list_empty(progs)) {
229 pl = kmalloc(sizeof(*pl), GFP_KERNEL);
230 if (!pl)
231 return -ENOMEM;
232 pl_was_allocated = true;
233 list_add_tail(&pl->node, progs);
234 } else {
235 pl = list_first_entry(progs, typeof(*pl), node);
236 old_prog = pl->prog;
237 pl_was_allocated = false;
238 }
239 pl->prog = prog;
240 }
241
242 old_flags = cgrp->bpf.flags[type];
243 cgrp->bpf.flags[type] = flags;
244
245 /* allocate and recompute effective prog arrays */
246 css_for_each_descendant_pre(css, &cgrp->self) {
247 struct cgroup *desc = container_of(css, struct cgroup, self);
248
249 err = compute_effective_progs(desc, type, &desc->bpf.inactive);
250 if (err)
251 goto cleanup;
252 }
253
254 /* all allocations were successful. Activate all prog arrays */
255 css_for_each_descendant_pre(css, &cgrp->self) {
256 struct cgroup *desc = container_of(css, struct cgroup, self);
257
258 activate_effective_progs(desc, type, desc->bpf.inactive);
259 desc->bpf.inactive = NULL;
260 }
261
262 static_branch_inc(&cgroup_bpf_enabled_key);
263 if (old_prog) {
264 bpf_prog_put(old_prog);
265 static_branch_dec(&cgroup_bpf_enabled_key);
266 }
267 return 0;
268
269 cleanup:
270 /* oom while computing effective. Free all computed effective arrays
271 * since they were not activated
272 */
273 css_for_each_descendant_pre(css, &cgrp->self) {
274 struct cgroup *desc = container_of(css, struct cgroup, self);
275
276 bpf_prog_array_free(desc->bpf.inactive);
277 desc->bpf.inactive = NULL;
278 }
279
280 /* and cleanup the prog list */
281 pl->prog = old_prog;
282 if (pl_was_allocated) {
283 list_del(&pl->node);
284 kfree(pl);
285 }
286 return err;
287 }
288

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx