HomeFreeBSD

Cleanup: !A || A && B is equivalent to !A || B

Description

Cleanup: !A || A && B is equivalent to !A || B

In zfs_zaccess_dataset_check(), we have the following subexpression:

(!IS_DEVVP(ZTOV(zp)) ||

(IS_DEVVP(ZTOV(zp)) && (v4_mode & WRITE_MASK_ATTRS)))

When !IS_DEVVP(ZTOV(zp)) is false, IS_DEVVP(ZTOV(zp)) is true under the
law of the excluded middle since we are not doing pseudoboolean alegbra.
Therefore doing:

(IS_DEVVP(ZTOV(zp)) && (v4_mode & WRITE_MASK_ATTRS))

Is unnecessary and we can just do:

(v4_mode & WRITE_MASK_ATTRS)

The Linux 5.16.14 kernel's coccicheck caught this. The semantic
patch that caught it was:

./scripts/coccinelle/misc/excluded_middle.cocci

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14372

Details

Provenance
Richard Yao <richard.yao@alumni.stonybrook.edu>Authored on Jan 10 2023, 9:34 PM
Brian Behlendorf <behlendorf1@llnl.gov>Committed on Jan 13 2023, 12:00 AM
Parents
rG9c8fabffa2b1: Cleanup: Replace oldstyle struct hack with C99 flexible array members
Branches
Unknown
Tags
Unknown

Event Timeline

Brian Behlendorf <behlendorf1@llnl.gov> committed rGe6328fda2e5c: Cleanup: !A || A && B is equivalent to !A || B (authored by Richard Yao <richard.yao@alumni.stonybrook.edu>).Jan 13 2023, 12:00 AM