Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

apparmor: Use true and false for bool variable

Fixes coccicheck warnings:

security/apparmor/file.c:162:9-10: WARNING: return of 0/1 in function 'is_deleted' with return type bool
security/apparmor/file.c:362:9-10: WARNING: return of 0/1 in function 'xindex_is_subset' with return type bool
security/apparmor/policy_unpack.c:246:9-10: WARNING: return of 0/1 in function 'unpack_X' with return type bool
security/apparmor/policy_unpack.c:292:9-10: WARNING: return of 0/1 in function 'unpack_nameX' with return type bool
security/apparmor/policy_unpack.c:646:8-9: WARNING: return of 0/1 in function 'unpack_rlimits' with return type bool
security/apparmor/policy_unpack.c:604:8-9: WARNING: return of 0/1 in function 'unpack_secmark' with return type bool
security/apparmor/policy_unpack.c:538:8-9: WARNING: return of 0/1 in function 'unpack_trans_table' with return type bool
security/apparmor/policy_unpack.c:327:9-10: WARNING: return of 0/1 in function 'unpack_u32' with return type bool
security/apparmor/policy_unpack.c:345:9-10: WARNING: return of 0/1 in function 'unpack_u64' with return type bool
security/apparmor/policy_unpack.c:309:9-10: WARNING: return of 0/1 in function 'unpack_u8' with return type bool
security/apparmor/policy_unpack.c:568:8-9: WARNING: return of 0/1 in function 'unpack_xattrs' with return type bool
security/apparmor/policy_unpack.c:1007:10-11: WARNING: return of 0/1 in function 'verify_dfa_xindex' with return type bool
security/apparmor/policy_unpack.c:997:9-10: WARNING: return of 0/1 in function 'verify_xindex' with return type bool

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>

authored by

Zou Wei and committed by
John Johansen
e3798609 c84b80cd

