mirror_zfs/include/os/linux/spl/sys
Richard Yao 2e7f664f04
Cleanup of dead code suggested by Clang Static Analyzer (#14380)
I recently gained the ability to run Clang's static analyzer on the
linux kernel modules via a few hacks. This extended coverage to code
that was previously missed since Clang's static analyzer only looked at
code that we built in userspace. Running it against the Linux kernel
modules built from my local branch produced a total of 72 reports
against my local branch. Of those, 50 were reports of logic errors and
22 were reports of dead code. Since we already had cleaned up all of
the previous dead code reports, I felt it would be a good next step to
clean up these dead code reports. Clang did a further breakdown of the
dead code reports into:

Dead assignment	15

Dead increment	2

Dead nested assignment	5

The benefit of cleaning these up, especially in the case of dead nested
assignment, is that they can expose places where our error handling is
incorrect. A number of them were fairly straight forward. However
several were not:

In vdev_disk_physio_completion(), not only were we not using the return
value from the static function vdev_disk_dio_put(), but nothing used it,
so I changed it to return void and removed the existing (void) cast in
the other area where we call it in addition to no longer storing it to a
stack value.

In FSE_createDTable(), the function is dead code. Its helper function
FSE_freeDTable() is also dead code, as are the CPP definitions in
`module/zstd/include/zstd_compat_wrapper.h`. We just delete it all.

In zfs_zevent_wait(), we have an optimization opportunity. cv_wait_sig()
returns 0 if there are waiting signals and 1 if there are none. The
Linux SPL version literally returns `signal_pending(current) ? 0 : 1)`
and FreeBSD implements the same semantics, we can just do
`!cv_wait_sig()` in place of `signal_pending(current)` to avoid
unnecessarily calling it again.

zfs_setattr() on FreeBSD version did not have error handling issue
because the code was removed entirely from FreeBSD version. The error is
from updating the attribute directory's files. After some thought, I
decided to propapage errors on it to userspace.

In zfs_secpolicy_tmp_snapshot(), we ignore a lack of permission from the
first check in favor of checking three other permissions. I assume this
is intentional.

In zfs_create_fs(), the return value of zap_update() was not checked
despite setting an important version number. I see no backward
compatibility reason to permit failures, so we add an assertion to catch
failures. Interestingly, Linux is still using ASSERT(error == 0) from
OpenSolaris while FreeBSD has switched to the improved ASSERT0(error)
from illumos, although illumos has yet to adopt it here. ASSERT(error ==
0) was used on Linux while ASSERT0(error) was used on FreeBSD since the
entire file needs conversion and that should be the subject of
another patch.

dnode_move()'s issue was caused by us not having implemented
POINTER_IS_VALID() on Linux. We have a stub in
`include/os/linux/spl/sys/kmem_cache.h` for it, when it really should be
in `include/os/linux/spl/sys/kmem.h` to be consistent with
Illumos/OpenSolaris. FreeBSD put both `POINTER_IS_VALID()` and
`POINTER_INVALIDATE()` in `include/os/freebsd/spl/sys/kmem.h`, so we
copy what it did.

Whenever a report was in platform-specific code, I checked the FreeBSD
version to see if it also applied to FreeBSD, but it was only relevant a
few times.

Lastly, the patch that enabled Clang's static analyzer to be run on the
Linux kernel modules needs more work before it can be put into a PR. I
plan to do that in the future as part of the on-going static analysis
work that I am doing.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14380
2023-01-17 09:57:12 -08:00
..
acl.h Clean up CSTYLEDs 2022-01-26 11:38:52 -08:00
atomic.h More aggsum optimizations 2021-06-07 09:02:47 -07:00
byteorder.h Reduce false positives from Static Analyzers 2022-09-30 15:30:12 -07:00
callb.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
callo.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
cmn_err.h Reduce false positives from Static Analyzers 2022-09-30 15:30:12 -07:00
condvar.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
cred.h Support idmapped mount in user namespace 2022-11-08 10:28:56 -08:00
ctype.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
debug.h debug: fix output from VERIFY0 assertion 2022-10-28 11:46:44 -07:00
disp.h Cleanup: Use OpenSolaris functions to call scheduler 2022-09-12 09:55:37 -07:00
dkio.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
errno.h Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
fcntl.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
file.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
inttypes.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
isa_defs.h linux isa_defs.h: Don't define _ALIGNMENT_REQUIRED 2022-11-03 09:39:51 -07:00
kmem_cache.h Cleanup of dead code suggested by Clang Static Analyzer (#14380) 2023-01-17 09:57:12 -08:00
kmem.h Cleanup of dead code suggested by Clang Static Analyzer (#14380) 2023-01-17 09:57:12 -08:00
kstat.h Cleanup: Switch to strlcpy from strncpy 2022-09-27 16:35:29 -07:00
list.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
misc.h zed: mark disks as REMOVED when they are removed 2022-09-28 09:48:46 -07:00
mod_os.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
mutex.h Clean up CSTYLEDs 2022-01-26 11:38:52 -08:00
param.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
proc.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
processor.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
procfs_list.h Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
random.h FreeBSD: fix compilation of FreeBSD world after 29274c9f6 2021-06-25 10:28:51 -07:00
rwlock.h Clean up CSTYLEDs 2022-01-26 11:38:52 -08:00
shrinker.h Linux 6.0 compat: register_shrinker() now var-arg 2022-08-08 16:18:30 -07:00
sid.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
signal.h Add SIGSTOP and SIGTSTP handling to issig 2021-04-15 13:34:35 -07:00
simd.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
stat.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
string.h Forbid b{copy,zero,cmp}(). Don't include <strings.h> for <string.h> 2022-03-15 15:13:48 -07:00
sunddi.h Remove hw_serial, ddi_strtoul() 2022-05-13 10:15:31 -07:00
sysmacros.h zfs_rename: support RENAME_* flags 2022-10-28 09:49:20 -07:00
systeminfo.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
taskq.h module: icp: remove other provider types 2022-02-15 16:23:53 -08:00
thread.h Switch from _Noreturn to __attribute__((noreturn)) 2022-03-23 08:51:00 -07:00
time.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
timer.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
trace_spl.h Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
trace_taskq.h Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
trace.h Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
tsd.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
types32.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
types.h Support idmapped mount 2022-10-19 11:17:09 -07:00
uio.h zvol: Support blk-mq for better performance 2022-06-09 08:10:38 -06:00
user.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
vfs.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
vmem.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
vmsystm.h Add membar_sync 2022-09-20 15:32:44 -07:00
vnode.h Consolidate zfs_holey and zfs_access 2020-10-31 09:40:08 -07:00
wait.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
wmsum.h Introduce write-mostly sums 2021-05-27 14:27:29 -06:00
zmod.h Replace ZFS on Linux references with OpenZFS 2020-10-08 20:10:13 -07:00
zone.h Add Linux namespace delegation support 2022-06-10 09:51:46 -07:00