+33 -33
+6 -6
security/apparmor/file.c
··· 154 154 * is_deleted - test if a file has been completely unlinked 155 155 * @dentry: dentry of file to test for deletion (NOT NULL) 156 156 * 157 - * Returns: %1 if deleted else %0 157 + * Returns: true if deleted else false 158 158 */ 159 159 static inline bool is_deleted(struct dentry *dentry) 160 160 { 161 161 if (d_unlinked(dentry) && d_backing_inode(dentry)->i_nlink == 0) 162 - return 1; 163 - return 0; 162 + return true; 163 + return false; 164 164 } 165 165 166 166 static int path_name(const char *op, struct aa_label *label, ··· 353 353 * this is done as part of the subset test, where a hardlink must have 354 354 * a subset of permissions that the target has. 355 355 * 356 - * Returns: %1 if subset else %0 356 + * Returns: true if subset else false 357 357 */ 358 358 static inline bool xindex_is_subset(u32 link, u32 target) 359 359 { 360 360 if (((link & ~AA_X_UNSAFE) != (target & ~AA_X_UNSAFE)) || 361 361 ((link & AA_X_UNSAFE) && !(target & AA_X_UNSAFE))) 362 - return 0; 362 + return false; 363 363 364 - return 1; 364 + return true; 365 365 } 366 366 367 367 static int profile_path_link(struct aa_profile *profile,
+27 -27
security/apparmor/policy_unpack.c
··· 243 243 static bool unpack_X(struct aa_ext *e, enum aa_code code) 244 244 { 245 245 if (!inbounds(e, 1)) 246 - return 0; 246 + return false; 247 247 if (*(u8 *) e->pos != code) 248 - return 0; 248 + return false; 249 249 e->pos++; 250 - return 1; 250 + return true; 251 251 } 252 252 253 253 /** ··· 261 261 * name element in the stream. If @name is NULL any name element will be 262 262 * skipped and only the typecode will be tested. 263 263 * 264 - * Returns 1 on success (both type code and name tests match) and the read 264 + * Returns true on success (both type code and name tests match) and the read 265 265 * head is advanced past the headers 266 266 * 267 - * Returns: 0 if either match fails, the read head does not move 267 + * Returns: false if either match fails, the read head does not move 268 268 */ 269 269 static bool unpack_nameX(struct aa_ext *e, enum aa_code code, const char *name) 270 270 { ··· 289 289 290 290 /* now check if type code matches */ 291 291 if (unpack_X(e, code)) 292 - return 1; 292 + return true; 293 293 294 294 fail: 295 295 e->pos = pos; 296 - return 0; 296 + return false; 297 297 } 298 298 299 299 static bool unpack_u8(struct aa_ext *e, u8 *data, const char *name) ··· 306 306 if (data) 307 307 *data = get_unaligned((u8 *)e->pos); 308 308 e->pos += sizeof(u8); 309 - return 1; 309 + return true; 310 310 } 311 311 312 312 fail: 313 313 e->pos = pos; 314 - return 0; 314 + return false; 315 315 } 316 316 317 317 static bool unpack_u32(struct aa_ext *e, u32 *data, const char *name) ··· 324 324 if (data) 325 325 *data = le32_to_cpu(get_unaligned((__le32 *) e->pos)); 326 326 e->pos += sizeof(u32); 327 - return 1; 327 + return true; 328 328 } 329 329 330 330 fail: 331 331 e->pos = pos; 332 - return 0; 332 + return false; 333 333 } 334 334 335 335 static bool unpack_u64(struct aa_ext *e, u64 *data, const char *name) ··· 342 342 if (data) 343 343 *data = le64_to_cpu(get_unaligned((__le64 *) e->pos)); 344 344 e->pos += sizeof(u64); 345 - return 1; 345 + return true; 346 346 } 347 347 348 348 fail: 349 349 e->pos = pos; 350 - return 0; 350 + return false; 351 351 } 352 352 353 353 static size_t unpack_array(struct aa_ext *e, const char *name) ··· 472 472 * @e: serialized data extent information (NOT NULL) 473 473 * @profile: profile to add the accept table to (NOT NULL) 474 474 * 475 - * Returns: 1 if table successfully unpacked 475 + * Returns: true if table successfully unpacked 476 476 */ 477 477 static bool unpack_trans_table(struct aa_ext *e, struct aa_profile *profile) 478 478 { ··· 535 535 if (!unpack_nameX(e, AA_STRUCTEND, NULL)) 536 536 goto fail; 537 537 } 538 - return 1; 538 + return true; 539 539 540 540 fail: 541 541 aa_free_domain_entries(&profile->file.trans); 542 542 e->pos = saved_pos; 543 - return 0; 543 + return false; 544 544 } 545 545 546 546 static bool unpack_xattrs(struct aa_ext *e, struct aa_profile *profile) ··· 565 565 goto fail; 566 566 } 567 567 568 - return 1; 568 + return true; 569 569 570 570 fail: 571 571 e->pos = pos; 572 - return 0; 572 + return false; 573 573 } 574 574 575 575 static bool unpack_secmark(struct aa_ext *e, struct aa_profile *profile) ··· 601 601 goto fail; 602 602 } 603 603 604 - return 1; 604 + return true; 605 605 606 606 fail: 607 607 if (profile->secmark) { ··· 613 613 } 614 614 615 615 e->pos = pos; 616 - return 0; 616 + return false; 617 617 } 618 618 619 619 static bool unpack_rlimits(struct aa_ext *e, struct aa_profile *profile) ··· 643 643 if (!unpack_nameX(e, AA_STRUCTEND, NULL)) 644 644 goto fail; 645 645 } 646 - return 1; 646 + return true; 647 647 648 648 fail: 649 649 e->pos = pos; 650 - return 0; 650 + return false; 651 651 } 652 652 653 653 static u32 strhash(const void *data, u32 len, u32 seed) ··· 994 994 xtype = xindex & AA_X_TYPE_MASK; 995 995 index = xindex & AA_X_INDEX_MASK; 996 996 if (xtype == AA_X_TABLE && index >= table_size) 997 - return 0; 998 - return 1; 997 + return false; 998 + return true; 999 999 } 1000 1000 1001 1001 /* verify dfa xindexes are in range of transition tables */ ··· 1004 1004 int i; 1005 1005 for (i = 0; i < dfa->tables[YYTD_ID_ACCEPT]->td_lolen; i++) { 1006 1006 if (!verify_xindex(dfa_user_xindex(dfa, i), table_size)) 1007 - return 0; 1007 + return false; 1008 1008 if (!verify_xindex(dfa_other_xindex(dfa, i), table_size)) 1009 - return 0; 1009 + return false; 1010 1010 } 1011 - return 1; 1011 + return true; 1012 1012 } 1013 1013 1014 1014 /**