# By Daniel Rosenberg (98) and others
# Via Greg Kroah-Hartman (219) and others
* google/common/android-4.4-p:
ANDROID: xt_qtaguid: fix UAF race
ANDROID: Make vsock virtio packet buff size configurable
ANDROID: cuttlefish_defconfig: add missing CONFIG_BLK_CGROUP
ANDROID: xt_qtaguid: Remove tag_entry from process list on untag
ANDROID: usb: f_accessory: Don't drop NULL reference in acc_disconnect()
ANDROID: usb: f_accessory: Avoid bitfields for shared variables
ANDROID: usb: f_accessory: Cancel any pending work before teardown
ANDROID: usb: f_accessory: Don't corrupt global state on double registration
ANDROID: usb: f_accessory: Fix teardown ordering in acc_release()
ANDROID: usb: f_accessory: Add refcounting to global 'acc_dev'
UPSTREAM: locking/atomic, kref: Add KREF_INIT()
ANDROID: usb: f_accessory: Wrap '_acc_dev' in get()/put() accessors
ANDROID: usb: f_accessory: Remove useless assignment
ANDROID: usb: f_accessory: Remove useless non-debug prints
ANDROID: usb: f_accessory: Remove stale comments
ANDROID: USB: f_accessory: Check dev pointer before decoding ctrl request
ANDROID: usb: gadget: f_accessory: fix CTS test stuck
ANDROID: cuttlefish_defconfig: Disable CONFIG_KSM
UPSTREAM: arm64: SW PAN: Point saved ttbr0 at the zero page when switching to init_mm
UPSTREAM: arm64: kaslr: Fix up the kernel image alignment
UPSTREAM: sched/fair: Fix FTQ noise bench regression
UPSTREAM: dm verity fec: fix bufio leaks
UPSTREAM: arm64: kernel: restrict /dev/mem read() calls to linear region
UPSTREAM: binder: fix incorrect cmd to binder_stat_br
UPSTREAM: arm64: SW PAN: Update saved ttbr0 value on enter_lazy_tlb
UPSTREAM: KVM: arm/arm64: Check pagesize when allocating a hugepage at Stage 2
UPSTREAM: fs/proc/kcore.c: use probe_kernel_read() instead of memcpy()
UPSTREAM: arm64: fix unwind_frame() for filtered out fn for function graph tracing
UPSTREAM: arm64: kpti: Use early_param for kpti= command-line option
UPSTREAM: arm64: kaslr: ensure randomized quantities are clean to the PoC
UPSTREAM: arm64: kaslr: ensure randomized quantities are clean also when kaslr is off
UPSTREAM: staging: android: vsoc: fix copy_from_user overrun
UPSTREAM: arm64/mm: Inhibit huge-vmap with ptdump
UPSTREAM: drivers/perf: arm_pmu: Fix failure path in PM notifier
UPSTREAM: fs/posix_acl.c: fix kernel-doc warnings
UPSTREAM: ext2: fix debug reference to ext2_xattr_cache
UPSTREAM: arm64: alternative: fix build with clang integrated assembler
UPSTREAM: dm verity fec: fix hash block number in verity_fec_decode
ANDROID: Temporarily disable XFRM_USER_COMPAT filtering
BACKPORT: xfrm/compat: Translate 32-bit user_policy from sockptr
BACKPORT: xfrm/compat: Add 32=>64-bit messages translator
UPSTREAM: xfrm/compat: Attach xfrm dumps to 64=>32 bit translator
BACKPORT: xfrm/compat: Add 64=>32-bit messages translator
BACKPORT: xfrm: Provide API to register translator module
UPSTREAM: mm/sl[uo]b: export __kmalloc_track(_node)_caller
ANDROID: Publish uncompressed Image on aarch64
ANDROID: Makefile: append BUILD_NUMBER to version string when defined
UPSTREAM: binder: fix UAF when releasing todo list
ANDROID: fix a bug in quota2
UPSTREAM: binder: Prevent context manager from incrementing ref 0
BACKPORT: xtables: extend matches and targets with .usersize
UPSTREAM: ip6tables: use match, target and data copy_to_user helpers
UPSTREAM: iptables: use match, target and data copy_to_user helpers
UPSTREAM: xtables: add xt_match, xt_target and data copy_to_user functions
ANDROID: cuttlefish_defconfig: Drop built-in cmdline (except nopti)
ANDROID: cuttlefish defconfig - enable mount/net/uts namespaces.
ANDROID: hid: steam: remove BT controller matching
UPSTREAM: HID: steam: Fix input device disappearing
Revert "ext2: fix empty body warnings when -Wextra is used"
Revert "net: ipv6: Fix processing of RAs in presence of VRF"
UPSTREAM: net: socket: set sock->sk to NULL after calling proto_ops::release()
BACKPORT: xfrm: Allow Output Mark to be Updated Using UPDSA
UPSTREAM: socket: close race condition between sock_close() and sockfs_setattr()
UPSTREAM: net: ipv6: Use passed in table for nexthop lookups
ANDROID: cuttlefish_defconfig: Fix dm-verity related options
Revert "ANDROID: dm verity: add minimum prefetch size"
ANDROID: mnt: Propagate remount correctly
BACKPORT: loop: Add LOOP_SET_BLOCK_SIZE in compat ioctl
UPSTREAM: loop: drop caches if offset or block_size are changed
UPSTREAM: loop: add ioctl for changing logical block size
BACKPORT: block/loop: set hw_sectors
ANDROID: cuttlefish_defconfig: Minimally enable EFI
UPSTREAM: bpf: Explicitly memset the bpf_attr structure
FROMLIST: HID: nintendo: add nintendo switch controller driver
UPSTREAM: staging: most: net: fix buffer overflow
UPSTREAM: ALSA: pcm: Add missing copy ops check before clearing buffer
ANDROID: selinux: modify RTM_GETLINK permission
UPSTREAM: HID: input: map digitizer battery usage
UPSTREAM: HID: input: ignore the battery in OKLICK Laser BTmouse
ANDROID: cuttlefish_defconfig: Disable TRANSPARENT_HUGEPAGE
commit e82b9b0727ff ("vhost: introduce vhost_exceeds_weight()")
UPSTREAM: HID: steam: fix deadlock with input devices.
UPSTREAM: HID: steam: fix boot loop with bluetooth firmware
UPSTREAM: HID: steam: remove input device when a hid client is running.
UPSTREAM: HID: steam: use hid_device.driver_data instead of hid_set_drvdata()
UPSTREAM: HID: steam: add missing fields in client initialization
UPSTREAM: HID: steam: add battery device.
UPSTREAM: HID: add driver for Valve Steam Controller
UPSTREAM: HID: sony: Fix memory corruption issue on cleanup.
UPSTREAM: HID: sony: Fix race condition between rumble and device remove.
UPSTREAM: HID: sony: remove redundant check for -ve err
UPSTREAM: HID: sony: Make sure to unregister sensors on failure
UPSTREAM: HID: sony: Make DS4 bt poll interval adjustable
UPSTREAM: HID: sony: Set proper bit flags on DS4 output report
UPSTREAM: HID: sony: DS4 use brighter LED colors
UPSTREAM: HID: sony: Improve navigation controller axis/button mapping
UPSTREAM: HID: sony: Use DS3 MAC address as unique identifier on USB
UPSTREAM: HID: sony: Perform duplicate device check earlier on
UPSTREAM: HID: sony: Expose DS3 motion sensors through separate device
UPSTREAM: HID: sony: Print error on failure to active DS3 / Navigation controllers
UPSTREAM: HID: sony: DS3 comply to Linux gamepad spec
UPSTREAM: HID: sony: Mark DS4 touchpad device as a pointer
UPSTREAM: HID: sony: Support motion sensor calibration on dongle
UPSTREAM: HID: sony: Make work handling more generic
UPSTREAM: HID: sony: Treat the ds4 dongle as a separate device
UPSTREAM: HID: sony: Remove report descriptor fixup for DS4
UPSTREAM: HID: sony: Report hardware timestamp for DS4 sensor values
UPSTREAM: HID: sony: Calibrate DS4 motion sensors
UPSTREAM: HID: sony: Report DS4 motion sensors through a separate device
UPSTREAM: HID: sony: Fix input device leak when connecting a DS4 twice using USB/BT
UPSTREAM: HID: sony: Use LED_CORE_SUSPENDRESUME
UPSTREAM: HID: sony: Ignore DS4 dongle reports when no device is connected
UPSTREAM: HID: sony: Use DS4 MAC address as unique identifier on USB
UPSTREAM: HID: sony: Fix error handling bug when touchpad registration fails
UPSTREAM: HID: sony: Comply to Linux gamepad spec for DS4
UPSTREAM: HID: sony: Make the DS4 touchpad a separate device
UPSTREAM: HID: sony: Fix memory issue when connecting device using both Bluetooth and USB
UPSTREAM: HID: sony: Adjust value range for motion sensors
UPSTREAM: HID: sony: Handle multiple touch events input record
UPSTREAM: HID: sony: Send ds4 output reports on output end-point
UPSTREAM: HID: sony: Perform CRC check on bluetooth input packets
UPSTREAM: HID: sony: Adjust HID report size name definitions
UPSTREAM: HID: sony: Fix race condition in sony_probe
UPSTREAM: HID: sony: Update copyright and add Dualshock 4 rate control note
UPSTREAM: HID: sony: Defer the initial USB Sixaxis output report
UPSTREAM: HID: sony: Relax duplicate checking for USB-only devices
UPSTREAM: HID: sony: underscores are unnecessary for u8, u16, s32
UPSTREAM: HID: sony: fix some warnings from scripts/checkpatch.pl
UPSTREAM: HID: sony: fix errors from scripts/checkpatch.pl
UPSTREAM: HID: sony: fix a typo in descriptors comments s/Joystik/Joystick/
UPSTREAM: HID: sony: Fixup output reports for the nyko core controller
UPSTREAM: HID: sony: Remove the size check for the Dualshock 4 HID Descriptor
UPSTREAM: HID: sony: Save and restore the controller state on suspend and resume
UPSTREAM: HID: sony: Refactor the output report sending functions
ANDROID: cpufreq: times: add /proc/uid_concurrent_{active,policy}_time
rtlwifi: Fix potential overflow on P2P code
ANDROID: clang: update to 9.0.8 based on r365631c
ANDROID: move up spin_unlock_bh() ahead of remove_proc_entry()
ANDROID: refactor build.config files to remove duplication
ANDROID: usb: gadget: Fix dependency for f_accessory
Remove taskname from lowmemorykiller kill reports
ANDROID: Fixes to locking around handle_lmk_event
Revert "ANDROID: regression introduced override_creds=off"
ANDROID: regression introduced override_creds=off
Fix fallout from changes to bootparam_utils.h
ANDROID: sched: Disallow WALT with CFS bandwidth control
ANDROID: fiq_debugger: remove
ANDROID: arm64: fix leftover RWX when using CONFIG_UNMAP_KERNEL_AT_EL0
ANDROID: fix kernelci build-break in lowmemorykiller
ANDROID: Avoid taking multiple locks in handle_lmk_event
UPSTREAM: net-ipv6-ndisc: add support for RFC7710 RA Captive Portal Identifier
ANDROID: fix binder change in merge of 4.4.183
Fix overlayfs build break
binder: binder: fix possible UAF when freeing buffer
ANDROID: Revert "f2fs: avoid out-of-range memory access"
ANDROID: overlayfs: Fix a regression in commit b24be4acd
ANDROID: enable CONFIG_RTC_DRV_TEST on cuttlefish
ANDROID: xfrm: remove in_compat_syscall() checks
BACKPORT: binder: Set end of SG buffer area properly.
UPSTREAM: binder: check for overflow when alloc for security context
BACKPORT: binder: fix race between munmap() and direct reclaim
ANDROID: cuttlefish 4.4: enable CONFIG_CRYPTO_AES_NI_INTEL=y
ANDROID: cuttlefish_defconfig: Disable DEVTMPFS
ANDROID: cuttlefish_defconfig: Enable CONFIG_CPUSETS and CONFIG_CGROUP_SCHEDTUNE
ANDROID: cuttlefish_defconfig: Drop dead CRYPTO options
UPSTREAM: virtio: new feature to detect IOMMU device quirk
UPSTREAM: vring: Use the DMA API on Xen
UPSTREAM: virtio_ring: Support DMA APIs
UPSTREAM: vring: Introduce vring_use_dma_api()
ANDROID: cuttlefish_defconfig: L2TP/PPTP to OLAC/OPNS
ANDROID: cuttlefish_defconfig: Enable DEBUG_SET_MODULE_RONX
ANDROID: Fix cuttlefish redundant vsock connection.
ANDROID: cuttlefish_defconfig: Enable CONFIG_RTC_HCTOSYS
ANDROID: Move from clang r349610 to r353983c.
Make arm64 serial port config compatible with crosvm
UPSTREAM: virt_wifi: Remove REGULATORY_WIPHY_SELF_MANAGED
ANDROID: cuttlefish_defconfig: Add support for AC97 audio
ANDROID: Move from clang r346389b to r349610.
ANDROID: cuttlefish_defconfig: Enable vsock options
UPSTREAM: vhost/vsock: fix reset orphans race with close timeout
UPSTREAM: vhost/vsock: fix use-after-free in network stack callers
UPSTREAM: vhost: correctly check the iova range when waking virtqueue
UPSTREAM: vhost: synchronize IOTLB message with dev cleanup
UPSTREAM: vhost: fix info leak due to uninitialized memory
UPSTREAM: vhost: fix vhost_vq_access_ok() log check
UPSTREAM: vhost: validate log when IOTLB is enabled
UPSTREAM: vhost_net: add missing lock nesting notation
UPSTREAM: vhost: use mutex_lock_nested() in vhost_dev_lock_vqs()
UPSTREAM: vhost/vsock: fix uninitialized vhost_vsock->guest_cid
UPSTREAM: vhost_net: correctly check tx avail during rx busy polling
UPSTREAM: vsock: use new wait API for vsock_stream_sendmsg()
UPSTREAM: vsock: cancel packets when failing to connect
UPSTREAM: vhost-vsock: add pkt cancel capability
UPSTREAM: vsock: track pkt owner vsock
UPSTREAM: vhost: fix initialization for vq->is_le
UPSTREAM: vhost/vsock: handle vhost_vq_init_access() error
UPSTREAM: vsock: lookup and setup guest_cid inside vhost_vsock_lock
UPSTREAM: vhost-vsock: fix orphan connection reset
UPSTREAM: vsock/virtio: fix src/dst cid format
UPSTREAM: VSOCK: Don't dec ack backlog twice for rejected connections
UPSTREAM: vhost/vsock: drop space available check for TX vq
UPSTREAM: virtio-vsock: fix include guard typo
UPSTREAM: vhost/vsock: fix vhost virtio_vsock_pkt use-after-free
UPSTREAM: VSOCK: Use kvfree()
BACKPORT: vhost: split out vringh Kconfig
UPSTREAM: vhost: drop vringh dependency
UPSTREAM: vhost: drop vringh dependency
UPSTREAM: vhost: detect 32 bit integer wrap around
UPSTREAM: VSOCK: Add Makefile and Kconfig
UPSTREAM: VSOCK: Introduce vhost_vsock.ko
UPSTREAM: VSOCK: Introduce virtio_transport.ko
BACKPORT: VSOCK: Introduce virtio_vsock_common.ko
UPSTREAM: VSOCK: defer sock removal to transports
UPSTREAM: VSOCK: transport-specific vsock_transport functions
UPSTREAM: vsock: make listener child lock ordering explicit
UPSTREAM: vhost: new device IOTLB API
BACKPORT: vhost: convert pre sorted vhost memory array to interval tree
UPSTREAM: vhost: introduce vhost memory accessors
UPSTREAM: vhost_net: stop polling socket during rx processing
UPSTREAM: VSOCK: constify vsock_transport structure
UPSTREAM: vhost: lockless enqueuing
UPSTREAM: vhost: simplify work flushing
UPSTREAM: VSOCK: Only check error on skb_recv_datagram when skb is NULL
BACKPORT: AF_VSOCK: Shrink the area influenced by prepare_to_wait
UPSTREAM: vhost_net: basic polling support
UPSTREAM: vhost: introduce vhost_vq_avail_empty()
UPSTREAM: vhost: introduce vhost_has_work()
UPSTREAM: vhost: rename vhost_init_used()
UPSTREAM: vhost: rename cross-endian helpers
UPSTREAM: vhost: fix error path in vhost_init_used()
UPSTREAM: virtio: make find_vqs() checkpatch.pl-friendly
UPSTREAM: net: move napi_hash[] into read mostly section
ANDROID: cuttlefish_defconfig: Enable VIRTIO_INPUT
ANDROID: cuttlefish_defconfig: Enable VIRT_WIFI
FROMGIT, BACKPORT: mac80211-next: rtnetlink wifi simulation device
ANDROID: Move from clang r328903 to r346389b.
ANDROID: arm64 defconfig / build config for cuttlefish
ANDROID: Communicates LMK events to userland where they can be logged
Fix merge issue with 4.4.178
Fix merge issue with 4.4.177
FROMGIT: binder: create node flag to request sender's security context
ion: Disable ION_HEAP_TYPE_SYSTEM_CONTIG
ANDROID: uid_sys_stats: Copy task_struct comm field to bigger buffer
UPSTREAM: binder: fix race that allows malicious free of live buffer
Makefile: Tidy up 4.4.165 merge
ANDROID: sdcardfs: Change current->fs under lock
ANDROID: sdcardfs: Don't use OVERRIDE_CRED macro
arm64/vdso: Fix nsec handling for CLOCK_MONOTONIC_RAW
ANDROID: arm64: mm: fix 4.4.154 merge
Fix backport of "tcp: detect malicious patterns in tcp_collapse_ofo_queue()"
tcp: detect malicious patterns in tcp_collapse_ofo_queue()
tcp: avoid collapses in tcp_prune_queue() if possible
x86_64_cuttlefish_defconfig: Enable android-verity
x86_64_cuttlefish_defconfig: enable verity cert
ANDROID: Fix massive cpufreq_times memory leaks
ANDROID: Reduce use of #ifdef CONFIG_CPU_FREQ_TIMES
UPSTREAM: binder: replace "%p" with "%pK"
UPSTREAM: binder: free memory on error
UPSTREAM: binder: fix proc->files use-after-free
UPSTREAM: Revert "FROMLIST: binder: fix proc->files use-after-free"
UPSTREAM: ANDROID: binder: change down_write to down_read
UPSTREAM: ANDROID: binder: correct the cmd print for BINDER_WORK_RETURN_ERROR
UPSTREAM: ANDROID: binder: remove 32-bit binder interface.
UPSTREAM: ANDROID: binder: re-order some conditions
UPSTREAM: android: binder: use VM_ALLOC to get vm area
UPSTREAM: android: binder: Use true and false for boolean values
UPSTREAM: android: binder: Use octal permissions
UPSTREAM: android: binder: Prefer __func__ to using hardcoded function name
UPSTREAM: ANDROID: binder: make binder_alloc_new_buf_locked static and indent its arguments
UPSTREAM: android: binder: Check for errors in binder_alloc_shrinker_init().
cpufreq: Kconfig: Remove CPU_FREQ_DEFAULT_GOV_SCHED
ANDROID: Add kconfig to make dm-verity check_at_most_once default enabled
ANDROID: sdcardfs: fix potential crash when reserved_mb is not zero
ANDROID: Update arm64 ranchu64_defconfig
FROMLIST: f2fs: run fstrim asynchronously if runtime discard is on
goldfish: pipe: ANDROID: address must be written as __pa(x), not x
goldfish: pipe: ANDROID: add missing check for memory allocated
goldfish: pipe: ANDROID: remove redundant blank lines
Update arch/x86/configs/x86_64_ranchu_defconfig
ANDROID: x86_64_cuttlefish_defconfig: Enable F2FS
ANDROID: Update x86_64_cuttlefish_defconfig
FROMLIST: f2fs: early updates queued for v4.18-rc1
Revert "vti4: Don't override MTU passed on link creation via IFLA_MTU"
UPSTREAM: sched/fair: Consider RT/IRQ pressure in capacity_spare_wake
BACKPORT, FROMLIST: fscrypt: add Speck128/256 support
cgroup: Disable IRQs while holding css_set_lock
Revert "cgroup: Disable IRQs while holding css_set_lock"
cgroup: Disable IRQs while holding css_set_lock
ANDROID: proc: fix undefined behavior in proc_uid_base_readdir
x86: vdso: Fix leaky vdso linker with CC=clang.
ANDROID: build: cuttlefish: Upgrade clang to newer version.
ANDROID: build: cuttlefish: Upgrade clang to newer version.
ANDROID: build: cuttlefish: Fix path to clang.
UPSTREAM: dm bufio: avoid sleeping while holding the dm_bufio lock
ANDROID: sdcardfs: Don't d_drop in d_revalidate
goldfish: pipe: ANDROID: mark local functions static
Revert "goldfish: pipe: ANDROID: Allocate memory with GFP_KERNEL."
UPSTREAM: ANDROID: binder: prevent transactions into own process.
goldfish: pipe: ANDROID: Add DMA support
UPSTREAM: f2fs: clear PageError on writepage - part 2
UPSTREAM: f2fs: avoid fsync() failure caused by EAGAIN in writepage()
ANDROID: build.config: enforce trace_printk check
ANDROID: x86_64_cuttlefish_defconfig: Disable KPTI
UPSTREAM: mac80211: ibss: Fix channel type enum in ieee80211_sta_join_ibss()
UPSTREAM: mac80211: Fix clang warning about constant operand in logical operation
UPSTREAM: nl80211: Fix enum type of variable in nl80211_put_sta_rate()
UPSTREAM: sysfs: remove signedness from sysfs_get_dirent
UPSTREAM: tracing: Use cpumask_available() to check if cpumask variable may be used
BACKPORT: clocksource: Use GENMASK_ULL in definition of CLOCKSOURCE_MASK
UPSTREAM: netpoll: Fix device name check in netpoll_setup()
FROMLIST: staging: Fix sparse warnings in vsoc driver.
FROMLIST: staging: vsoc: Fix a i386-randconfig warning.
FROMLIST: staging: vsoc: Create wc kernel mapping for region shm.
Revert "goldfish: pipe: ANDROID: remove a redundant target"
goldfish: pipe: ANDROID: Replace writel with gf_write_ptr
goldfish: pipe: ANDROID: Use dev_ logging instead of pr_
goldfish: pipe: ANDROID: fix checkpatch warnings
goldfish: pipe: ANDROID: Update module license
goldfish: pipe: ANDROID: Allocate memory with GFP_KERNEL.
goldfish: pipe: ANDROID: Do not crash
goldfish: pipe: ANDROID: remove redundant casting
goldfish: pipe: ANDROID: Add 'pipe' to pipe functions
goldfish: pipe: ANDROID: fix whitespace
goldfish: pipe: ANDROID: rename global variables
goldfish: pipe: ANDROID: remove a redundant target
goldfish: pipe: ANDROID: add blank lines
goldfish: pipe: ANDROID: replace 'BUG_ON' with 'BUILD_BUG_ON'
goldfish: pipe: ANDROID: use the 'BIT' macro for wakeup flags
goldfish: pipe: ANDROID: fix logging format strings
UPSTREAM: tracing: always define trace_{irq,preempt}_{enable_disable}
ANDROID: staging: ion: Obey kptr_restrict
ANDROID: sdcardfs: Set s_root to NULL after putting
ANDROID: sdcardfs: d_make_root calls iput
ANDROID: sdcardfs: Check for private data earlier
f2fs: check cap_resource only for data blocks
Revert "f2fs: introduce f2fs_set_page_dirty_nobuffer"
f2fs: clear PageError on writepage
UPSTREAM: timer: Export destroy_hrtimer_on_stack()
BACKPORT: dm verity: add 'check_at_most_once' option to only validate hashes once
f2fs: call unlock_new_inode() before d_instantiate()
f2fs: refactor read path to allow multiple postprocessing steps
fscrypt: allow synchronous bio decryption
ANDROID: Add build server config for cuttlefish.
ANDROID: Add defconfig for cuttlefish.
FROMLIST: staging: Android: Add 'vsoc' driver for cuttlefish.
Revert "proc: make oom adjustment files user read-only"
Revert "fixup! proc: make oom adjustment files user read-only"
ANDROID: proc: add null check in proc_uid_init
f2fs/fscrypt: updates to v4.17-rc1
Reduce amount of casting in drivers/tty/goldfish.c.
Replace #define with enum for better compilation errors.
Add missing include to drivers/tty/goldfish.c
Fix whitespace in drivers/tty/goldfish.c
ANDROID: fuse: Add null terminator to path in canonical path to avoid issue
ANDROID: sdcardfs: Fix sdcardfs to stop creating cases-sensitive duplicate entries.
ANDROID: add missing include to pdev_bus
ANDROID: pdev_bus: replace writel with gf_write_ptr
ANDROID: Cleanup type casting in goldfish.h
ANDROID: Include missing headers in goldfish.h
ANDROID: cpufreq: times: skip printing invalid frequencies
ANDROID: xt_qtaguid: Remove unnecessary null checks to device's name
ANDROID: xt_qtaguid: Remove unnecessary null checks to ifa_label
ANDROID: cpufreq: times: allocate enough space for a uid_entry
Revert "genirq: Use irqd_get_trigger_type to compare the trigger type for shared IRQs"
UPSTREAM: drm: virtio-gpu: set atomic flag
UPSTREAM: drm: virtio-gpu: transfer dumb buffers to host on plane update
UPSTREAM: drm: virtio-gpu: ensure plane is flushed to host on atomic update
UPSTREAM: drm: virtio-gpu: get the fb from the plane state for atomic updates
ANDROID: cpufreq: times: fix proc_time_in_state_show
dtc: turn off dtc unit address warnings by default
BACKPORT, FROMLIST: crypto: arm64/speck - add NEON-accelerated implementation of Speck-XTS
ANDROID: cpufreq: times: avoid prematurely freeing uid_entry
ANDROID: Use standard logging functions in goldfish_pipe
ANDROID: Fix whitespace in goldfish
staging: android: ashmem: Fix possible deadlock in ashmem_ioctl
llist: clang: introduce member_address_is_nonnull()
ANDROID: ranchu: 32 bit framebuffer support
ANDROID: Address checkpatch warnings in goldfishfb
ANDROID: Address checkpatch.pl warnings in goldfish_pipe
ANDROID: sdcardfs: fix lock issue on 32 bit/SMP architectures
ANDROID: goldfish: Fix typo in goldfish_cmd_locked() call
ANDROID: Address checkpatch.pl warnings in goldfish_pipe_v2
FROMLIST: f2fs: don't put dentry page in pagecache into highmem
ANDROID: Delete the goldfish_nand driver.
ANDROID: Add input support for Android Wear.
ANDROID: proc: fix config & includes for /proc/uid
FROMLIST: ARM: amba: Don't read past the end of sysfs "driver_override" buffer
UPSTREAM: ANDROID: binder: remove WARN() for redundant txn error
ANDROID: cpufreq: times: Add missing includes
ANDROID: cpufreq: Add time_in_state to /proc/uid directories
ANDROID: proc: Add /proc/uid directory
ANDROID: cpufreq: times: track per-uid time in state
ANDROID: cpufreq: track per-task time in state
ANDROID: keychord: Check for write data size
Revert "binder: add missing binder_unlock()"
ANDROID: sdcardfs: Set num in extension_details during make_item
ANDROID: sdcardfs: Hold i_mutex for i_size_write
BACKPORT, FROMGIT: crypto: speck - add test vectors for Speck64-XTS
BACKPORT, FROMGIT: crypto: speck - add test vectors for Speck128-XTS
BACKPORT, FROMGIT: crypto: arm/speck - add NEON-accelerated implementation of Speck-XTS
FROMGIT: crypto: speck - export common helpers
BACKPORT, FROMGIT: crypto: speck - add support for the Speck block cipher
UPSTREAM: ANDROID: binder: synchronize_rcu() when using POLLFREE.
f2fs: updates on v4.16-rc1
BACKPORT: tee: shm: Potential NULL dereference calling tee_shm_register()
BACKPORT: tee: shm: don't put_page on null shm->pages
BACKPORT: tee: shm: make function __tee_shm_alloc static
BACKPORT: tee: optee: check type of registered shared memory
BACKPORT: tee: add start argument to shm_register callback
BACKPORT: tee: optee: fix header dependencies
BACKPORT: tee: shm: inline tee_shm_get_id()
BACKPORT: tee: use reference counting for tee_context
BACKPORT: tee: optee: enable dynamic SHM support
BACKPORT: tee: optee: add optee-specific shared pool implementation
BACKPORT: tee: optee: store OP-TEE capabilities in private data
BACKPORT: tee: optee: add registered buffers handling into RPC calls
BACKPORT: tee: optee: add registered shared parameters handling
BACKPORT: tee: optee: add shared buffer registration functions
BACKPORT: tee: optee: add page list manipulation functions
BACKPORT: tee: optee: Update protocol definitions
BACKPORT: tee: shm: add page accessor functions
BACKPORT: tee: shm: add accessors for buffer size and page offset
BACKPORT: tee: add register user memory
BACKPORT: tee: flexible shared memory pool creation
BACKPORT: optee: support asynchronous supplicant requests
BACKPORT: tee: add TEE_IOCTL_PARAM_ATTR_META
BACKPORT: tee: add tee_param_is_memref() for driver use
f2fs: fix build error with multiply defined inode_nohighmem()
BACKPORT: xfrm: Fix return value check of copy_sec_ctx.
time: Fix ktime_get_raw() incorrect base accumulation
sched/fair: prevent possible infinite loop in sched_group_energy
UPSTREAM: MIPS: Fix build of compressed image
ANDROID: qtaguid: Fix the UAF probelm with tag_ref_tree
UPSTREAM: ANDROID: binder: remove waitqueue when thread exits.
UPSTREAM: arm64/efi: Make strnlen() available to the EFI namespace
UPSTREAM: ARM: boot: Add an implementation of strnlen for libfdt
ANDROID: MIPS: Add ranchu[32r5|32r6|64]_defconfig
FROMLIST: tty: goldfish: Enable 'earlycon' only if built-in
FROMLIST: MIPS: ranchu: Add Ranchu as a new generic-based board
FROMLIST: MIPS: Add noexec=on|off kernel parameter
FROMLIST: MIPS: CPC: Map registers using DT in mips_cpc_default_phys_base()
FROMLIST: dt-bindings: Document mti,mips-cpc binding
FROMLIST: MIPS: math-emu: Mark fall throughs in switch statements with a comment
FROMLIST: MIPS: math-emu: Avoid multiple assignment
FROMLIST: MIPS: math-emu: Avoid an assignment within if statement condition
FROMLIST: MIPS: math-emu: Declare function srl128() as static
FROMLIST: MIPS: math-emu: Avoid definition duplication for macro DPXMULT()
FROMLIST: MIPS: math-emu: Remove an unnecessary header inclusion
UPSTREAM: scripts/dtc: Update to upstream version 0931cea3ba20
UPSTREAM: scripts/dtc: dt_to_config - kernel config options for a devicetree
UPSTREAM: scripts/dtc: Update to upstream version 53bf130b1cdd
UPSTREAM: scripts/dtc: Update to upstream commit b06e55c88b9b
UPSTREAM: scripts/dtc: dtx_diff - add info to error message
UPSTREAM: dtc: create tool to diff device trees
UPSTREAM: config: android-base: disable CONFIG_NFSD and CONFIG_NFS_FS
UPSTREAM: config: android-base: add CGROUP_BPF
UPSTREAM: config: android-base: add CONFIG_MODULES option
UPSTREAM: config: android-base: add CONFIG_IKCONFIG option
UPSTREAM: config: android-base: disable CONFIG_USELIB and CONFIG_FHANDLE
UPSTREAM: config: android-base: enable hardened usercopy and kernel ASLR
UPSTREAM: config: android: enable CONFIG_SECCOMP
UPSTREAM: config: android: set SELinux as default security mode
UPSTREAM: config: android: move device mapper options to recommended
UPSTREAM: config/android: Remove CONFIG_IPV6_PRIVACY
UPSTREAM: config: add android config fragments
BACKPORT: MIPS: generic: Add a MAINTAINERS entry
BACKPORT: irqchip/irq-goldfish-pic: Add Goldfish PIC driver
UPSTREAM: dt-bindings/goldfish-pic: Add device tree binding for Goldfish PIC driver
UPSTREAM: MIPS: Allow storing pgd in C0_CONTEXT for MIPSr6
UPSTREAM: MIPS: CPS: Handle spurious VP starts more gracefully
UPSTREAM: MIPS: CPS: Handle cores not powering down more gracefully
UPSTREAM: MIPS: CPS: Prevent multi-core with dcache aliasing
UPSTREAM: MIPS: CPS: Select CONFIG_SYS_SUPPORTS_SCHED_SMT for MIPSr6
UPSTREAM: MIPS: CM: WARN on attempt to lock invalid VP, not BUG
UPSTREAM: MIPS: CM: Avoid per-core locking with CM3 & higher
UPSTREAM: MIPS: smp-cps: Avoid BUG() when offlining pre-r6 CPUs
UPSTREAM: MIPS: smp-cps: Add support for CPU hotplug of MIPSr6 processors
UPSTREAM: MIPS: generic: Bump default NR_CPUS to 16
UPSTREAM: MIPS: pm-cps: Change FSB workaround to CPU blacklist
UPSTREAM: MIPS: Fix early CM probing
UPSTREAM: MIPS: smp-cps: Stop printing EJTAG exceptions to UART
UPSTREAM: MIPS: smp-cps: Add nothreads kernel parameter
UPSTREAM: MIPS: smp-cps: Support MIPSr6 Virtual Processors
UPSTREAM: MIPS: smp-cps: Skip core setup if coherent
UPSTREAM: MIPS: smp-cps: Pull boot config retrieval out of mips_cps_boot_vpes
UPSTREAM: MIPS: smp-cps: Pull cache init into a function
UPSTREAM: MIPS: smp-cps: Ensure our VP ident calculation is correct
UPSTREAM: irqchip: mips-gic: Provide VP ID accessor
UPSTREAM: irqchip: mips-gic: Use HW IDs for VPE_OTHER_ADDR
UPSTREAM: MIPS: CM: Fix mips_cm_max_vp_width for UP kernels
UPSTREAM: MIPS: CM: Add CM GCR_BEV_BASE accessors
UPSTREAM: MIPS: CPC: Add start, stop and running CM3 CPC registers
UPSTREAM: MIPS: pm-cps: Avoid offset overflow on MIPSr6
UPSTREAM: MIPS: traps: Make sure secondary cores have a sane ebase register
UPSTREAM: MIPS: Detect MIPSr6 Virtual Processor support
UPSTREAM: Documentation: Add device tree binding for Goldfish FB driver
UPSTREAM: MIPS: math-emu: Use preferred flavor of unsigned integer declarations
UPSTREAM: MIPS: math-emu: <MADDF|MSUBF>.D: Fix accuracy (64-bit case)
UPSTREAM: MIPS: math-emu: <MADDF|MSUBF>.S: Fix accuracy (32-bit case)
UPSTREAM: MIPS: Update Goldfish RTC driver maintainer email address
UPSTREAM: MIPS: Update RINT emulation maintainer email address
UPSTREAM: MIPS: math-emu: do not use bools for arithmetic
UPSTREAM: rtc: goldfish: Add RTC driver for Android emulator
BACKPORT: dt-bindings: Add device tree binding for Goldfish RTC driver
UPSTREAM: tty: goldfish: Implement support for kernel 'earlycon' parameter
UPSTREAM: tty: goldfish: Use streaming DMA for r/w operations on Ranchu platforms
UPSTREAM: tty: goldfish: Refactor constants to better reflect their nature
UPSTREAM: MIPS: math-emu: Add FP emu debugfs stats for individual instructions
UPSTREAM: MIPS: math-emu: Add FP emu debugfs clear functionality
UPSTREAM: MIPS: math-emu: Add FP emu debugfs statistics for branches
BACKPORT: MIPS: math-emu: CLASS.D: Zero bits 32-63 of the result
BACKPORT: MIPS: math-emu: RINT.<D|S>: Fix several problems by reimplementation
UPSTREAM: MIPS: math-emu: CMP.Sxxx.<D|S>: Prevent occurrences of SIGILL crashes
UPSTREAM: MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Clean up "maddf_flags" enumeration
UPSTREAM: MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Fix some cases of zero inputs
UPSTREAM: MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Fix some cases of infinite inputs
UPSTREAM: MIPS: math-emu: <MADDF|MSUBF>.<D|S>: Fix NaN propagation
UPSTREAM: tty: goldfish: Fix a parameter of a call to free_irq
UPSTREAM: MIPS: VDSO: Fix clobber lists in fallback code paths
UPSTREAM: MIPS: VDSO: Fix a mismatch between comment and preprocessor constant
UPSTREAM: MIPS: VDSO: Add implementation of gettimeofday() fallback
UPSTREAM: MIPS: VDSO: Add implementation of clock_gettime() fallback
UPSTREAM: MIPS: VDSO: Fix conversions in do_monotonic()/do_monotonic_coarse()
UPSTREAM: MIPS: unaligned: Add DSP lwx & lhx missaligned access support
UPSTREAM: MIPS: build: Fix "-modd-spreg" switch usage when compiling for mips32r6
UPSTREAM: MIPS: cmdline: Add support for 'memmap' parameter
UPSTREAM: MIPS: math-emu: Handle zero accumulator case in MADDF and MSUBF separately
UPSTREAM: MIPS: Support per-device DMA coherence
UPSTREAM: MIPS: dma-default: Don't check hw_coherentio if device is non-coherent
UPSTREAM: MIPS: Sanitise coherentio semantics
UPSTREAM: MIPS: CPC: Provide default mips_cpc_default_phys_base to ignore CPC
UPSTREAM: MIPS: generic: Introduce generic DT-based board support
UPSTREAM: MIPS: Support generating Flattened Image Trees (.itb)
UPSTREAM: MIPS: Allow emulation for unaligned [LS]DXC1 instructions
UPSTREAM: MIPS: math-emu: Fix BC1EQZ and BC1NEZ condition handling
UPSTREAM: MIPS: r2-on-r6-emu: Clear BLTZALL and BGEZALL debugfs counters
UPSTREAM: MIPS: r2-on-r6-emu: Fix BLEZL and BGTZL identification
UPSTREAM: MIPS: remove aliasing alignment if HW has antialising support
BACKPORT: MIPS: store the appended dtb address in a variable
UPSTREAM: MIPS: Fix FCSR Cause bit handling for correct SIGFPE issue
UPSTREAM: MIPS: kernel: Audit and remove any unnecessary uses of module.h
UPSTREAM: MIPS: c-r4k: Fix sigtramp SMP call to use kmap
UPSTREAM: MIPS: c-r4k: Fix protected_writeback_scache_line for EVA
UPSTREAM: MIPS: Spelling fix lets -> let's
UPSTREAM: MIPS: R6: Fix typo
UPSTREAM: MIPS: traps: Correct the SIGTRAP debug ABI in `do_watch' and `do_trap_or_bp'
UPSTREAM: MIPS: inst.h: Rename cbcond{0,1}_op to pop{1,3}0_op
UPSTREAM: MIPS: inst.h: Rename b{eq,ne}zcji[al]c_op to pop{6,7}6_op
UPSTREAM: MIPS: math-emu: Fix m{add,sub}.s shifts
UPSTREAM: MIPS: inst: Declare fsel_op for sel.fmt instruction
UPSTREAM: MIPS: math-emu: Fix code indentation
UPSTREAM: MIPS: math-emu: Fix bit-width in ieee754dp_{mul, maddf, msubf} comments
UPSTREAM: MIPS: math-emu: Add z argument macros
UPSTREAM: MIPS: math-emu: Unify ieee754dp_m{add,sub}f
UPSTREAM: MIPS: math-emu: Unify ieee754sp_m{add,sub}f
UPSTREAM: MIPS: math-emu: Emulate MIPSr6 sel.fmt instruction
UPSTREAM: MIPS: math-emu: Fix BC1{EQ,NE}Z emulation
UPSTREAM: MIPS: math-emu: Always propagate sNaN payload in quieting
UPSTREAM: MIPS: Fix misspellings in comments.
UPSTREAM: MIPS: math-emu: Add IEEE Std 754-2008 NaN encoding emulation
UPSTREAM: MIPS: math-emu: Add IEEE Std 754-2008 ABS.fmt and NEG.fmt emulation
UPSTREAM: MIPS: non-exec stack & heap when non-exec PT_GNU_STACK is present
UPSTREAM: MIPS: Add IEEE Std 754 conformance mode selection
UPSTREAM: MIPS: Determine the presence of IEEE Std 754-2008 features
UPSTREAM: MIPS: Define the legacy-NaN and 2008-NaN features
UPSTREAM: MIPS: ELF: Interpret the NAN2008 file header flag
UPSTREAM: ELF: Also pass any interpreter's file header to `arch_check_elf'
UPSTREAM: MIPS: Use a union to access the ELF file header
UPSTREAM: MIPS: Fix delay slot emulation count in debugfs
BACKPORT: exit_thread: accept a task parameter to be exited
UPSTREAM: mn10300: let exit_fpu accept a task
UPSTREAM: MIPS: Use per-mm page to execute branch delay slot instructions
BACKPORT: s390: get rid of exit_thread()
BACKPORT: exit_thread: remove empty bodies
UPSTREAM: MIPS: Make flush_thread
UPSTREAM: MIPS: Properly disable FPU in start_thread()
UPSTREAM: MIPS: Select CONFIG_HANDLE_DOMAIN_IRQ and make it work.
UPSTREAM: MIPS: math-emu: Fix typo
UPSTREAM: MIPS: math-emu: dsemul: Remove an unused bit in ADDIUPC emulation
UPSTREAM: MIPS: math-emu: dsemul: Reduce `get_isa16_mode' clutter
UPSTREAM: MIPS: math-emu: dsemul: Correct description of the emulation frame
UPSTREAM: MIPS: math-emu: Correct the emulation of microMIPS ADDIUPC instruction
UPSTREAM: MIPS: math-emu: Make microMIPS branch delay slot emulation work
UPSTREAM: MIPS: math-emu: dsemul: Fix ill formatting of microMIPS part
UPSTREAM: MIPS: math-emu: Correctly handle NOP emulation
ANDROID: sdcardfs: Protect set_top
ANDROID: fsnotify: Notify lower fs of open
Revert "ANDROID: sdcardfs: notify lower file of opens"
ANDROID: sdcardfs: Use lower getattr times/size
ANDROID: sched/rt: schedtune: Add boost retention to RT
ANDROID: sched: EAS: check energy_aware() before calling select_energy_cpu_brute() in up-migrate path
UPSTREAM: eventpoll.h: add missing epoll event masks
ANDROID: xattr: Pass EOPNOTSUPP to permission2
ANDROID: sdcardfs: Move default_normal to superblock
blkdev: Refactoring block io latency histogram codes
FROMLIST: arm64: kpti: Fix the interaction between ASID switching and software PAN
FROMLIST: arm64: Move post_ttbr_update_workaround to C code
FROMLIST: arm64: mm: Rename post_ttbr0_update_workaround
sched: EAS: Initialize push_task as NULL to avoid direct reference on out_unlock path
fscrypt: updates on 4.15-rc4
ANDROID: uid_sys_stats: fix the comment
BACKPORT: optee: fix invalid of_node_put() in optee_driver_init()
BACKPORT: tee: optee: sync with new naming of interrupts
BACKPORT: tee: indicate privileged dev in gen_caps
BACKPORT: tee: optee: interruptible RPC sleep
BACKPORT: tee: optee: add const to tee_driver_ops and tee_desc structures
BACKPORT: tee: tee_shm: Constify dma_buf_ops structures.
BACKPORT: tee: add forward declaration for struct device
BACKPORT: tee: optee: fix uninitialized symbol 'parg'
BACKPORT: tee.txt: standardize document format
BACKPORT: tee: add ARM_SMCCC dependency
BACKPORT: selinux: nlmsgtab: add SOCK_DESTROY to the netlink mapping tables
clocksource: arch_timer: make virtual counter access configurable
arm64: issue isb when trapping CNTVCT_EL0 access
BACKPORT: arm64: Add CNTFRQ_EL0 trap handler
BACKPORT: arm64: Add CNTVCT_EL0 trap handler
ANDROID: sdcardfs: Fix missing break on default_normal
ANDROID: usb: f_fs: Prevent gadget unbind if it is already unbound
arm64: Kconfig: Reword UNMAP_KERNEL_AT_EL0 kconfig entry
arm64: use RET instruction for exiting the trampoline
FROMLIST: arm64: kaslr: Put kernel vectors address in separate data page
FROMLIST: arm64: mm: Introduce TTBR_ASID_MASK for getting at the ASID in the TTBR
FROMLIST: arm64: Kconfig: Add CONFIG_UNMAP_KERNEL_AT_EL0
FROMLIST: arm64: entry: Add fake CPU feature for unmapping the kernel at EL0
FROMLIST: arm64: tls: Avoid unconditional zeroing of tpidrro_el0 for native tasks
FROMLIST: arm64: erratum: Work around Falkor erratum #E1003 in trampoline code
FROMLIST: arm64: entry: Hook up entry trampoline to exception vectors
FROMLIST: arm64: entry: Explicitly pass exception level to kernel_ventry macro
FROMLIST: arm64: mm: Map entry trampoline into trampoline and kernel page tables
FROMLIST: arm64: entry: Add exception trampoline page for exceptions from EL0
FROMLIST: arm64: mm: Invalidate both kernel and user ASIDs when performing TLBI
FROMLIST: arm64: mm: Add arm64_kernel_unmapped_at_el0 helper
FROMLIST: arm64: mm: Allocate ASIDs in pairs
FROMLIST: arm64: mm: Fix and re-enable ARM64_SW_TTBR0_PAN
FROMLIST: arm64: mm: Move ASID from TTBR0 to TTBR1
FROMLIST: arm64: mm: Temporarily disable ARM64_SW_TTBR0_PAN
FROMLIST: arm64: mm: Use non-global mappings for kernel space
UPSTREAM: arm64: factor out entry stack manipulation
UPSTREAM: arm64: tlbflush.h: add __tlbi() macro
ANDROID: sdcardfs: Add default_normal option
ANDROID: sdcardfs: notify lower file of opens
ANDROID: binder: Remove obsolete proc waitqueue.
UPSTREAM: arm64: setup: introduce kaslr_offset()
UPSTREAM: kcov: fix comparison callback signature
UPSTREAM: kcov: support comparison operands collection
UPSTREAM: kcov: remove pointless current != NULL check
UPSTREAM: kcov: support compat processes
UPSTREAM: kcov: simplify interrupt check
UPSTREAM: kcov: make kcov work properly with KASLR enabled
UPSTREAM: kcov: add more missing includes
UPSTREAM: kcov: add missing #include <linux/sched.h>
UPSTREAM: kcov: properly check if we are in an interrupt
UPSTREAM: kcov: don't profile branches in kcov
UPSTREAM: kcov: don't trace the code coverage code
BACKPORT: kernel: add kcov code coverage
BACKPORT: irq: Make the irqentry text section unconditional
UPSTREAM: arch, ftrace: for KASAN put hard/soft IRQ entries into separate sections
UPSTREAM: x86, kasan, ftrace: Put APIC interrupt handlers into .irqentry.text
UPSTREAM: kasan: make get_wild_bug_type() static
UPSTREAM: kasan: separate report parts by empty lines
UPSTREAM: kasan: improve double-free report format
UPSTREAM: kasan: print page description after stacks
UPSTREAM: kasan: improve slab object description
UPSTREAM: kasan: change report header
UPSTREAM: kasan: simplify address description logic
UPSTREAM: kasan: change allocation and freeing stack traces headers
UPSTREAM: kasan: unify report headers
UPSTREAM: kasan: introduce helper functions for determining bug type
BACKPORT: kasan: report only the first error by default
UPSTREAM: kasan: fix races in quarantine_remove_cache()
UPSTREAM: kasan: resched in quarantine_remove_cache()
BACKPORT: kasan, sched/headers: Uninline kasan_enable/disable_current()
BACKPORT: kasan: drain quarantine of memcg slab objects
UPSTREAM: kasan: eliminate long stalls during quarantine reduction
UPSTREAM: kasan: support panic_on_warn
UPSTREAM: x86/suspend: fix false positive KASAN warning on suspend/resume
UPSTREAM: kasan: support use-after-scope detection
UPSTREAM: kasan/tests: add tests for user memory access functions
UPSTREAM: mm, kasan: add a ksize() test
UPSTREAM: kasan: test fix: warn if the UAF could not be detected in kmalloc_uaf2
UPSTREAM: kasan: modify kmalloc_large_oob_right(), add kmalloc_pagealloc_oob_right()
UPSTREAM: lib/stackdepot: export save/fetch stack for drivers
UPSTREAM: lib/stackdepot.c: bump stackdepot capacity from 16MB to 128MB
BACKPORT: kprobes: Unpoison stack in jprobe_return() for KASAN
UPSTREAM: kasan: remove the unnecessary WARN_ONCE from quarantine.c
UPSTREAM: kasan: avoid overflowing quarantine size on low memory systems
UPSTREAM: kasan: improve double-free reports
BACKPORT: mm: coalesce split strings
BACKPORT: mm/kasan: get rid of ->state in struct kasan_alloc_meta
UPSTREAM: mm/kasan: get rid of ->alloc_size in struct kasan_alloc_meta
UPSTREAM: mm: kasan: remove unused 'reserved' field from struct kasan_alloc_meta
UPSTREAM: mm/kasan, slub: don't disable interrupts when object leaves quarantine
UPSTREAM: mm/kasan: don't reduce quarantine in atomic contexts
UPSTREAM: mm/kasan: fix corruptions and false positive reports
UPSTREAM: lib/stackdepot.c: use __GFP_NOWARN for stack allocations
BACKPORT: mm, kasan: switch SLUB to stackdepot, enable memory quarantine for SLUB
UPSTREAM: kasan/quarantine: fix bugs on qlist_move_cache()
UPSTREAM: mm: mempool: kasan: don't poot mempool objects in quarantine
UPSTREAM: kasan: change memory hot-add error messages to info messages
BACKPORT: mm/kasan: add API to check memory regions
UPSTREAM: mm/kasan: print name of mem[set,cpy,move]() caller in report
UPSTREAM: mm: kasan: initial memory quarantine implementation
UPSTREAM: lib/stackdepot: avoid to return 0 handle
UPSTREAM: lib/stackdepot.c: allow the stack trace hash to be zero
UPSTREAM: mm, kasan: fix compilation for CONFIG_SLAB
BACKPORT: mm, kasan: stackdepot implementation. Enable stackdepot for SLAB
BACKPORT: mm, kasan: add GFP flags to KASAN API
UPSTREAM: mm, kasan: SLAB support
UPSTREAM: mm/slab: align cache size first before determination of OFF_SLAB candidate
UPSTREAM: mm/slab: use more appropriate condition check for debug_pagealloc
UPSTREAM: mm/slab: factor out debugging initialization in cache_init_objs()
UPSTREAM: mm/slab: remove object status buffer for DEBUG_SLAB_LEAK
UPSTREAM: mm/slab: alternative implementation for DEBUG_SLAB_LEAK
UPSTREAM: mm/slab: clean up DEBUG_PAGEALLOC processing code
UPSTREAM: mm/slab: activate debug_pagealloc in SLAB when it is actually enabled
sched: EAS/WALT: Don't take into account of running task's util
BACKPORT: schedutil: Reset cached freq if it is not in sync with next_freq
UPSTREAM: kasan: add functions to clear stack poison
ANDROID: initramfs: call free_initrd() when skipping init
Documentation: tee subsystem and op-tee driver
tee: add OP-TEE driver
tee: generic TEE subsystem
dt/bindings: add bindings for optee
kernel.h: add u64_to_user_ptr()
ARM: 8481/2: drivers: psci: replace psci firmware calls
ARM: 8480/2: arm64: add implementation for arm-smccc
ARM: 8479/2: add implementation for arm-smccc
ARM: 8478/2: arm/arm64: add arm-smccc
UPSTREAM: net: xfrm: allow clearing socket xfrm policies.
BACKPORT: time: Clean up CLOCK_MONOTONIC_RAW time handling
BACKPORT: time: Fix CLOCK_MONOTONIC_RAW sub-nanosecond accounting
UPSTREAM: arm64: vdso: fix clock_getres for 4GiB-aligned res
f2fs: updates on 4.15-rc1
UPSTREAM: android: binder: fix type mismatch warning
BACKPORT: arm64: Use __pa_symbol for empty_zero_page
BACKPORT: arm64: Use __pa_symbol for kernel symbols
UPSTREAM: mm: Introduce lm_alias
FROMLIST: binder: fix proc->files use-after-free
ANDROID: binder: clarify deferred thread work.
FROMLIST: arm64: Avoid aligning normal memory pointers in __memcpy_{to,from}io
BACKPORT: xfrm: Clear sk_dst_cache when applying per-socket policy.
Revert "ANDROID: sched/rt: schedtune: Add boost retention to RT"
cpufreq: Drop schedfreq governor
ANDROID: sched/rt: schedtune: Add boost retention to RT
ANDROID: sched/rt: add schedtune accounting
ANDROID: Revert "arm64: move ELF_ET_DYN_BASE to 4GB / 4MB"
ANDROID: Revert "arm: move ELF_ET_DYN_BASE to 4MB"
sched: EAS: Fix the calculation of group util in group_idle_state()
sched: EAS: update trg_cpu to backup_cpu if no energy saving for target_cpu
sched: EAS: Fix the condition to distinguish energy before/after
sched: EAS: upmigrate misfit current task
sched: avoid pushing tasks to an offline CPU
sched: Extend active balance to accept 'push_task' argument
Revert "sched/core: Warn if ENERGY_AWARE is enabled but data is missing"
Revert "sched/core: fix have_sched_energy_data build warning"
FROMLIST: kbuild: clang: fix build failures with sparse check
Revert "Revert "UPSTREAM: efi/libstub/arm64: Set -fpie when building the EFI stub""
BACKPORT: efi/libstub: Unify command line param parsing
BACKPORT: arm64: relocatable: suppress R_AARCH64_ABS64 relocations in vmlinux
sched/core: fix have_sched_energy_data build warning
sched/core: Warn if ENERGY_AWARE is enabled but data is missing
sched: walt: Correct WALT window size initialization
FROMLIST: sched/fair: Use wake_q length as a hint for wake_wide
sched: WALT: account cumulative window demand
sched/fair: remove useless variable in find_best_target
sched/tune: access schedtune_initialized under CGROUP_SCHEDTUNE
sched/fair: consider task utilization in group_max_util()
sched/fair: consider task utilization in group_norm_util()
sched/fair: enforce EAS mode
sched/fair: ignore backup CPU when not valid
sched/fair: trace energy_diff for non boosted tasks
UPSTREAM: sched/fair: Sync task util before slow-path wakeup
UPSTREAM: sched/fair: Fix usage of find_idlest_group() when the local group is idlest
UPSTREAM: sched/fair: Fix usage of find_idlest_group() when no groups are allowed
BACKPORT: sched/fair: Fix find_idlest_group when local group is not allowed
UPSTREAM: sched/fair: Remove unnecessary comparison with -1
BACKPORT: sched/fair: Move select_task_rq_fair slow-path into its own function
UPSTREAM: sched/fair: Force balancing on nohz balance if local group has capacity
UPSTREAM: sched/core: Add missing update_rq_clock() call in set_user_nice()
UPSTREAM: sched/core: Add missing update_rq_clock() call for task_hot()
UPSTREAM: sched/core: Add missing update_rq_clock() in detach_task_cfs_rq()
UPSTREAM: sched/core: Add missing update_rq_clock() in post_init_entity_util_avg()
UPSTREAM: sched/core: Fix find_idlest_group() for fork
BACKPORT: sched/fair: Fix PELT integrity for new tasks
BACKPORT: sched/cgroup: Fix cpu_cgroup_fork() handling
UPSTREAM: sched/fair: Fix and optimize the fork() path
BACKPORT: sched/fair: Make it possible to account fair load avg consistently
cpufreq/sched: Consider max cpu capacity when choosing frequencies
ANDROID: binder: show high watermark of alloc->pages.
ANDROID: binder: Add thread->process_todo flag.
UPSTREAM: arm64: compat: Remove leftover variable declaration
ANDROID: sched/fair: Select correct capacity state for energy_diff
Revert "UPSTREAM: efi/libstub/arm64: Set -fpie when building the EFI stub"
cpufreq: schedutil: clamp util to CPU maximum capacity
FROMLIST: android: binder: Fix null ptr dereference in debug msg
FROMLIST: android: binder: Change binder_shrinker to static
cpufreq/sched: Use cpu max freq rather than policy max
trace: sched: Fix util_avg_walt in sched_load_avg_cpu trace
sched/fair: remove erroneous RCU_LOCKDEP_WARN from start_cpu()
sched: EAS/WALT: finish accounting prior to task_tick
cpufreq: sched: update capacity request upon tick always
sched/fair: prevent meaningless active migration
sched: walt: Leverage existing helper APIs to apply invariance
ANDROID: HACK: arm64: use -mno-implicit-float instead of -mgeneral-regs-only
sched: Update task->on_rq when tasks are moving between runqueues
FROMLIST: f2fs: expose some sectors to user in inline data or dentry case
crypto: Work around deallocated stack frame reference gcc bug on sparc.
UPSTREAM: f2fs: fix potential panic during fstrim
ANDROID: fscrypt: remove unnecessary fscrypto.h
ANDROID: binder: fix node sched policy calculation
ANDROID: binder: init desired_prio.sched_policy before use it
BACKPORT: net: xfrm: support setting an output mark.
UPSTREAM: xfrm: Only add l3mdev oif to dst lookups
UPSTREAM: net: l3mdev: Add master device lookup by index
ANDROID: Kbuild, LLVMLinux: allow overriding clang target triple
CHROMIUM: arm64: Disable asm-operand-width warning for clang
CHROMIUM: kbuild: clang: Disable the 'duplicate-decl-specifier' warning
UPSTREAM: x86/build: Use cc-option to validate stack alignment parameter
UPSTREAM: x86/build: Fix stack alignment for CLang
UPSTREAM: efi/libstub/arm64: Set -fpie when building the EFI stub
BACKPORT: efi/libstub/arm64: Force 'hidden' visibility for section markers
UPSTREAM: compiler, clang: always inline when CONFIG_OPTIMIZE_INLINING is disabled
UPSTREAM: x86/boot: #undef memcpy() et al in string.c
UPSTREAM: crypto: arm64/sha - avoid non-standard inline asm tricks
UPSTREAM: kbuild: clang: Disable 'address-of-packed-member' warning
UPSTREAM: x86/build: Specify stack alignment for clang
UPSTREAM: x86/build: Use __cc-option for boot code compiler options
BACKPORT: kbuild: Add __cc-option macro
UPSTREAM: x86/hweight: Don't clobber %rdi
BACKPORT: x86/hweight: Get rid of the special calling convention
BACKPORT: x86/mm/kaslr: Use the _ASM_MUL macro for multiplication to work around Clang incompatibility
UPSTREAM: crypto, x86: aesni - fix token pasting for clang
UPSTREAM: x86/kbuild: Use cc-option to enable -falign-{jumps/loops}
UPSTREAM: compiler, clang: properly override 'inline' for clang
UPSTREAM: compiler, clang: suppress warning for unused static inline functions
UPSTREAM: Kbuild: provide a __UNIQUE_ID for clang
UPSTREAM: modules: mark __inittest/__exittest as __maybe_unused
BACKPORT: kbuild: Add support to generate LLVM assembly files
UPSTREAM: kbuild: use -Oz instead of -Os when using clang
BACKPORT: kbuild, LLVMLinux: Add -Werror to cc-option to support clang
UPSTREAM: kbuild: drop -Wno-unknown-warning-option from clang options
UPSTREAM: kbuild: fix asm-offset generation to work with clang
UPSTREAM: kbuild: consolidate redundant sed script ASM offset generation
UPSTREAM: kbuild: Consolidate header generation from ASM offset information
UPSTREAM: kbuild: clang: add -no-integrated-as to KBUILD_[AC]FLAGS
UPSTREAM: kbuild: Add better clang cross build support
FROMLIST: tracing: Add support for preempt and irq enable/disable events
FROMLIST: tracing: Prepare to add preempt and irq trace events
ANDROID: binder: fix transaction leak.
ANDROID: binder: Add tracing for binder priority inheritance.
f2fs: catch up to v4.14-rc1
UPSTREAM: cpufreq: schedutil: use now as reference when aggregating shared policy requests
ANDROID: add script to fetch android kernel config fragments
f2fs: reorganize stat information
f2fs: clean up flush/discard command namings
f2fs: check in-memory sit version bitmap
f2fs: check in-memory nat version bitmap
f2fs: check in-memory block bitmap
f2fs: introduce FI_ATOMIC_COMMIT
f2fs: clean up with list_{first, last}_entry
f2fs: return fs_trim if there is no candidate
f2fs: avoid needless checkpoint in f2fs_trim_fs
f2fs: relax async discard commands more
f2fs: drop exist_data for inline_data when truncated to 0
f2fs: don't allow encrypted operations without keys
f2fs: show the max number of atomic operations
f2fs: get io size bit from mount option
f2fs: support IO alignment for DATA and NODE writes
f2fs: add submit_bio tracepoint
f2fs: reassign new segment for mode=lfs
f2fs: fix a missing discard prefree segments
f2fs: use rb_entry_safe
f2fs: add a case of no need to read a page in write begin
f2fs: fix a problem of using memory after free
f2fs: remove unneeded condition
f2fs: don't cache nat entry if out of memory
f2fs: remove unused values in recover_fsync_data
f2fs: support async discard based on v4.9
f2fs: resolve op and op_flags confilcts
f2fs: remove wrong backported codes
FROMLIST: binder: fix use-after-free in binder_transaction()
UPSTREAM: ipv6: fib: Unlink replaced routes from their nodes
f2fs: fix a missing size change in f2fs_setattr
f2fs: fix to access nullified flush_cmd_control pointer
f2fs: free meta pages if sanity check for ckpt is failed
f2fs: detect wrong layout
f2fs: call sync_fs when f2fs is idle
Revert "f2fs: use percpu_counter for # of dirty pages in inode"
f2fs: return AOP_WRITEPAGE_ACTIVATE for writepage
f2fs: do not activate auto_recovery for fallocated i_size
f2fs: fix 32-bit build
f2fs: fix incorrect free inode count in ->statfs
f2fs: drop duplicate header timer.h
f2fs: fix wrong AUTO_RECOVER condition
f2fs: do not recover i_size if it's valid
f2fs: fix fdatasync
f2fs: fix to account total free nid correctly
f2fs: fix an infinite loop when flush nodes in cp
f2fs: don't wait writeback for datas during checkpoint
f2fs: fix wrong written_valid_blocks counting
f2fs: avoid BG_GC in f2fs_balance_fs
f2fs: fix redundant block allocation
f2fs: use err for f2fs_preallocate_blocks
f2fs: support multiple devices
f2fs: allow dio read for LFS mode
f2fs: revert segment allocation for direct IO
f2fs: return directly if block has been removed from the victim
Revert "f2fs: do not recover from previous remained wrong dnodes"
f2fs: remove checkpoint in f2fs_freeze
f2fs: assign segments correctly for direct_io
f2fs: fix wrong i_atime recovery
f2fs: record inode updating status correctly
f2fs: Trace reset zone events
f2fs: Reset sequential zones on zoned block devices
f2fs: Cache zoned block devices zone type
f2fs: Do not allow adaptive mode for host-managed zoned block devices
f2fs: Always enable discard for zoned blocks devices
f2fs: Suppress discard warning message for zoned block devices
f2fs: Check zoned block feature for host-managed zoned block devices
f2fs: Use generic zoned block device terminology
f2fs: Add missing break in switch-case
f2fs: avoid infinite loop in the EIO case on recover_orphan_inodes
f2fs: report error of f2fs_fill_dentries
fs/crypto: catch up 4.9-rc6
f2fs: hide a maybe-uninitialized warning
f2fs: remove percpu_count due to performance regression
f2fs: make clean inodes when flushing inode page
f2fs: keep dirty inodes selectively for checkpoint
f2fs: Replace CURRENT_TIME_SEC with current_time() for inode timestamps
f2fs: use BIO_MAX_PAGES for bio allocation
f2fs: declare static function for __build_free_nids
f2fs: call f2fs_balance_fs for setattr
f2fs: count dirty inodes to flush node pages during checkpoint
f2fs: avoid casted negative value as shrink count
f2fs: don't interrupt free nids building during nid allocation
f2fs: clean up free nid list operations
f2fs: split free nid list
f2fs: clear nlink if fail to add_link
f2fs: fix sparse warnings
f2fs: fix error handling in fsync_node_pages
f2fs: fix to update largest extent under lock
f2fs: be aware of extent beyond EOF in fiemap
f2fs: don't miss any f2fs_balance_fs cases
f2fs: add missing f2fs_balance_fs in f2fs_zero_range
f2fs: give a chance to detach from dirty list
f2fs: fix to release discard entries during checkpoint
f2fs: exclude free nids building and allocation
f2fs: fix to determine start_cp_addr by sbi->cur_cp_pack
f2fs: fix overflow due to condition check order
posix_acl: Clear SGID bit when setting file permissions
f2fs: fix wrong sum_page pointer in f2fs_gc
f2fs: backport from (4c1fad64 - Merge tag 'for-f2fs-4.9' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs)
Revert "ANDROID: sched/tune: Initialize raw_spin_lock in boosted_groups"
BACKPORT: partial: mm, oom_reaper: do not mmput synchronously from the oom reaper context
FROMLIST: android: binder: Don't get mm from task
FROMLIST: android: binder: Remove unused vma argument
FROMLIST: android: binder: Drop lru lock in isolate callback
ANDROID: configs: remove config fragments
drivers: cpufreq_interactive: handle error for module load fail
UPSTREAM: Fix build break in fork.c when THREAD_SIZE < PAGE_SIZE
ANDROID: sdcardfs: Add missing break
ANDROID: Sdcardfs: Move gid derivation under flag
ANDROID: mnt: Fix freeing of mount data
drivers: cpufreq: checks to avoid kernel crash in cpufreq_interactive
ANDROID: Use sk_uid to replace uid get from socket file
ANDROID: nf: xt_qtaguid: fix handling for cases where tunnels are used.
Revert "ANDROID: Use sk_uid to replace uid get from socket file"
ANDROID: fiq_debugger: Fix minor bug in code
ANDROID: cpufreq-dt: Set sane defaults for schedutil rate limits
BACKPORT: cpufreq: schedutil: Use policy-dependent transition delays
FROMLIST: binder: fix an ret value override
FROMLIST: binder: fix memory corruption in binder_transaction binder
sched: WALT: fix window mis-alignment
sched: EAS: kill incorrect nohz idle cpu kick
sched: EAS: fix incorrect energy delta calculation due to rounding error
sched: EAS/WALT: take into account of waking task's load
cpufreq: sched: WALT: don't apply capacity margin twice
sched: WALT: fix potential overflow
sched: EAS: schedfreq: fix CPU util over estimation
sched: EAS/WALT: use cr_avg instead of prev_runnable_sum
sched: WALT: fix broken cumulative runnable average accounting
sched: deadline: WALT: account cumulative runnable avg
FROMLIST: android: binder: Add page usage in binder stats
FROMLIST: android: binder: Add shrinker tracepoints
FROMLIST: android: binder: Add global lru shrinker to binder
FROMLIST: android: binder: Move buffer out of area shared with user space
FROMLIST: android: binder: Add allocator selftest
FROMLIST: android: binder: Refactor prev and next buffer into a helper function
android: android-base.config: enable IP6_NF_MATCH_RPFILTER
UPSTREAM: cpufreq: schedutil: Use unsigned int for iowait boost
UPSTREAM: cpufreq: schedutil: Make iowait boost more energy efficient
ANDROID: NFC: st21nfca: Fix memory OOB and leak issues in connectivity events handler
ANDROID: check dir value of xfrm_userpolicy_id
ANDROID: NFC: Fix possible memory corruption when handling SHDLC I-Frame commands
ANDROID: nfc: fdp: Fix possible buffer overflow in WCS4000 NFC driver
ANDROID: NFC: st21nfca: Fix out of bounds kernel access when handling ATR_REQ
UPSTREAM: usb: dwc3: gadget: don't send extra ZLP
BACKPORT: usb: dwc3: gadget: handle request->zero
ANDROID: usb: gadget: assign no-op request complete callbacks
ANDROID: usb: gadget: configfs: fix null ptr in android_disconnect
ANDROID: uid_sys_stats: Fix implicit declaration of get_cmdline()
uid_sys_stats: log task io with a debug flag
ANDROID: Use sk_uid to replace uid get from socket file
UPSTREAM: arm64: smp: Prevent raw_smp_processor_id() recursion
UPSTREAM: arm64: restore get_current() optimisation
ANDROID: arm64: Fix a copy-paste error in prior init_thread_info build fix
UPSTREAM: locking: avoid passing around 'thread_info' in mutex debugging code
ANDROID: arm64: fix undeclared 'init_thread_info' error
UPSTREAM: kdb: use task_cpu() instead of task_thread_info()->cpu
ANDROID: keychord: Fix for a memory leak in keychord.
ANDROID: keychord: Fix races in keychord_write.
Use %zu to print resid (size_t).
ANDROID: keychord: Fix a slab out-of-bounds read.
ANDROID: binder: don't queue async transactions to thread.
ANDROID: binder: don't enqueue death notifications to thread todo.
ANDROID: binder: call poll_wait() unconditionally.
android: configs: move quota-related configs to recommended
BACKPORT: arm64: split thread_info from task stack
UPSTREAM: arm64: assembler: introduce ldr_this_cpu
UPSTREAM: arm64: make cpu number a percpu variable
UPSTREAM: arm64: smp: prepare for smp_processor_id() rework
BACKPORT: arm64: move sp_el0 and tpidr_el1 into cpu_suspend_ctx
UPSTREAM: arm64: prep stack walkers for THREAD_INFO_IN_TASK
UPSTREAM: arm64: unexport walk_stackframe
UPSTREAM: arm64: traps: simplify die() and __die()
UPSTREAM: arm64: factor out current_stack_pointer
BACKPORT: arm64: asm-offsets: remove unused definitions
UPSTREAM: arm64: thread_info remove stale items
UPSTREAM: thread_info: include <current.h> for THREAD_INFO_IN_TASK
UPSTREAM: thread_info: factor out restart_block
UPSTREAM: kthread: Pin the stack via try_get_task_stack()/put_task_stack() in to_live_kthread() function
UPSTREAM: sched/core: Add try_get_task_stack() and put_task_stack()
UPSTREAM: sched/core: Allow putting thread_info into task_struct
UPSTREAM: printk: when dumping regs, show the stack, not thread_info
UPSTREAM: fix up initial thread stack pointer vs thread_info confusion
UPSTREAM: Clarify naming of thread info/stack allocators
ANDROID: sdcardfs: override credential for ioctl to lower fs
ANDROID: binder: Don't BUG_ON(!spin_is_locked()).
sched/fair: Add a backup_cpu to find_best_target
sched/fair: Try to estimate possible idle states.
sched/fair: Sync task util before EAS wakeup
Revert "sched/fair: ensure utilization signals are synchronized before use"
sched/fair: kick nohz idle balance for misfit task
sched/fair: Update signals of nohz cpus if we are going idle
events: add tracepoint for find_best_target
sched/fair: streamline find_best_target heuristics
UPSTREAM: af_key: Fix sadb_x_ipsecrequest parsing
ANDROID: lowmemorykiller: Add tgid to kill message
Revert "proc: smaps: Allow smaps access for CAP_SYS_RESOURCE"
ANDROID: android-verity: mark dev as rw for linear target
ANDROID: sdcardfs: Remove unnecessary lock
ANDROID: binder: don't check prio permissions on restore.
Add BINDER_GET_NODE_DEBUG_INFO ioctl
UPSTREAM: cpufreq: schedutil: Trace frequency only if it has changed
UPSTREAM: cpufreq: schedutil: Avoid reducing frequency of busy CPUs prematurely
UPSTREAM: cpufreq: schedutil: Refactor sugov_next_freq_shared()
UPSTREAM: cpufreq: schedutil: Fix per-CPU structure initialization in sugov_start()
UPSTREAM: cpufreq: schedutil: Pass sg_policy to get_next_freq()
UPSTREAM: cpufreq: schedutil: move cached_raw_freq to struct sugov_policy
UPSTREAM: cpufreq: schedutil: Rectify comment in sugov_irq_work() function
UPSTREAM: cpufreq: schedutil: irq-work and mutex are only used in slow path
UPSTREAM: cpufreq: schedutil: enable fast switch earlier
UPSTREAM: cpufreq: schedutil: Avoid indented labels
ANDROID: binder: add RT inheritance flag to node.
ANDROID: binder: improve priority inheritance.
ANDROID: binder: add min sched_policy to node.
ANDROID: binder: add support for RT prio inheritance.
ANDROID: binder: push new transactions to waiting threads.
ANDROID: binder: remove proc waitqueue
FROMLIST: binder: remove global binder lock
FROMLIST: binder: fix death race conditions
FROMLIST: binder: protect against stale pointers in print_binder_transaction
FROMLIST: binder: protect binder_ref with outer lock
FROMLIST: binder: use inner lock to protect thread accounting
FROMLIST: binder: protect transaction_stack with inner lock.
FROMLIST: binder: protect proc->threads with inner_lock
FROMLIST: binder: protect proc->nodes with inner lock
FROMLIST: binder: add spinlock to protect binder_node
FROMLIST: binder: add spinlocks to protect todo lists
FROMLIST: binder: use inner lock to sync work dq and node counts
FROMLIST: binder: introduce locking helper functions
FROMLIST: binder: use node->tmp_refs to ensure node safety
FROMLIST: binder: refactor binder ref inc/dec for thread safety
FROMLIST: binder: make sure accesses to proc/thread are safe
FROMLIST: binder: make sure target_node has strong ref
FROMLIST: binder: guarantee txn complete / errors delivered in-order
FROMLIST: binder: refactor binder_pop_transaction
FROMLIST: binder: use atomic for transaction_log index
FROMLIST: binder: add more debug info when allocation fails.
FROMLIST: binder: protect against two threads freeing buffer
FROMLIST: binder: remove dead code in binder_get_ref_for_node
FROMLIST: binder: don't modify thread->looper from other threads
FROMLIST: binder: avoid race conditions when enqueuing txn
FROMLIST: binder: refactor queue management in binder_thread_read
FROMLIST: binder: add log information for binder transaction failures
FROMLIST: binder: make binder_last_id an atomic
FROMLIST: binder: change binder_stats to atomics
FROMLIST: binder: add protection for non-perf cases
FROMLIST: binder: remove binder_debug_no_lock mechanism
FROMLIST: binder: move binder_alloc to separate file
FROMLIST: binder: separate out binder_alloc functions
FROMLIST: binder: remove unneeded cleanup code
FROMLIST: binder: separate binder allocator structure from binder proc
FROMLIST: binder: Use wake up hint for synchronous transactions.
Revert "android: binder: move global binder state into context struct."
sched: walt: fix window misalignment when HZ=300
ANDROID: android-base.cfg: remove CONFIG_CGROUP_DEBUG
ANDROID: sdcardfs: use mount_nodev and fix a issue in sdcardfs_kill_sb
UPSTREAM: selinux: enable genfscon labeling for tracefs
UPSTREAM: drivers/perf: arm-pmu: fix RCU usage on pmu resume from low-power
UPSTREAM: drivers/perf: arm_pmu: implement CPU_PM notifier
ANDROID: squashfs: Fix endianness issue
ANDROID: squashfs: Fix signed division issue
UPSTREAM: usb: gadget: f_fs: avoid out of bounds access on comp_desc
UPSTREAM: bpf: don't let ldimm64 leak map addresses on unprivileged
BACKPORT: ext4: fix data exposure after a crash
ANDROID: sdcardfs: remove dead function open_flags_to_access_mode()
ANDROID: android-base.cfg: split out arm64-specific configs
usb: gadget: f_fs: Fix possibe deadlock
ANDROID: uid_sys_stats: check previous uid_entry before call find_or_register_uid
ANDROID: sdcardfs: d_splice_alias can return error values
android: base-cfg: disable CONFIG_NFS_FS and CONFIG_NFSD
schedstats/eas: guard properly to avoid breaking non-smp schedstats users
BACKPORT: f2fs: sanity check size of nat and sit cache
FROMLIST: f2fs: sanity check checkpoint segno and blkoff
sched/tune: don't use schedtune before it is ready
sched/fair: use SCHED_CAPACITY_SCALE for energy normalization
sched/{fair,tune}: use reciprocal_value to compute boost margin
sched/tune: Initialize raw_spin_lock in boosted_groups
sched/tune: report when SchedTune has not been initialized
sched/tune: fix sched_energy_diff tracepoint
sched/tune: increase group count to 5
cpufreq/schedutil: use boosted_cpu_util for PELT to match WALT
sched/fair: Fix sched_group_energy() to support per-cpu capacity states
sched/fair: discount task contribution to find CPU with lowest utilization
sched/fair: ensure utilization signals are synchronized before use
sched/fair: remove task util from own cpu when placing waking task
trace:sched: Make util_avg in load_avg trace reflect PELT/WALT as used
sched/fair: Add eas (& cas) specific rq, sd and task stats
sched/core: Fix PELT jump to max OPP upon util increase
sched: EAS & 'single cpu per cluster'/cpu hotplug interoperability
UPSTREAM: sched/core: Fix group_entity's share update
UPSTREAM: sched/fair: Fix calc_cfs_shares() fixed point arithmetics width confusion
UPSTREAM: sched/fair: Fix incorrect task group ->load_avg
UPSTREAM: sched/fair: Fix effective_load() to consistently use smoothed load
UPSTREAM: sched/fair: Propagate asynchrous detach
UPSTREAM: sched/fair: Propagate load during synchronous attach/detach
UPSTREAM: sched/fair: Fix hierarchical order in rq->leaf_cfs_rq_list
BACKPORT: sched/fair: Factorize PELT update
UPSTREAM: sched/fair: Factorize attach/detach entity
UPSTREAM: sched/fair: Improve PELT stuff some more
UPSTREAM: sched/fair: Apply more PELT fixes
UPSTREAM: sched/fair: Fix post_init_entity_util_avg() serialization
BACKPORT: sched/fair: Initiate a new task's util avg to a bounded value
sched/fair: Simplify idle_idx handling in select_idle_sibling()
sched/fair: refactor find_best_target() for simplicity
sched/fair: Change cpu iteration order in find_best_target()
sched/core: Add first cpu w/ max/min orig capacity to root domain
sched/core: Remove remnants of commit fd5c98da1a42
sched: Remove sysctl_sched_is_big_little
sched/fair: Code !is_big_little path into select_energy_cpu_brute()
EAS: sched/fair: Re-integrate 'honor sync wakeups' into wakeup path
Fixup!: sched/fair.c: Set SchedTune specific struct energy_env.task
sched/fair: Energy-aware wake-up task placement
sched/fair: Add energy_diff dead-zone margin
sched/fair: Decommission energy_aware_wake_cpu()
sched/fair: Do not force want_affine eq. true if EAS is enabled
arm64: Set SD_ASYM_CPUCAPACITY sched_domain flag on DIE level
UPSTREAM: sched/fair: Fix incorrect comment for capacity_margin
UPSTREAM: sched/fair: Avoid pulling tasks from non-overloaded higher capacity groups
UPSTREAM: sched/fair: Add per-CPU min capacity to sched_group_capacity
UPSTREAM: sched/fair: Consider spare capacity in find_idlest_group()
UPSTREAM: sched/fair: Compute task/cpu utilization at wake-up correctly
UPSTREAM: sched/fair: Let asymmetric CPU configurations balance at wake-up
UPSTREAM: sched/core: Enable SD_BALANCE_WAKE for asymmetric capacity systems
UPSTREAM: sched/core: Pass child domain into sd_init()
UPSTREAM: sched/core: Introduce SD_ASYM_CPUCAPACITY sched_domain topology flag
UPSTREAM: sched/core: Remove unnecessary NULL-pointer check
UPSTREAM: sched/fair: Optimize find_idlest_cpu() when there is no choice
BACKPORT: sched/fair: Make the use of prev_cpu consistent in the wakeup path
UPSTREAM: sched/core: Fix power to capacity renaming in comment
Partial Revert: "WIP: sched: Add cpu capacity awareness to wakeup balancing"
Revert "WIP: sched: Consider spare cpu capacity at task wake-up"
FROM-LIST: cpufreq: schedutil: Redefine the rate_limit_us tunable
cpufreq: schedutil: add up/down frequency transition rate limits
trace/sched: add rq utilization signal for WALT
sched/cpufreq: make schedutil use WALT signal
sched: cpufreq: use rt_avg as estimate of required RT CPU capacity
cpufreq: schedutil: move slow path from workqueue to SCHED_FIFO task
BACKPORT: kthread: allow to cancel kthread work
sched/cpufreq: fix tunables for schedfreq governor
BACKPORT: cpufreq: schedutil: New governor based on scheduler utilization data
sched: backport cpufreq hooks from 4.9-rc4
ANDROID: Kconfig: add depends for UID_SYS_STATS
ANDROID: hid: uhid: implement refcount for open and close
Revert "ext4: require encryption feature for EXT4_IOC_SET_ENCRYPTION_POLICY"
ANDROID: mnt: Fix next_descendent
ANDROID: uid_sys_stats: defer io stats calulation for dead tasks
ANDROID: AVB: Fix linter errors.
ANDROID: AVB: Fix invalidate_vbmeta_submit().
ANDROID: sdcardfs: Check for NULL in revalidate
ANDROID: AVB: Only invalidate vbmeta when told to do so.
ANDROID: sdcardfs: Move top to its own struct
ANDROID: lowmemorykiller: account for unevictable pages
ANDROID: usb: gadget: fix NULL pointer issue in mtp_read()
ANDROID: usb: f_mtp: return error code if transfer error in receive_file_work function
ANDROID: android-base.cfg: remove spurious CONFIG_MODULES line
ANDROID: memory_state_time: fix undefined behavior with missing DT properties
ANDROID: rfkill: fix unused function warning
ANDROID: make PF_KEY SHA256 use RFC-compliant truncation.
ANDROID: sdcardfs: fix sdcardfs_destroy_inode for the inode RCU approach
ANDROID: android-base.cfg: remove NETFILTER_XT_MATCH_QUOTA2_LOG
ANDROID: sdcardfs: Don't iput if we didn't igrab
ANDROID: Add untag hacks to inet_release function
ANDROID: android-base.cfg: remove USB_OTG_WAKELOCK
ANDROID: android-base.cfg: remove defunct options
ANDROID: arm64: suspend: Restore the UAO state
ANDROID: usb: gadget: f_audio_source: disable the CPU C-states upon playback
ANDROID: usb: gadget: f_mtp: Set 0xFFFFFFFF in mtp header ContainerLength field
net: pppolac/pppopns: Add back the msg_flags
ANDROID: uid_sys_stats: fix access of task_uid(task)
BACKPORT: f2fs: sanity check log_blocks_per_seg
ANDROID: sdcardfs: Call lower fs's revalidate
ANDROID: sdcardfs: Avoid setting GIDs outside of valid ranges
ANDROID: sdcardfs: Copy meta-data from lower inode
Revert "Revert "Android: sdcardfs: Don't do d_add for lower fs""
ANDROID: sdcardfs: Use filesystem specific hash
ANDROID: AVB error handler to invalidate vbmeta partition.
ANDROID: Update init/do_mounts_dm.c to the latest ChromiumOS version.
Revert "[RFC]cgroup: Change from CAP_SYS_NICE to CAP_SYS_RESOURCE for cgroup migration permissions"
Revert "USB: gadget: u_ether: Fix data stall issue in RNDIS tethering mode"
ANDROID: uid_sys_stats: reduce update_io_stats overhead
UPSTREAM: char: lack of bool string made CONFIG_DEVPORT always on
UPSTREAM: char: Drop bogus dependency of DEVPORT on !M68K
Revert "Android: sdcardfs: Don't do d_add for lower fs"
ANDROID: usb: gadget: fix MTP enumeration issue under super speed mode
Android: sdcardfs: Don't complain in fixup_lower_ownership
Android: sdcardfs: Don't do d_add for lower fs
ANDROID: sdcardfs: ->iget fixes
Android: sdcardfs: Change cache GID value
BACKPORT: [UPSTREAM] ext2: convert to mbcache2
BACKPORT [UPSTREAM] ext4: convert to mbcache2
BACKPORT: [UPSTREAM] mbcache2: reimplement mbcache
UPSTREAM: net: socket: Make unnecessarily global sockfs_setattr() static
UPSTREAM: net: ipv4: Don't crash if passing a null sk to ip_do_redirect.
UPSTREAM: net/packet: fix overflow in check for priv area size
Revert "Revert "Revert "CHROMIUM: android: binder: Fix potential scheduling-while-atomic"""
ANDROID: sdcardfs: Directly pass lower file for mmap
UPSTREAM: checkpatch: special audit for revert commit line
UPSTREAM: PM / sleep: make PM notifiers called symmetrically
Revert "Revert "CHROMIUM: android: binder: Fix potential scheduling-while-atomic""
BACKPORT: arm64: dts: juno: fix cluster sleep state entry latency on all SoC versions
staging: android: ashmem: lseek failed due to no FMODE_LSEEK.
ANDROID: sdcardfs: update module info
ANDROID: sdcardfs: use d_splice_alias
ANDROID: sdcardfs: add read_iter/write_iter opeations
ANDROID: sdcardfs: fix ->llseek to update upper and lower offset
ANDROID: sdcardfs: copy lower inode attributes in ->ioctl
ANDROID: sdcardfs: remove unnecessary call to do_munmap
Merge 4.4.59 into android-4.4
UPSTREAM: ipv6 addrconf: implement RFC7559 router solicitation backoff
android: base-cfg: enable CONFIG_INET_DIAG_DESTROY
ANDROID: android-base.cfg: add CONFIG_MODULES option
ANDROID: android-base.cfg: add CONFIG_IKCONFIG option
ANDROID: android-base.cfg: properly sort the file
ANDROID: binder: add hwbinder,vndbinder to BINDER_DEVICES.
ANDROID: sort android-recommended.cfg
UPSTREAM: config/android: Remove CONFIG_IPV6_PRIVACY
UPSTREAM: config: android: set SELinux as default security mode
config: android: move device mapper options to recommended
ANDROID: ARM64: Allow to choose appended kernel image
UPSTREAM: arm64: vdso: constify vm_special_mapping used for aarch32 vectors page
UPSTREAM: arm64: vdso: add __init section marker to alloc_vectors_page
UPSTREAM: ARM: 8597/1: VDSO: put RO and RO after init objects into proper sections
UPSTREAM: arm64: Add support for CLOCK_MONOTONIC_RAW in clock_gettime() vDSO
UPSTREAM: arm64: Refactor vDSO time functions
UPSTREAM: arm64: fix vdso-offsets.h dependency
UPSTREAM: kbuild: drop FORCE from PHONY targets
UPSTREAM: mm: add PHYS_PFN, use it in __phys_to_pfn()
UPSTREAM: ARM: 8476/1: VDSO: use PTR_ERR_OR_ZERO for vma check
ANDROID: sdcardfs: Fix style issues in macros
ANDROID: sdcardfs: Use seq_puts over seq_printf
ANDROID: sdcardfs: Use to kstrout
ANDROID: sdcardfs: Use pr_[...] instead of printk
ANDROID: sdcardfs: remove unneeded null check
ANDROID: sdcardfs: Fix style issues with comments
ANDROID: sdcardfs: Fix formatting
ANDROID: sdcardfs: correct order of descriptors
fix the deadlock in xt_qtaguid when enable DDEBUG
net: ipv6: Add sysctl for minimum prefix len acceptable in RIOs.
ANDROID: mmc: core: export emmc revision
BACKPORT: mmc: core: Export device lifetime information through sysfs
ANDROID: android-verity: do not compile as independent module
ANDROID: sched: fix duplicate sched_group_energy const specifiers
config: disable CONFIG_USELIB and CONFIG_FHANDLE
ANDROID: power: align wakeup_sources format
ANDROID: dm: android-verity: allow disable dm-verity for Treble VTS
uid_sys_stats: change to use rt_mutex
ANDROID: vfs: user permission2 in notify_change2
ANDROID: sdcardfs: Fix gid issue
ANDROID: sdcardfs: Use tabs instead of spaces in multiuser.h
ANDROID: sdcardfs: Remove uninformative prints
ANDROID: sdcardfs: move path_put outside of spinlock
ANDROID: sdcardfs: Use case insensitive hash function
ANDROID: sdcardfs: declare MODULE_ALIAS_FS
ANDROID: sdcardfs: Get the blocksize from the lower fs
ANDROID: sdcardfs: Use d_invalidate instead of drop_recurisve
ANDROID: sdcardfs: Switch to internal case insensitive compare
ANDROID: sdcardfs: Use spin_lock_nested
ANDROID: sdcardfs: Replace get/put with d_lock
ANDROID: sdcardfs: rate limit warning print
ANDROID: sdcardfs: Fix case insensitive lookup
ANDROID: uid_sys_stats: account for fsync syscalls
ANDROID: sched: add a counter to track fsync
ANDROID: uid_sys_stats: fix negative write bytes.
ANDROID: uid_sys_stats: allow writing same state
ANDROID: uid_sys_stats: rename uid_cputime.c to uid_sys_stats.c
ANDROID: uid_cputime: add per-uid IO usage accounting
DTB: Add EAS compatible Juno Energy model to 'juno.dts'
arm64: dts: juno: Add idle-states to device tree
ANDROID: Replace spaces by '_' for some android filesystem tracepoints.
usb: gadget: f_accessory: Fix for UsbAccessory clean unbind.
android: binder: move global binder state into context struct.
android: binder: add padding to binder_fd_array_object.
binder: use group leader instead of open thread
nf: IDLETIMER: Use fullsock when querying uid
nf: IDLETIMER: Fix use after free condition during work
ANDROID: dm: android-verity: fix table_make_digest() error handling
ANDROID: usb: gadget: function: Fix commenting style
cpufreq: interactive governor drops bits in time calculation
ANDROID: sdcardfs: support direct-IO (DIO) operations
ANDROID: sdcardfs: implement vm_ops->page_mkwrite
ANDROID: sdcardfs: Don't bother deleting freelist
ANDROID: sdcardfs: Add missing path_put
ANDROID: sdcardfs: Fix incorrect hash
ANDROID: ext4 crypto: Disables zeroing on truncation when there's no key
ANDROID: ext4: add a non-reversible key derivation method
ANDROID: ext4: allow encrypting filenames using HEH algorithm
ANDROID: arm64/crypto: add ARMv8-CE optimized poly_hash algorithm
ANDROID: crypto: heh - factor out poly_hash algorithm
ANDROID: crypto: heh - Add Hash-Encrypt-Hash (HEH) algorithm
ANDROID: crypto: gf128mul - Add ble multiplication functions
ANDROID: crypto: gf128mul - Refactor gf128 overflow macros and tables
UPSTREAM: crypto: gf128mul - Zero memory when freeing multiplication table
ANDROID: crypto: shash - Add crypto_grab_shash() and crypto_spawn_shash_alg()
ANDROID: crypto: allow blkcipher walks over ablkcipher data
UPSTREAM: arm/arm64: crypto: assure that ECB modes don't require an IV
ANDROID: Refactor fs readpage/write tracepoints.
ANDROID: export security_path_chown
Squashfs: optimize reading uncompressed data
Squashfs: implement .readpages()
Squashfs: replace buffer_head with BIO
Squashfs: refactor page_actor
Squashfs: remove the FILE_CACHE option
ANDROID: android-recommended.cfg: CONFIG_CPU_SW_DOMAIN_PAN=y
FROMLIST: 9p: fix a potential acl leak
BACKPORT: posix_acl: Clear SGID bit when setting file permissions
UPSTREAM: udp: properly support MSG_PEEK with truncated buffers
UPSTREAM: arm64: Allow hw watchpoint of length 3,5,6 and 7
BACKPORT: arm64: hw_breakpoint: Handle inexact watchpoint addresses
UPSTREAM: arm64: Allow hw watchpoint at varied offset from base address
BACKPORT: hw_breakpoint: Allow watchpoint of length 3,5,6 and 7
ANDROID: sdcardfs: Switch strcasecmp for internal call
ANDROID: sdcardfs: switch to full_name_hash and qstr
ANDROID: sdcardfs: Add GID Derivation to sdcardfs
ANDROID: sdcardfs: Remove redundant operation
ANDROID: sdcardfs: add support for user permission isolation
ANDROID: sdcardfs: Refactor configfs interface
ANDROID: sdcardfs: Allow non-owners to touch
ANDROID: binder: fix format specifier for type binder_size_t
ANDROID: fs: Export vfs_rmdir2
ANDROID: fs: Export free_fs_struct and set_fs_pwd
BACKPORT: Input: xpad - validate USB endpoint count during probe
BACKPORT: Input: xpad - fix oops when attaching an unknown Xbox One gamepad
ANDROID: mnt: remount should propagate to slaves of slaves
ANDROID: sdcardfs: Switch ->d_inode to d_inode()
ANDROID: sdcardfs: Fix locking issue with permision fix up
ANDROID: sdcardfs: Change magic value
ANDROID: sdcardfs: Use per mount permissions
ANDROID: sdcardfs: Add gid and mask to private mount data
ANDROID: sdcardfs: User new permission2 functions
ANDROID: vfs: Add setattr2 for filesystems with per mount permissions
ANDROID: vfs: Add permission2 for filesystems with per mount permissions
ANDROID: vfs: Allow filesystems to access their private mount data
ANDROID: mnt: Add filesystem private data to mount points
ANDROID: sdcardfs: Move directory unlock before touch
ANDROID: sdcardfs: fix external storage exporting incorrect uid
ANDROID: sdcardfs: Added top to sdcardfs_inode_info
ANDROID: sdcardfs: Switch package list to RCU
ANDROID: sdcardfs: Fix locking for permission fix up
ANDROID: sdcardfs: Check for other cases on path lookup
ANDROID: sdcardfs: override umask on mkdir and create
arm64: kernel: Fix build warning
DEBUG: sched/fair: Fix sched_load_avg_cpu events for task_groups
DEBUG: sched/fair: Fix missing sched_load_avg_cpu events
UPSTREAM: l2tp: fix racy SOCK_ZAPPED flag check in l2tp_ip{,6}_bind()
UPSTREAM: packet: fix race condition in packet_set_ring
UPSTREAM: netlink: Fix dump skb leak/double free
UPSTREAM: net: avoid signed overflows for SO_{SND|RCV}BUFFORCE
MIPS: Prevent "restoration" of MSA context in non-MSA kernels
net: socket: don't set sk_uid to garbage value in ->setattr()
ANDROID: configs: CONFIG_ARM64_SW_TTBR0_PAN=y
UPSTREAM: arm64: Disable PAN on uaccess_enable()
UPSTREAM: arm64: Enable CONFIG_ARM64_SW_TTBR0_PAN
UPSTREAM: arm64: xen: Enable user access before a privcmd hvc call
UPSTREAM: arm64: Handle faults caused by inadvertent user access with PAN enabled
BACKPORT: arm64: Disable TTBR0_EL1 during normal kernel execution
BACKPORT: arm64: Introduce uaccess_{disable,enable} functionality based on TTBR0_EL1
BACKPORT: arm64: Factor out TTBR0_EL1 post-update workaround into a specific asm macro
BACKPORT: arm64: Factor out PAN enabling/disabling into separate uaccess_* macros
UPSTREAM: arm64: alternative: add auto-nop infrastructure
UPSTREAM: arm64: barriers: introduce nops and __nops macros for NOP sequences
Revert "FROMLIST: arm64: Factor out PAN enabling/disabling into separate uaccess_* macros"
Revert "FROMLIST: arm64: Factor out TTBR0_EL1 post-update workaround into a specific asm macro"
Revert "FROMLIST: arm64: Introduce uaccess_{disable,enable} functionality based on TTBR0_EL1"
Revert "FROMLIST: arm64: Disable TTBR0_EL1 during normal kernel execution"
Revert "FROMLIST: arm64: Handle faults caused by inadvertent user access with PAN enabled"
Revert "FROMLIST: arm64: xen: Enable user access before a privcmd hvc call"
Revert "FROMLIST: arm64: Enable CONFIG_ARM64_SW_TTBR0_PAN"
ANDROID: sched/walt: fix build failure if FAIR_GROUP_SCHED=n
ANDROID: trace: net: use %pK for kernel pointers
ANDROID: android-base: Enable QUOTA related configs
net: ipv4: Don't crash if passing a null sk to ip_rt_update_pmtu.
net: inet: Support UID-based routing in IP protocols.
net: core: add UID to flows, rules, and routes
net: core: Add a UID field to struct sock.
Revert "net: core: Support UID-based routing."
UPSTREAM: efi/arm64: Don't apply MEMBLOCK_NOMAP to UEFI memory map mapping
UPSTREAM: arm64: mm: always take dirty state from new pte in ptep_set_access_flags
UPSTREAM: arm64: Implement pmdp_set_access_flags() for hardware AF/DBM
UPSTREAM: arm64: Fix typo in the pmdp_huge_get_and_clear() definition
UPSTREAM: arm64: enable CONFIG_DEBUG_RODATA by default
goldfish: enable CONFIG_INET_DIAG_DESTROY
sched/walt: kill {min,max}_capacity
sched: fix wrong truncation of walt_avg
build: fix build config kernel_dir
ANDROID: dm verity: add minimum prefetch size
build: add build server configs for goldfish
usb: gadget: Fix compilation problem with tx_qlen field
Conflicts:
Documentation/kasan.txt
Makefile
arch/arm64/Makefile
arch/arm64/boot/Makefile
arch/arm64/include/asm/assembler.h
arch/arm64/include/asm/cputype.h
arch/arm64/include/asm/efi.h
arch/arm64/include/asm/mmu_context.h
arch/arm64/include/asm/signal32.h
arch/arm64/include/asm/suspend.h
arch/arm64/include/asm/vdso_datapage.h
arch/arm64/kernel/asm-offsets.c
arch/arm64/kernel/cpufeature.c
arch/arm64/kernel/entry.S
arch/arm64/kernel/head.S
arch/arm64/kernel/insn.c
arch/arm64/kernel/io.c
arch/arm64/kernel/psci.c
arch/arm64/kernel/setup.c
arch/arm64/kernel/smp.c
arch/arm64/kernel/suspend.c
arch/arm64/kernel/traps.c
arch/arm64/kernel/vdso.c
arch/arm64/kernel/vdso/gettimeofday.S
arch/arm64/kernel/vmlinux.lds.S
arch/arm64/mm/cache.S
arch/arm64/mm/fault.c
arch/arm64/mm/kasan_init.c
arch/arm64/mm/mmu.c
arch/arm64/mm/proc.S
arch/x86/include/asm/thread_info.h
arch/x86/kernel/Makefile
arch/x86/kernel/kprobes/core.c
block/blk-core.c
build.config.common
drivers/Kconfig
drivers/Makefile
drivers/android/Makefile
drivers/android/binder.c
drivers/base/power/main.c
drivers/block/loop.c
drivers/clocksource/Kconfig
drivers/cpufreq/Kconfig
drivers/cpufreq/cpufreq-dt.c
drivers/gpu/drm/msm/msm_gem_submit.c
drivers/irqchip/Kconfig
drivers/irqchip/Makefile
drivers/md/Kconfig
drivers/md/Makefile
drivers/misc/Kconfig
drivers/misc/Makefile
drivers/misc/uid_sys_stats.c
drivers/scsi/ufs/ufshcd.c
drivers/scsi/ufs/ufshcd.h
drivers/staging/android/Kconfig
drivers/staging/android/Makefile
drivers/staging/android/fiq_debugger/fiq_watchdog.h
drivers/staging/android/ion/ion.c
drivers/staging/android/ion/ion_cma_heap.c
drivers/tee/optee/shm_pool.h
drivers/usb/dwc3/gadget.c
drivers/usb/gadget/configfs.c
drivers/usb/gadget/function/f_accessory.c
fs/exec.c
fs/ext4/crypto.c
fs/ext4/crypto_fname.c
fs/ext4/crypto_key.c
fs/ext4/ext4.h
fs/ext4/ext4_crypto.h
fs/f2fs/crypto_policy.c
fs/f2fs/data.c
fs/f2fs/f2fs.h
fs/f2fs/super.c
fs/proc/task_mmu.c
fs/sdcardfs/derived_perm.c
fs/sdcardfs/inode.c
fs/sdcardfs/main.c
fs/sdcardfs/sdcardfs.h
fs/squashfs/lz4_wrapper.c
include/linux/blkdev.h
include/linux/cpufreq.h
include/linux/dcache.h
include/linux/mmc/card.h
include/linux/mmc/mmc.h
include/linux/msm_mdp.h
include/linux/sched.h
include/linux/slab_def.h
include/linux/slub_def.h
include/linux/thread_info.h
include/trace/events/android_fs.h
include/trace/events/sched.h
include/uapi/linux/android/binder.h
include/uapi/linux/ipv6.h
include/uapi/linux/prctl.h
kernel/configs/android-base.config
kernel/configs/android-recommended.config
kernel/cpu.c
kernel/fork.c
kernel/sched/Makefile
kernel/sched/core.c
kernel/sched/cpufreq_sched.c
kernel/sched/cpufreq_schedutil.c
kernel/sched/fair.c
kernel/sched/rt.c
kernel/sched/sched.h
kernel/sched/stats.c
kernel/sched/walt.c
kernel/sys.c
kernel/sysctl.c
kernel/time/timekeeping.c
lib/Kconfig
lib/test_kasan.c
mm/kasan/Makefile
mm/kasan/kasan.c
mm/kasan/kasan.h
mm/kasan/report.c
mm/slab.c
mm/slab.h
mm/slub.c
net/ipv4/route.c
net/ipv4/tcp_ipv4.c
net/ipv4/xfrm4_policy.c
net/ipv6/route.c
net/netfilter/xt_IDLETIMER.c
net/netfilter/xt_qtaguid.c
net/netfilter/xt_quota2.c
net/socket.c
net/wireless/scan.c
scripts/Makefile.lib
scripts/checkpatch.pl
security/selinux/nlmsgtab.c
Skipped commit:
a08cafa7e0 ANDROID: ARM64: Allow to choose appended kernel image
Change-Id: I306e14a74d75f56cd39b5ad344f0f4440c26b52a
6157 lines
178 KiB
Prolog
Executable File
6157 lines
178 KiB
Prolog
Executable File
#!/usr/bin/perl -w
|
|
# (c) 2001, Dave Jones. (the file handling bit)
|
|
# (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit)
|
|
# (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite)
|
|
# (c) 2008-2010 Andy Whitcroft <apw@canonical.com>
|
|
# Licensed under the terms of the GNU GPL License version 2
|
|
|
|
use strict;
|
|
use POSIX;
|
|
use File::Basename;
|
|
use Cwd 'abs_path';
|
|
use Term::ANSIColor qw(:constants);
|
|
|
|
use constant BEFORE_SHORTTEXT => 0;
|
|
use constant IN_SHORTTEXT_BLANKLINE => 1;
|
|
use constant IN_SHORTTEXT => 2;
|
|
use constant AFTER_SHORTTEXT => 3;
|
|
use constant CHECK_NEXT_SHORTTEXT => 4;
|
|
use constant SHORTTEXT_LIMIT => 75;
|
|
|
|
my $P = $0;
|
|
my $D = dirname(abs_path($P));
|
|
|
|
my $V = '0.32';
|
|
|
|
use Getopt::Long qw(:config no_auto_abbrev);
|
|
|
|
my $quiet = 0;
|
|
my $tree = 1;
|
|
my $chk_signoff = 1;
|
|
my $chk_patch = 1;
|
|
my $chk_author = 1;
|
|
my $tst_only;
|
|
my $emacs = 0;
|
|
my $terse = 0;
|
|
my $showfile = 0;
|
|
my $file = 0;
|
|
my $check = 0;
|
|
my $check_orig = 0;
|
|
my $summary = 1;
|
|
my $mailback = 0;
|
|
my $summary_file = 0;
|
|
my $show_types = 0;
|
|
my $fix = 0;
|
|
my $fix_inplace = 0;
|
|
my $root;
|
|
my %debug;
|
|
my %camelcase = ();
|
|
my %use_type = ();
|
|
my @use = ();
|
|
my %ignore_type = ();
|
|
my @ignore = ();
|
|
my $help = 0;
|
|
my $configuration_file = ".checkpatch.conf";
|
|
my $max_line_length = 80;
|
|
my $ignore_perl_version = 0;
|
|
my $minimum_perl_version = 5.10.0;
|
|
my $min_conf_desc_length = 4;
|
|
my $spelling_file = "$D/spelling.txt";
|
|
my $codespell = 0;
|
|
my $codespellfile = "/usr/share/codespell/dictionary.txt";
|
|
my $color = 1;
|
|
my $qca_sign_off = 0;
|
|
my $codeaurora_sign_off = 0;
|
|
|
|
sub help {
|
|
my ($exitcode) = @_;
|
|
|
|
print << "EOM";
|
|
Usage: $P [OPTION]... [FILE]...
|
|
Version: $V
|
|
|
|
Options:
|
|
-q, --quiet quiet
|
|
--no-tree run without a kernel tree
|
|
--no-signoff do not check for 'Signed-off-by' line
|
|
--no-author do not check for unexpected authors
|
|
--patch treat FILE as patchfile (default)
|
|
--emacs emacs compile window format
|
|
--terse one line per report
|
|
--showfile emit diffed file position, not input file position
|
|
-f, --file treat FILE as regular source file
|
|
--subjective, --strict enable more subjective tests
|
|
--types TYPE(,TYPE2...) show only these comma separated message types
|
|
--ignore TYPE(,TYPE2...) ignore various comma separated message types
|
|
--max-line-length=n set the maximum line length, if exceeded, warn
|
|
--min-conf-desc-length=n set the min description length, if shorter, warn
|
|
--show-types show the message "types" in the output
|
|
--root=PATH PATH to the kernel tree root
|
|
--no-summary suppress the per-file summary
|
|
--mailback only produce a report in case of warnings/errors
|
|
--summary-file include the filename in summary
|
|
--debug KEY=[0|1] turn on/off debugging of KEY, where KEY is one of
|
|
'values', 'possible', 'type', and 'attr' (default
|
|
is all off)
|
|
--test-only=WORD report only warnings/errors containing WORD
|
|
literally
|
|
--fix EXPERIMENTAL - may create horrible results
|
|
If correctable single-line errors exist, create
|
|
"<inputfile>.EXPERIMENTAL-checkpatch-fixes"
|
|
with potential errors corrected to the preferred
|
|
checkpatch style
|
|
--fix-inplace EXPERIMENTAL - may create horrible results
|
|
Is the same as --fix, but overwrites the input
|
|
file. It's your fault if there's no backup or git
|
|
--ignore-perl-version override checking of perl version. expect
|
|
runtime errors.
|
|
--codespell Use the codespell dictionary for spelling/typos
|
|
(default:/usr/share/codespell/dictionary.txt)
|
|
--codespellfile Use this codespell dictionary
|
|
--color Use colors when output is STDOUT (default: on)
|
|
-h, --help, --version display this help and exit
|
|
|
|
When FILE is - read standard input.
|
|
EOM
|
|
|
|
exit($exitcode);
|
|
}
|
|
|
|
my $conf = which_conf($configuration_file);
|
|
if (-f $conf) {
|
|
my @conf_args;
|
|
open(my $conffile, '<', "$conf")
|
|
or warn "$P: Can't find a readable $configuration_file file $!\n";
|
|
|
|
while (<$conffile>) {
|
|
my $line = $_;
|
|
|
|
$line =~ s/\s*\n?$//g;
|
|
$line =~ s/^\s*//g;
|
|
$line =~ s/\s+/ /g;
|
|
|
|
next if ($line =~ m/^\s*#/);
|
|
next if ($line =~ m/^\s*$/);
|
|
|
|
my @words = split(" ", $line);
|
|
foreach my $word (@words) {
|
|
last if ($word =~ m/^#/);
|
|
push (@conf_args, $word);
|
|
}
|
|
}
|
|
close($conffile);
|
|
unshift(@ARGV, @conf_args) if @conf_args;
|
|
}
|
|
|
|
GetOptions(
|
|
'q|quiet+' => \$quiet,
|
|
'tree!' => \$tree,
|
|
'signoff!' => \$chk_signoff,
|
|
'patch!' => \$chk_patch,
|
|
'author!' => \$chk_author,
|
|
'emacs!' => \$emacs,
|
|
'terse!' => \$terse,
|
|
'showfile!' => \$showfile,
|
|
'f|file!' => \$file,
|
|
'subjective!' => \$check,
|
|
'strict!' => \$check,
|
|
'ignore=s' => \@ignore,
|
|
'types=s' => \@use,
|
|
'show-types!' => \$show_types,
|
|
'max-line-length=i' => \$max_line_length,
|
|
'min-conf-desc-length=i' => \$min_conf_desc_length,
|
|
'root=s' => \$root,
|
|
'summary!' => \$summary,
|
|
'mailback!' => \$mailback,
|
|
'summary-file!' => \$summary_file,
|
|
'fix!' => \$fix,
|
|
'fix-inplace!' => \$fix_inplace,
|
|
'ignore-perl-version!' => \$ignore_perl_version,
|
|
'debug=s' => \%debug,
|
|
'test-only=s' => \$tst_only,
|
|
'codespell!' => \$codespell,
|
|
'codespellfile=s' => \$codespellfile,
|
|
'color!' => \$color,
|
|
'h|help' => \$help,
|
|
'version' => \$help
|
|
) or help(1);
|
|
|
|
help(0) if ($help);
|
|
|
|
$fix = 1 if ($fix_inplace);
|
|
$check_orig = $check;
|
|
|
|
my $exit = 0;
|
|
|
|
if ($^V && $^V lt $minimum_perl_version) {
|
|
printf "$P: requires at least perl version %vd\n", $minimum_perl_version;
|
|
if (!$ignore_perl_version) {
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
if ($#ARGV < 0) {
|
|
print "$P: no input files\n";
|
|
exit(1);
|
|
}
|
|
|
|
sub hash_save_array_words {
|
|
my ($hashRef, $arrayRef) = @_;
|
|
|
|
my @array = split(/,/, join(',', @$arrayRef));
|
|
foreach my $word (@array) {
|
|
$word =~ s/\s*\n?$//g;
|
|
$word =~ s/^\s*//g;
|
|
$word =~ s/\s+/ /g;
|
|
$word =~ tr/[a-z]/[A-Z]/;
|
|
|
|
next if ($word =~ m/^\s*#/);
|
|
next if ($word =~ m/^\s*$/);
|
|
|
|
$hashRef->{$word}++;
|
|
}
|
|
}
|
|
|
|
sub hash_show_words {
|
|
my ($hashRef, $prefix) = @_;
|
|
|
|
if (keys %$hashRef) {
|
|
print "\nNOTE: $prefix message types:";
|
|
foreach my $word (sort keys %$hashRef) {
|
|
print " $word";
|
|
}
|
|
print "\n";
|
|
}
|
|
}
|
|
|
|
hash_save_array_words(\%ignore_type, \@ignore);
|
|
hash_save_array_words(\%use_type, \@use);
|
|
|
|
my $dbg_values = 0;
|
|
my $dbg_possible = 0;
|
|
my $dbg_type = 0;
|
|
my $dbg_attr = 0;
|
|
for my $key (keys %debug) {
|
|
## no critic
|
|
eval "\${dbg_$key} = '$debug{$key}';";
|
|
die "$@" if ($@);
|
|
}
|
|
|
|
my $rpt_cleaners = 0;
|
|
|
|
if ($terse) {
|
|
$emacs = 1;
|
|
$quiet++;
|
|
}
|
|
|
|
if ($tree) {
|
|
if (defined $root) {
|
|
if (!top_of_kernel_tree($root)) {
|
|
die "$P: $root: --root does not point at a valid tree\n";
|
|
}
|
|
} else {
|
|
if (top_of_kernel_tree('.')) {
|
|
$root = '.';
|
|
} elsif ($0 =~ m@(.*)/scripts/[^/]*$@ &&
|
|
top_of_kernel_tree($1)) {
|
|
$root = $1;
|
|
}
|
|
}
|
|
|
|
if (!defined $root) {
|
|
print "Must be run from the top-level dir. of a kernel tree\n";
|
|
exit(2);
|
|
}
|
|
}
|
|
|
|
my $emitted_corrupt = 0;
|
|
|
|
our $Ident = qr{
|
|
[A-Za-z_][A-Za-z\d_]*
|
|
(?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*
|
|
}x;
|
|
our $Storage = qr{extern|static|asmlinkage};
|
|
our $Sparse = qr{
|
|
__user|
|
|
__kernel|
|
|
__force|
|
|
__iomem|
|
|
__pmem|
|
|
__must_check|
|
|
__init_refok|
|
|
__kprobes|
|
|
__ref|
|
|
__rcu
|
|
}x;
|
|
our $InitAttributePrefix = qr{__(?:mem|cpu|dev|net_|)};
|
|
our $InitAttributeData = qr{$InitAttributePrefix(?:initdata\b)};
|
|
our $InitAttributeConst = qr{$InitAttributePrefix(?:initconst\b)};
|
|
our $InitAttributeInit = qr{$InitAttributePrefix(?:init\b)};
|
|
our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeInit};
|
|
|
|
# Notes to $Attribute:
|
|
# We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
|
|
our $Attribute = qr{
|
|
const|
|
|
__percpu|
|
|
__nocast|
|
|
__safe|
|
|
__bitwise__|
|
|
__packed__|
|
|
__packed2__|
|
|
__naked|
|
|
__maybe_unused|
|
|
__always_unused|
|
|
__noreturn|
|
|
__used|
|
|
__cold|
|
|
__pure|
|
|
__noclone|
|
|
__deprecated|
|
|
__read_mostly|
|
|
__kprobes|
|
|
$InitAttribute|
|
|
____cacheline_aligned|
|
|
____cacheline_aligned_in_smp|
|
|
____cacheline_internodealigned_in_smp|
|
|
__weak
|
|
}x;
|
|
our $Modifier;
|
|
our $Inline = qr{inline|__always_inline|noinline|__inline|__inline__};
|
|
our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
|
|
our $Lval = qr{$Ident(?:$Member)*};
|
|
|
|
our $Int_type = qr{(?i)llu|ull|ll|lu|ul|l|u};
|
|
our $Binary = qr{(?i)0b[01]+$Int_type?};
|
|
our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?};
|
|
our $Int = qr{[0-9]+$Int_type?};
|
|
our $Octal = qr{0[0-7]+$Int_type?};
|
|
our $String = qr{"[X\t]*"};
|
|
our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
|
|
our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
|
|
our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?};
|
|
our $Float = qr{$Float_hex|$Float_dec|$Float_int};
|
|
our $Constant = qr{$Float|$Binary|$Octal|$Hex|$Int};
|
|
our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=};
|
|
our $Compare = qr{<=|>=|==|!=|<|(?<!-)>};
|
|
our $Arithmetic = qr{\+|-|\*|\/|%};
|
|
our $Operators = qr{
|
|
<=|>=|==|!=|
|
|
=>|->|<<|>>|<|>|!|~|
|
|
&&|\|\||,|\^|\+\+|--|&|\||$Arithmetic
|
|
}x;
|
|
|
|
our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x;
|
|
|
|
our $BasicType;
|
|
our $NonptrType;
|
|
our $NonptrTypeMisordered;
|
|
our $NonptrTypeWithAttr;
|
|
our $Type;
|
|
our $TypeMisordered;
|
|
our $Declare;
|
|
our $DeclareMisordered;
|
|
|
|
our $NON_ASCII_UTF8 = qr{
|
|
[\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
|
|
| \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
|
|
| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
|
|
| \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
|
|
| \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
|
|
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
|
|
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
|
|
}x;
|
|
|
|
our $UTF8 = qr{
|
|
[\x09\x0A\x0D\x20-\x7E] # ASCII
|
|
| $NON_ASCII_UTF8
|
|
}x;
|
|
|
|
our $typeC99Typedefs = qr{(?:__)?(?:[us]_?)?int_?(?:8|16|32|64)_t};
|
|
our $typeOtherOSTypedefs = qr{(?x:
|
|
u_(?:char|short|int|long) | # bsd
|
|
u(?:nchar|short|int|long) # sysv
|
|
)};
|
|
our $typeKernelTypedefs = qr{(?x:
|
|
(?:__)?(?:u|s|be|le)(?:8|16|32|64)|
|
|
atomic_t
|
|
)};
|
|
our $typeTypedefs = qr{(?x:
|
|
$typeC99Typedefs\b|
|
|
$typeOtherOSTypedefs\b|
|
|
$typeKernelTypedefs\b
|
|
)};
|
|
|
|
our $zero_initializer = qr{(?:(?:0[xX])?0+$Int_type?|NULL|false)\b};
|
|
|
|
our $logFunctions = qr{(?x:
|
|
printk(?:_ratelimited|_once|)|
|
|
(?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)|
|
|
WARN(?:_RATELIMIT|_ONCE|)|
|
|
panic|
|
|
MODULE_[A-Z_]+|
|
|
seq_vprintf|seq_printf|seq_puts
|
|
)};
|
|
|
|
our $signature_tags = qr{(?xi:
|
|
Signed-off-by:|
|
|
Acked-by:|
|
|
Tested-by:|
|
|
Reviewed-by:|
|
|
Reported-by:|
|
|
Suggested-by:|
|
|
To:|
|
|
Cc:
|
|
)};
|
|
|
|
our @typeListMisordered = (
|
|
qr{char\s+(?:un)?signed},
|
|
qr{int\s+(?:(?:un)?signed\s+)?short\s},
|
|
qr{int\s+short(?:\s+(?:un)?signed)},
|
|
qr{short\s+int(?:\s+(?:un)?signed)},
|
|
qr{(?:un)?signed\s+int\s+short},
|
|
qr{short\s+(?:un)?signed},
|
|
qr{long\s+int\s+(?:un)?signed},
|
|
qr{int\s+long\s+(?:un)?signed},
|
|
qr{long\s+(?:un)?signed\s+int},
|
|
qr{int\s+(?:un)?signed\s+long},
|
|
qr{int\s+(?:un)?signed},
|
|
qr{int\s+long\s+long\s+(?:un)?signed},
|
|
qr{long\s+long\s+int\s+(?:un)?signed},
|
|
qr{long\s+long\s+(?:un)?signed\s+int},
|
|
qr{long\s+long\s+(?:un)?signed},
|
|
qr{long\s+(?:un)?signed},
|
|
);
|
|
|
|
our @typeList = (
|
|
qr{void},
|
|
qr{(?:(?:un)?signed\s+)?char},
|
|
qr{(?:(?:un)?signed\s+)?short\s+int},
|
|
qr{(?:(?:un)?signed\s+)?short},
|
|
qr{(?:(?:un)?signed\s+)?int},
|
|
qr{(?:(?:un)?signed\s+)?long\s+int},
|
|
qr{(?:(?:un)?signed\s+)?long\s+long\s+int},
|
|
qr{(?:(?:un)?signed\s+)?long\s+long},
|
|
qr{(?:(?:un)?signed\s+)?long},
|
|
qr{(?:un)?signed},
|
|
qr{float},
|
|
qr{double},
|
|
qr{bool},
|
|
qr{struct\s+$Ident},
|
|
qr{union\s+$Ident},
|
|
qr{enum\s+$Ident},
|
|
qr{${Ident}_t},
|
|
qr{${Ident}_handler},
|
|
qr{${Ident}_handler_fn},
|
|
@typeListMisordered,
|
|
);
|
|
our @typeListFile = ();
|
|
our @typeListWithAttr = (
|
|
@typeList,
|
|
qr{struct\s+$InitAttribute\s+$Ident},
|
|
qr{union\s+$InitAttribute\s+$Ident},
|
|
);
|
|
|
|
our @modifierList = (
|
|
qr{fastcall},
|
|
);
|
|
our @modifierListFile = ();
|
|
|
|
our @mode_permission_funcs = (
|
|
["module_param", 3],
|
|
["module_param_(?:array|named|string)", 4],
|
|
["module_param_array_named", 5],
|
|
["debugfs_create_(?:file|u8|u16|u32|u64|x8|x16|x32|x64|size_t|atomic_t|bool|blob|regset32|u32_array)", 2],
|
|
["proc_create(?:_data|)", 2],
|
|
["(?:CLASS|DEVICE|SENSOR)_ATTR", 2],
|
|
);
|
|
|
|
#Create a search pattern for all these functions to speed up a loop below
|
|
our $mode_perms_search = "";
|
|
foreach my $entry (@mode_permission_funcs) {
|
|
$mode_perms_search .= '|' if ($mode_perms_search ne "");
|
|
$mode_perms_search .= $entry->[0];
|
|
}
|
|
|
|
our $mode_perms_world_writable = qr{
|
|
S_IWUGO |
|
|
S_IWOTH |
|
|
S_IRWXUGO |
|
|
S_IALLUGO |
|
|
0[0-7][0-7][2367]
|
|
}x;
|
|
|
|
our $allowed_asm_includes = qr{(?x:
|
|
irq|
|
|
memory|
|
|
time|
|
|
reboot
|
|
)};
|
|
# memory.h: ARM has a custom one
|
|
|
|
# Load common spelling mistakes and build regular expression list.
|
|
my $misspellings;
|
|
my %spelling_fix;
|
|
|
|
if (open(my $spelling, '<', $spelling_file)) {
|
|
while (<$spelling>) {
|
|
my $line = $_;
|
|
|
|
$line =~ s/\s*\n?$//g;
|
|
$line =~ s/^\s*//g;
|
|
|
|
next if ($line =~ m/^\s*#/);
|
|
next if ($line =~ m/^\s*$/);
|
|
|
|
my ($suspect, $fix) = split(/\|\|/, $line);
|
|
|
|
$spelling_fix{$suspect} = $fix;
|
|
}
|
|
close($spelling);
|
|
} else {
|
|
warn "No typos will be found - file '$spelling_file': $!\n";
|
|
}
|
|
|
|
if ($codespell) {
|
|
if (open(my $spelling, '<', $codespellfile)) {
|
|
while (<$spelling>) {
|
|
my $line = $_;
|
|
|
|
$line =~ s/\s*\n?$//g;
|
|
$line =~ s/^\s*//g;
|
|
|
|
next if ($line =~ m/^\s*#/);
|
|
next if ($line =~ m/^\s*$/);
|
|
next if ($line =~ m/, disabled/i);
|
|
|
|
$line =~ s/,.*$//;
|
|
|
|
my ($suspect, $fix) = split(/->/, $line);
|
|
|
|
$spelling_fix{$suspect} = $fix;
|
|
}
|
|
close($spelling);
|
|
} else {
|
|
warn "No codespell typos will be found - file '$codespellfile': $!\n";
|
|
}
|
|
}
|
|
|
|
$misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix;
|
|
|
|
sub build_types {
|
|
my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)";
|
|
my $all = "(?x: \n" . join("|\n ", (@typeList, @typeListFile)) . "\n)";
|
|
my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)";
|
|
my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)";
|
|
$Modifier = qr{(?:$Attribute|$Sparse|$mods)};
|
|
$BasicType = qr{
|
|
(?:$typeTypedefs\b)|
|
|
(?:${all}\b)
|
|
}x;
|
|
$NonptrType = qr{
|
|
(?:$Modifier\s+|const\s+)*
|
|
(?:
|
|
(?:typeof|__typeof__)\s*\([^\)]*\)|
|
|
(?:$typeTypedefs\b)|
|
|
(?:${all}\b)
|
|
)
|
|
(?:\s+$Modifier|\s+const)*
|
|
}x;
|
|
$NonptrTypeMisordered = qr{
|
|
(?:$Modifier\s+|const\s+)*
|
|
(?:
|
|
(?:${Misordered}\b)
|
|
)
|
|
(?:\s+$Modifier|\s+const)*
|
|
}x;
|
|
$NonptrTypeWithAttr = qr{
|
|
(?:$Modifier\s+|const\s+)*
|
|
(?:
|
|
(?:typeof|__typeof__)\s*\([^\)]*\)|
|
|
(?:$typeTypedefs\b)|
|
|
(?:${allWithAttr}\b)
|
|
)
|
|
(?:\s+$Modifier|\s+const)*
|
|
}x;
|
|
$Type = qr{
|
|
$NonptrType
|
|
(?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)?
|
|
(?:\s+$Inline|\s+$Modifier)*
|
|
}x;
|
|
$TypeMisordered = qr{
|
|
$NonptrTypeMisordered
|
|
(?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)?
|
|
(?:\s+$Inline|\s+$Modifier)*
|
|
}x;
|
|
$Declare = qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type};
|
|
$DeclareMisordered = qr{(?:$Storage\s+(?:$Inline\s+)?)?$TypeMisordered};
|
|
}
|
|
build_types();
|
|
|
|
our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*};
|
|
|
|
# Using $balanced_parens, $LvalOrFunc, or $FuncArg
|
|
# requires at least perl version v5.10.0
|
|
# Any use must be runtime checked with $^V
|
|
|
|
our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/;
|
|
our $LvalOrFunc = qr{((?:[\&\*]\s*)?$Lval)\s*($balanced_parens{0,1})\s*};
|
|
our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant|$String)};
|
|
|
|
our $declaration_macros = qr{(?x:
|
|
(?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(|
|
|
(?:$Storage\s+)?LIST_HEAD\s*\(|
|
|
(?:$Storage\s+)?${Type}\s+uninitialized_var\s*\(
|
|
)};
|
|
|
|
sub deparenthesize {
|
|
my ($string) = @_;
|
|
return "" if (!defined($string));
|
|
|
|
while ($string =~ /^\s*\(.*\)\s*$/) {
|
|
$string =~ s@^\s*\(\s*@@;
|
|
$string =~ s@\s*\)\s*$@@;
|
|
}
|
|
|
|
$string =~ s@\s+@ @g;
|
|
|
|
return $string;
|
|
}
|
|
|
|
sub seed_camelcase_file {
|
|
my ($file) = @_;
|
|
|
|
return if (!(-f $file));
|
|
|
|
local $/;
|
|
|
|
open(my $include_file, '<', "$file")
|
|
or warn "$P: Can't read '$file' $!\n";
|
|
my $text = <$include_file>;
|
|
close($include_file);
|
|
|
|
my @lines = split('\n', $text);
|
|
|
|
foreach my $line (@lines) {
|
|
next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/);
|
|
if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {
|
|
$camelcase{$1} = 1;
|
|
} elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[\(\[,;]/) {
|
|
$camelcase{$1} = 1;
|
|
} elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[;\{]/) {
|
|
$camelcase{$1} = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
my $camelcase_seeded = 0;
|
|
sub seed_camelcase_includes {
|
|
return if ($camelcase_seeded);
|
|
|
|
my $files;
|
|
my $camelcase_cache = "";
|
|
my @include_files = ();
|
|
|
|
$camelcase_seeded = 1;
|
|
|
|
if (-e ".git") {
|
|
my $git_last_include_commit = `git log --no-merges --pretty=format:"%h%n" -1 -- include`;
|
|
chomp $git_last_include_commit;
|
|
$camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit";
|
|
} else {
|
|
my $last_mod_date = 0;
|
|
$files = `find $root/include -name "*.h"`;
|
|
@include_files = split('\n', $files);
|
|
foreach my $file (@include_files) {
|
|
my $date = POSIX::strftime("%Y%m%d%H%M",
|
|
localtime((stat $file)[9]));
|
|
$last_mod_date = $date if ($last_mod_date < $date);
|
|
}
|
|
$camelcase_cache = ".checkpatch-camelcase.date.$last_mod_date";
|
|
}
|
|
|
|
if ($camelcase_cache ne "" && -f $camelcase_cache) {
|
|
open(my $camelcase_file, '<', "$camelcase_cache")
|
|
or warn "$P: Can't read '$camelcase_cache' $!\n";
|
|
while (<$camelcase_file>) {
|
|
chomp;
|
|
$camelcase{$_} = 1;
|
|
}
|
|
close($camelcase_file);
|
|
|
|
return;
|
|
}
|
|
|
|
if (-e ".git") {
|
|
$files = `git ls-files "include/*.h"`;
|
|
@include_files = split('\n', $files);
|
|
}
|
|
|
|
foreach my $file (@include_files) {
|
|
seed_camelcase_file($file);
|
|
}
|
|
|
|
if ($camelcase_cache ne "") {
|
|
unlink glob ".checkpatch-camelcase.*";
|
|
open(my $camelcase_file, '>', "$camelcase_cache")
|
|
or warn "$P: Can't write '$camelcase_cache' $!\n";
|
|
foreach (sort { lc($a) cmp lc($b) } keys(%camelcase)) {
|
|
print $camelcase_file ("$_\n");
|
|
}
|
|
close($camelcase_file);
|
|
}
|
|
}
|
|
|
|
sub git_commit_info {
|
|
my ($commit, $id, $desc) = @_;
|
|
|
|
return ($id, $desc) if ((which("git") eq "") || !(-e ".git"));
|
|
|
|
my $output = `git log --no-color --format='%H %s' -1 $commit 2>&1`;
|
|
$output =~ s/^\s*//gm;
|
|
my @lines = split("\n", $output);
|
|
|
|
return ($id, $desc) if ($#lines < 0);
|
|
|
|
if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous\./) {
|
|
# Maybe one day convert this block of bash into something that returns
|
|
# all matching commit ids, but it's very slow...
|
|
#
|
|
# echo "checking commits $1..."
|
|
# git rev-list --remotes | grep -i "^$1" |
|
|
# while read line ; do
|
|
# git log --format='%H %s' -1 $line |
|
|
# echo "commit $(cut -c 1-12,41-)"
|
|
# done
|
|
} elsif ($lines[0] =~ /^fatal: ambiguous argument '$commit': unknown revision or path not in the working tree\./) {
|
|
} else {
|
|
$id = substr($lines[0], 0, 12);
|
|
$desc = substr($lines[0], 41);
|
|
}
|
|
|
|
return ($id, $desc);
|
|
}
|
|
|
|
$chk_signoff = 0 if ($file);
|
|
|
|
my @rawlines = ();
|
|
my @lines = ();
|
|
my @fixed = ();
|
|
my @fixed_inserted = ();
|
|
my @fixed_deleted = ();
|
|
my $fixlinenr = -1;
|
|
|
|
my $vname;
|
|
for my $filename (@ARGV) {
|
|
my $FILE;
|
|
if ($file) {
|
|
open($FILE, '-|', "diff -u /dev/null $filename") ||
|
|
die "$P: $filename: diff failed - $!\n";
|
|
} elsif ($filename eq '-') {
|
|
open($FILE, '<&STDIN');
|
|
} else {
|
|
open($FILE, '<', "$filename") ||
|
|
die "$P: $filename: open failed - $!\n";
|
|
}
|
|
if ($filename eq '-') {
|
|
$vname = 'Your patch';
|
|
} else {
|
|
$vname = $filename;
|
|
}
|
|
while (<$FILE>) {
|
|
chomp;
|
|
push(@rawlines, $_);
|
|
}
|
|
close($FILE);
|
|
|
|
if ($#ARGV > 0 && $quiet == 0) {
|
|
print '-' x length($vname) . "\n";
|
|
print "$vname\n";
|
|
print '-' x length($vname) . "\n";
|
|
}
|
|
|
|
if (!process($filename)) {
|
|
$exit = 1;
|
|
}
|
|
@rawlines = ();
|
|
@lines = ();
|
|
@fixed = ();
|
|
@fixed_inserted = ();
|
|
@fixed_deleted = ();
|
|
$fixlinenr = -1;
|
|
@modifierListFile = ();
|
|
@typeListFile = ();
|
|
build_types();
|
|
}
|
|
|
|
if (!$quiet) {
|
|
hash_show_words(\%use_type, "Used");
|
|
hash_show_words(\%ignore_type, "Ignored");
|
|
|
|
if ($^V lt 5.10.0) {
|
|
print << "EOM"
|
|
|
|
NOTE: perl $^V is not modern enough to detect all possible issues.
|
|
An upgrade to at least perl v5.10.0 is suggested.
|
|
EOM
|
|
}
|
|
if ($exit) {
|
|
print << "EOM"
|
|
|
|
NOTE: If any of the errors are false positives, please report
|
|
them to the maintainer, see CHECKPATCH in MAINTAINERS.
|
|
EOM
|
|
}
|
|
}
|
|
|
|
exit($exit);
|
|
|
|
sub top_of_kernel_tree {
|
|
my ($root) = @_;
|
|
|
|
my @tree_check = (
|
|
"COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile",
|
|
"README", "Documentation", "arch", "include", "drivers",
|
|
"fs", "init", "ipc", "kernel", "lib", "scripts",
|
|
);
|
|
|
|
foreach my $check (@tree_check) {
|
|
if (! -e $root . '/' . $check) {
|
|
return 0;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
sub parse_email {
|
|
my ($formatted_email) = @_;
|
|
|
|
my $name = "";
|
|
my $address = "";
|
|
my $comment = "";
|
|
|
|
if ($formatted_email =~ /^(.*)<(\S+\@\S+)>(.*)$/) {
|
|
$name = $1;
|
|
$address = $2;
|
|
$comment = $3 if defined $3;
|
|
} elsif ($formatted_email =~ /^\s*<(\S+\@\S+)>(.*)$/) {
|
|
$address = $1;
|
|
$comment = $2 if defined $2;
|
|
} elsif ($formatted_email =~ /(\S+\@\S+)(.*)$/) {
|
|
$address = $1;
|
|
$comment = $2 if defined $2;
|
|
$formatted_email =~ s/$address.*$//;
|
|
$name = $formatted_email;
|
|
$name = trim($name);
|
|
$name =~ s/^\"|\"$//g;
|
|
# If there's a name left after stripping spaces and
|
|
# leading quotes, and the address doesn't have both
|
|
# leading and trailing angle brackets, the address
|
|
# is invalid. ie:
|
|
# "joe smith joe@smith.com" bad
|
|
# "joe smith <joe@smith.com" bad
|
|
if ($name ne "" && $address !~ /^<[^>]+>$/) {
|
|
$name = "";
|
|
$address = "";
|
|
$comment = "";
|
|
}
|
|
}
|
|
|
|
$name = trim($name);
|
|
$name =~ s/^\"|\"$//g;
|
|
$address = trim($address);
|
|
$address =~ s/^\<|\>$//g;
|
|
|
|
if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
|
|
$name =~ s/(?<!\\)"/\\"/g; ##escape quotes
|
|
$name = "\"$name\"";
|
|
}
|
|
|
|
return ($name, $address, $comment);
|
|
}
|
|
|
|
sub format_email {
|
|
my ($name, $address) = @_;
|
|
|
|
my $formatted_email;
|
|
|
|
$name = trim($name);
|
|
$name =~ s/^\"|\"$//g;
|
|
$address = trim($address);
|
|
|
|
if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
|
|
$name =~ s/(?<!\\)"/\\"/g; ##escape quotes
|
|
$name = "\"$name\"";
|
|
}
|
|
|
|
if ("$name" eq "") {
|
|
$formatted_email = "$address";
|
|
} else {
|
|
$formatted_email = "$name <$address>";
|
|
}
|
|
|
|
return $formatted_email;
|
|
}
|
|
|
|
sub which {
|
|
my ($bin) = @_;
|
|
|
|
foreach my $path (split(/:/, $ENV{PATH})) {
|
|
if (-e "$path/$bin") {
|
|
return "$path/$bin";
|
|
}
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
sub which_conf {
|
|
my ($conf) = @_;
|
|
|
|
foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
|
|
if (-e "$path/$conf") {
|
|
return "$path/$conf";
|
|
}
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
sub expand_tabs {
|
|
my ($str) = @_;
|
|
|
|
my $res = '';
|
|
my $n = 0;
|
|
for my $c (split(//, $str)) {
|
|
if ($c eq "\t") {
|
|
$res .= ' ';
|
|
$n++;
|
|
for (; ($n % 8) != 0; $n++) {
|
|
$res .= ' ';
|
|
}
|
|
next;
|
|
}
|
|
$res .= $c;
|
|
$n++;
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
sub copy_spacing {
|
|
(my $res = shift) =~ tr/\t/ /c;
|
|
return $res;
|
|
}
|
|
|
|
sub line_stats {
|
|
my ($line) = @_;
|
|
|
|
# Drop the diff line leader and expand tabs
|
|
$line =~ s/^.//;
|
|
$line = expand_tabs($line);
|
|
|
|
# Pick the indent from the front of the line.
|
|
my ($white) = ($line =~ /^(\s*)/);
|
|
|
|
return (length($line), length($white));
|
|
}
|
|
|
|
my $sanitise_quote = '';
|
|
|
|
sub sanitise_line_reset {
|
|
my ($in_comment) = @_;
|
|
|
|
if ($in_comment) {
|
|
$sanitise_quote = '*/';
|
|
} else {
|
|
$sanitise_quote = '';
|
|
}
|
|
}
|
|
sub sanitise_line {
|
|
my ($line) = @_;
|
|
|
|
my $res = '';
|
|
my $l = '';
|
|
|
|
my $qlen = 0;
|
|
my $off = 0;
|
|
my $c;
|
|
|
|
# Always copy over the diff marker.
|
|
$res = substr($line, 0, 1);
|
|
|
|
for ($off = 1; $off < length($line); $off++) {
|
|
$c = substr($line, $off, 1);
|
|
|
|
# Comments we are wacking completly including the begin
|
|
# and end, all to $;.
|
|
if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') {
|
|
$sanitise_quote = '*/';
|
|
|
|
substr($res, $off, 2, "$;$;");
|
|
$off++;
|
|
next;
|
|
}
|
|
if ($sanitise_quote eq '*/' && substr($line, $off, 2) eq '*/') {
|
|
$sanitise_quote = '';
|
|
substr($res, $off, 2, "$;$;");
|
|
$off++;
|
|
next;
|
|
}
|
|
if ($sanitise_quote eq '' && substr($line, $off, 2) eq '//') {
|
|
$sanitise_quote = '//';
|
|
|
|
substr($res, $off, 2, $sanitise_quote);
|
|
$off++;
|
|
next;
|
|
}
|
|
|
|
# A \ in a string means ignore the next character.
|
|
if (($sanitise_quote eq "'" || $sanitise_quote eq '"') &&
|
|
$c eq "\\") {
|
|
substr($res, $off, 2, 'XX');
|
|
$off++;
|
|
next;
|
|
}
|
|
# Regular quotes.
|
|
if ($c eq "'" || $c eq '"') {
|
|
if ($sanitise_quote eq '') {
|
|
$sanitise_quote = $c;
|
|
|
|
substr($res, $off, 1, $c);
|
|
next;
|
|
} elsif ($sanitise_quote eq $c) {
|
|
$sanitise_quote = '';
|
|
}
|
|
}
|
|
|
|
#print "c<$c> SQ<$sanitise_quote>\n";
|
|
if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") {
|
|
substr($res, $off, 1, $;);
|
|
} elsif ($off != 0 && $sanitise_quote eq '//' && $c ne "\t") {
|
|
substr($res, $off, 1, $;);
|
|
} elsif ($off != 0 && $sanitise_quote && $c ne "\t") {
|
|
substr($res, $off, 1, 'X');
|
|
} else {
|
|
substr($res, $off, 1, $c);
|
|
}
|
|
}
|
|
|
|
if ($sanitise_quote eq '//') {
|
|
$sanitise_quote = '';
|
|
}
|
|
|
|
# The pathname on a #include may be surrounded by '<' and '>'.
|
|
if ($res =~ /^.\s*\#\s*include\s+\<(.*)\>/) {
|
|
my $clean = 'X' x length($1);
|
|
$res =~ s@\<.*\>@<$clean>@;
|
|
|
|
# The whole of a #error is a string.
|
|
} elsif ($res =~ /^.\s*\#\s*(?:error|warning)\s+(.*)\b/) {
|
|
my $clean = 'X' x length($1);
|
|
$res =~ s@(\#\s*(?:error|warning)\s+).*@$1$clean@;
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
|
|
sub get_quoted_string {
|
|
my ($line, $rawline) = @_;
|
|
|
|
return "" if ($line !~ m/($String)/g);
|
|
return substr($rawline, $-[0], $+[0] - $-[0]);
|
|
}
|
|
|
|
sub ctx_statement_block {
|
|
my ($linenr, $remain, $off) = @_;
|
|
my $line = $linenr - 1;
|
|
my $blk = '';
|
|
my $soff = $off;
|
|
my $coff = $off - 1;
|
|
my $coff_set = 0;
|
|
|
|
my $loff = 0;
|
|
|
|
my $type = '';
|
|
my $level = 0;
|
|
my @stack = ();
|
|
my $p;
|
|
my $c;
|
|
my $len = 0;
|
|
|
|
my $remainder;
|
|
while (1) {
|
|
@stack = (['', 0]) if ($#stack == -1);
|
|
|
|
#warn "CSB: blk<$blk> remain<$remain>\n";
|
|
# If we are about to drop off the end, pull in more
|
|
# context.
|
|
if ($off >= $len) {
|
|
for (; $remain > 0; $line++) {
|
|
last if (!defined $lines[$line]);
|
|
next if ($lines[$line] =~ /^-/);
|
|
$remain--;
|
|
$loff = $len;
|
|
$blk .= $lines[$line] . "\n";
|
|
$len = length($blk);
|
|
$line++;
|
|
last;
|
|
}
|
|
# Bail if there is no further context.
|
|
#warn "CSB: blk<$blk> off<$off> len<$len>\n";
|
|
if ($off >= $len) {
|
|
last;
|
|
}
|
|
if ($level == 0 && substr($blk, $off) =~ /^.\s*#\s*define/) {
|
|
$level++;
|
|
$type = '#';
|
|
}
|
|
}
|
|
$p = $c;
|
|
$c = substr($blk, $off, 1);
|
|
$remainder = substr($blk, $off);
|
|
|
|
#warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n";
|
|
|
|
# Handle nested #if/#else.
|
|
if ($remainder =~ /^#\s*(?:ifndef|ifdef|if)\s/) {
|
|
push(@stack, [ $type, $level ]);
|
|
} elsif ($remainder =~ /^#\s*(?:else|elif)\b/) {
|
|
($type, $level) = @{$stack[$#stack - 1]};
|
|
} elsif ($remainder =~ /^#\s*endif\b/) {
|
|
($type, $level) = @{pop(@stack)};
|
|
}
|
|
|
|
# Statement ends at the ';' or a close '}' at the
|
|
# outermost level.
|
|
if ($level == 0 && $c eq ';') {
|
|
last;
|
|
}
|
|
|
|
# An else is really a conditional as long as its not else if
|
|
if ($level == 0 && $coff_set == 0 &&
|
|
(!defined($p) || $p =~ /(?:\s|\}|\+)/) &&
|
|
$remainder =~ /^(else)(?:\s|{)/ &&
|
|
$remainder !~ /^else\s+if\b/) {
|
|
$coff = $off + length($1) - 1;
|
|
$coff_set = 1;
|
|
#warn "CSB: mark coff<$coff> soff<$soff> 1<$1>\n";
|
|
#warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
|
|
}
|
|
|
|
if (($type eq '' || $type eq '(') && $c eq '(') {
|
|
$level++;
|
|
$type = '(';
|
|
}
|
|
if ($type eq '(' && $c eq ')') {
|
|
$level--;
|
|
$type = ($level != 0)? '(' : '';
|
|
|
|
if ($level == 0 && $coff < $soff) {
|
|
$coff = $off;
|
|
$coff_set = 1;
|
|
#warn "CSB: mark coff<$coff>\n";
|
|
}
|
|
}
|
|
if (($type eq '' || $type eq '{') && $c eq '{') {
|
|
$level++;
|
|
$type = '{';
|
|
}
|
|
if ($type eq '{' && $c eq '}') {
|
|
$level--;
|
|
$type = ($level != 0)? '{' : '';
|
|
|
|
if ($level == 0) {
|
|
if (substr($blk, $off + 1, 1) eq ';') {
|
|
$off++;
|
|
}
|
|
last;
|
|
}
|
|
}
|
|
# Preprocessor commands end at the newline unless escaped.
|
|
if ($type eq '#' && $c eq "\n" && $p ne "\\") {
|
|
$level--;
|
|
$type = '';
|
|
$off++;
|
|
last;
|
|
}
|
|
$off++;
|
|
}
|
|
# We are truly at the end, so shuffle to the next line.
|
|
if ($off == $len) {
|
|
$loff = $len + 1;
|
|
$line++;
|
|
$remain--;
|
|
}
|
|
|
|
my $statement = substr($blk, $soff, $off - $soff + 1);
|
|
my $condition = substr($blk, $soff, $coff - $soff + 1);
|
|
|
|
#warn "STATEMENT<$statement>\n";
|
|
#warn "CONDITION<$condition>\n";
|
|
|
|
#print "coff<$coff> soff<$off> loff<$loff>\n";
|
|
|
|
return ($statement, $condition,
|
|
$line, $remain + 1, $off - $loff + 1, $level);
|
|
}
|
|
|
|
sub statement_lines {
|
|
my ($stmt) = @_;
|
|
|
|
# Strip the diff line prefixes and rip blank lines at start and end.
|
|
$stmt =~ s/(^|\n)./$1/g;
|
|
$stmt =~ s/^\s*//;
|
|
$stmt =~ s/\s*$//;
|
|
|
|
my @stmt_lines = ($stmt =~ /\n/g);
|
|
|
|
return $#stmt_lines + 2;
|
|
}
|
|
|
|
sub statement_rawlines {
|
|
my ($stmt) = @_;
|
|
|
|
my @stmt_lines = ($stmt =~ /\n/g);
|
|
|
|
return $#stmt_lines + 2;
|
|
}
|
|
|
|
sub statement_block_size {
|
|
my ($stmt) = @_;
|
|
|
|
$stmt =~ s/(^|\n)./$1/g;
|
|
$stmt =~ s/^\s*{//;
|
|
$stmt =~ s/}\s*$//;
|
|
$stmt =~ s/^\s*//;
|
|
$stmt =~ s/\s*$//;
|
|
|
|
my @stmt_lines = ($stmt =~ /\n/g);
|
|
my @stmt_statements = ($stmt =~ /;/g);
|
|
|
|
my $stmt_lines = $#stmt_lines + 2;
|
|
my $stmt_statements = $#stmt_statements + 1;
|
|
|
|
if ($stmt_lines > $stmt_statements) {
|
|
return $stmt_lines;
|
|
} else {
|
|
return $stmt_statements;
|
|
}
|
|
}
|
|
|
|
sub ctx_statement_full {
|
|
my ($linenr, $remain, $off) = @_;
|
|
my ($statement, $condition, $level);
|
|
|
|
my (@chunks);
|
|
|
|
# Grab the first conditional/block pair.
|
|
($statement, $condition, $linenr, $remain, $off, $level) =
|
|
ctx_statement_block($linenr, $remain, $off);
|
|
#print "F: c<$condition> s<$statement> remain<$remain>\n";
|
|
push(@chunks, [ $condition, $statement ]);
|
|
if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
|
|
return ($level, $linenr, @chunks);
|
|
}
|
|
|
|
# Pull in the following conditional/block pairs and see if they
|
|
# could continue the statement.
|
|
for (;;) {
|
|
($statement, $condition, $linenr, $remain, $off, $level) =
|
|
ctx_statement_block($linenr, $remain, $off);
|
|
#print "C: c<$condition> s<$statement> remain<$remain>\n";
|
|
last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
|
|
#print "C: push\n";
|
|
push(@chunks, [ $condition, $statement ]);
|
|
}
|
|
|
|
return ($level, $linenr, @chunks);
|
|
}
|
|
|
|
sub ctx_block_get {
|
|
my ($linenr, $remain, $outer, $open, $close, $off) = @_;
|
|
my $line;
|
|
my $start = $linenr - 1;
|
|
my $blk = '';
|
|
my @o;
|
|
my @c;
|
|
my @res = ();
|
|
|
|
my $level = 0;
|
|
my @stack = ($level);
|
|
for ($line = $start; $remain > 0; $line++) {
|
|
next if ($rawlines[$line] =~ /^-/);
|
|
$remain--;
|
|
|
|
$blk .= $rawlines[$line];
|
|
|
|
# Handle nested #if/#else.
|
|
if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
|
|
push(@stack, $level);
|
|
} elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
|
|
$level = $stack[$#stack - 1];
|
|
} elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) {
|
|
$level = pop(@stack);
|
|
}
|
|
|
|
foreach my $c (split(//, $lines[$line])) {
|
|
##print "C<$c>L<$level><$open$close>O<$off>\n";
|
|
if ($off > 0) {
|
|
$off--;
|
|
next;
|
|
}
|
|
|
|
if ($c eq $close && $level > 0) {
|
|
$level--;
|
|
last if ($level == 0);
|
|
} elsif ($c eq $open) {
|
|
$level++;
|
|
}
|
|
}
|
|
|
|
if (!$outer || $level <= 1) {
|
|
push(@res, $rawlines[$line]);
|
|
}
|
|
|
|
last if ($level == 0);
|
|
}
|
|
|
|
return ($level, @res);
|
|
}
|
|
sub ctx_block_outer {
|
|
my ($linenr, $remain) = @_;
|
|
|
|
my ($level, @r) = ctx_block_get($linenr, $remain, 1, '{', '}', 0);
|
|
return @r;
|
|
}
|
|
sub ctx_block {
|
|
my ($linenr, $remain) = @_;
|
|
|
|
my ($level, @r) = ctx_block_get($linenr, $remain, 0, '{', '}', 0);
|
|
return @r;
|
|
}
|
|
sub ctx_statement {
|
|
my ($linenr, $remain, $off) = @_;
|
|
|
|
my ($level, @r) = ctx_block_get($linenr, $remain, 0, '(', ')', $off);
|
|
return @r;
|
|
}
|
|
sub ctx_block_level {
|
|
my ($linenr, $remain) = @_;
|
|
|
|
return ctx_block_get($linenr, $remain, 0, '{', '}', 0);
|
|
}
|
|
sub ctx_statement_level {
|
|
my ($linenr, $remain, $off) = @_;
|
|
|
|
return ctx_block_get($linenr, $remain, 0, '(', ')', $off);
|
|
}
|
|
|
|
sub ctx_locate_comment {
|
|
my ($first_line, $end_line) = @_;
|
|
|
|
# Catch a comment on the end of the line itself.
|
|
my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@);
|
|
return $current_comment if (defined $current_comment);
|
|
|
|
# Look through the context and try and figure out if there is a
|
|
# comment.
|
|
my $in_comment = 0;
|
|
$current_comment = '';
|
|
for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
|
|
my $line = $rawlines[$linenr - 1];
|
|
#warn " $line\n";
|
|
if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
|
|
$in_comment = 1;
|
|
}
|
|
if ($line =~ m@/\*@) {
|
|
$in_comment = 1;
|
|
}
|
|
if (!$in_comment && $current_comment ne '') {
|
|
$current_comment = '';
|
|
}
|
|
$current_comment .= $line . "\n" if ($in_comment);
|
|
if ($line =~ m@\*/@) {
|
|
$in_comment = 0;
|
|
}
|
|
}
|
|
|
|
chomp($current_comment);
|
|
return($current_comment);
|
|
}
|
|
sub ctx_has_comment {
|
|
my ($first_line, $end_line) = @_;
|
|
my $cmt = ctx_locate_comment($first_line, $end_line);
|
|
|
|
##print "LINE: $rawlines[$end_line - 1 ]\n";
|
|
##print "CMMT: $cmt\n";
|
|
|
|
return ($cmt ne '');
|
|
}
|
|
|
|
sub raw_line {
|
|
my ($linenr, $cnt) = @_;
|
|
|
|
my $offset = $linenr - 1;
|
|
$cnt++;
|
|
|
|
my $line;
|
|
while ($cnt) {
|
|
$line = $rawlines[$offset++];
|
|
next if (defined($line) && $line =~ /^-/);
|
|
$cnt--;
|
|
}
|
|
|
|
return $line;
|
|
}
|
|
|
|
sub cat_vet {
|
|
my ($vet) = @_;
|
|
my ($res, $coded);
|
|
|
|
$res = '';
|
|
while ($vet =~ /([^[:cntrl:]]*)([[:cntrl:]]|$)/g) {
|
|
$res .= $1;
|
|
if ($2 ne '') {
|
|
$coded = sprintf("^%c", unpack('C', $2) + 64);
|
|
$res .= $coded;
|
|
}
|
|
}
|
|
$res =~ s/$/\$/;
|
|
|
|
return $res;
|
|
}
|
|
|
|
my $av_preprocessor = 0;
|
|
my $av_pending;
|
|
my @av_paren_type;
|
|
my $av_pend_colon;
|
|
|
|
sub annotate_reset {
|
|
$av_preprocessor = 0;
|
|
$av_pending = '_';
|
|
@av_paren_type = ('E');
|
|
$av_pend_colon = 'O';
|
|
}
|
|
|
|
sub annotate_values {
|
|
my ($stream, $type) = @_;
|
|
|
|
my $res;
|
|
my $var = '_' x length($stream);
|
|
my $cur = $stream;
|
|
|
|
print "$stream\n" if ($dbg_values > 1);
|
|
|
|
while (length($cur)) {
|
|
@av_paren_type = ('E') if ($#av_paren_type < 0);
|
|
print " <" . join('', @av_paren_type) .
|
|
"> <$type> <$av_pending>" if ($dbg_values > 1);
|
|
if ($cur =~ /^(\s+)/o) {
|
|
print "WS($1)\n" if ($dbg_values > 1);
|
|
if ($1 =~ /\n/ && $av_preprocessor) {
|
|
$type = pop(@av_paren_type);
|
|
$av_preprocessor = 0;
|
|
}
|
|
|
|
} elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') {
|
|
print "CAST($1)\n" if ($dbg_values > 1);
|
|
push(@av_paren_type, $type);
|
|
$type = 'c';
|
|
|
|
} elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
|
|
print "DECLARE($1)\n" if ($dbg_values > 1);
|
|
$type = 'T';
|
|
|
|
} elsif ($cur =~ /^($Modifier)\s*/) {
|
|
print "MODIFIER($1)\n" if ($dbg_values > 1);
|
|
$type = 'T';
|
|
|
|
} elsif ($cur =~ /^(\#\s*define\s*$Ident)(\(?)/o) {
|
|
print "DEFINE($1,$2)\n" if ($dbg_values > 1);
|
|
$av_preprocessor = 1;
|
|
push(@av_paren_type, $type);
|
|
if ($2 ne '') {
|
|
$av_pending = 'N';
|
|
}
|
|
$type = 'E';
|
|
|
|
} elsif ($cur =~ /^(\#\s*(?:undef\s*$Ident|include\b))/o) {
|
|
print "UNDEF($1)\n" if ($dbg_values > 1);
|
|
$av_preprocessor = 1;
|
|
push(@av_paren_type, $type);
|
|
|
|
} elsif ($cur =~ /^(\#\s*(?:ifdef|ifndef|if))/o) {
|
|
print "PRE_START($1)\n" if ($dbg_values > 1);
|
|
$av_preprocessor = 1;
|
|
|
|
push(@av_paren_type, $type);
|
|
push(@av_paren_type, $type);
|
|
$type = 'E';
|
|
|
|
} elsif ($cur =~ /^(\#\s*(?:else|elif))/o) {
|
|
print "PRE_RESTART($1)\n" if ($dbg_values > 1);
|
|
$av_preprocessor = 1;
|
|
|
|
push(@av_paren_type, $av_paren_type[$#av_paren_type]);
|
|
|
|
$type = 'E';
|
|
|
|
} elsif ($cur =~ /^(\#\s*(?:endif))/o) {
|
|
print "PRE_END($1)\n" if ($dbg_values > 1);
|
|
|
|
$av_preprocessor = 1;
|
|
|
|
# Assume all arms of the conditional end as this
|
|
# one does, and continue as if the #endif was not here.
|
|
pop(@av_paren_type);
|
|
push(@av_paren_type, $type);
|
|
$type = 'E';
|
|
|
|
} elsif ($cur =~ /^(\\\n)/o) {
|
|
print "PRECONT($1)\n" if ($dbg_values > 1);
|
|
|
|
} elsif ($cur =~ /^(__attribute__)\s*\(?/o) {
|
|
print "ATTR($1)\n" if ($dbg_values > 1);
|
|
$av_pending = $type;
|
|
$type = 'N';
|
|
|
|
} elsif ($cur =~ /^(sizeof)\s*(\()?/o) {
|
|
print "SIZEOF($1)\n" if ($dbg_values > 1);
|
|
if (defined $2) {
|
|
$av_pending = 'V';
|
|
}
|
|
$type = 'N';
|
|
|
|
} elsif ($cur =~ /^(if|while|for)\b/o) {
|
|
print "COND($1)\n" if ($dbg_values > 1);
|
|
$av_pending = 'E';
|
|
$type = 'N';
|
|
|
|
} elsif ($cur =~/^(case)/o) {
|
|
print "CASE($1)\n" if ($dbg_values > 1);
|
|
$av_pend_colon = 'C';
|
|
$type = 'N';
|
|
|
|
} elsif ($cur =~/^(return|else|goto|typeof|__typeof__)\b/o) {
|
|
print "KEYWORD($1)\n" if ($dbg_values > 1);
|
|
$type = 'N';
|
|
|
|
} elsif ($cur =~ /^(\()/o) {
|
|
print "PAREN('$1')\n" if ($dbg_values > 1);
|
|
push(@av_paren_type, $av_pending);
|
|
$av_pending = '_';
|
|
$type = 'N';
|
|
|
|
} elsif ($cur =~ /^(\))/o) {
|
|
my $new_type = pop(@av_paren_type);
|
|
if ($new_type ne '_') {
|
|
$type = $new_type;
|
|
print "PAREN('$1') -> $type\n"
|
|
if ($dbg_values > 1);
|
|
} else {
|
|
print "PAREN('$1')\n" if ($dbg_values > 1);
|
|
}
|
|
|
|
} elsif ($cur =~ /^($Ident)\s*\(/o) {
|
|
print "FUNC($1)\n" if ($dbg_values > 1);
|
|
$type = 'V';
|
|
$av_pending = 'V';
|
|
|
|
} elsif ($cur =~ /^($Ident\s*):(?:\s*\d+\s*(,|=|;))?/) {
|
|
if (defined $2 && $type eq 'C' || $type eq 'T') {
|
|
$av_pend_colon = 'B';
|
|
} elsif ($type eq 'E') {
|
|
$av_pend_colon = 'L';
|
|
}
|
|
print "IDENT_COLON($1,$type>$av_pend_colon)\n" if ($dbg_values > 1);
|
|
$type = 'V';
|
|
|
|
} elsif ($cur =~ /^($Ident|$Constant)/o) {
|
|
print "IDENT($1)\n" if ($dbg_values > 1);
|
|
$type = 'V';
|
|
|
|
} elsif ($cur =~ /^($Assignment)/o) {
|
|
print "ASSIGN($1)\n" if ($dbg_values > 1);
|
|
$type = 'N';
|
|
|
|
} elsif ($cur =~/^(;|{|})/) {
|
|
print "END($1)\n" if ($dbg_values > 1);
|
|
$type = 'E';
|
|
$av_pend_colon = 'O';
|
|
|
|
} elsif ($cur =~/^(,)/) {
|
|
print "COMMA($1)\n" if ($dbg_values > 1);
|
|
$type = 'C';
|
|
|
|
} elsif ($cur =~ /^(\?)/o) {
|
|
print "QUESTION($1)\n" if ($dbg_values > 1);
|
|
$type = 'N';
|
|
|
|
} elsif ($cur =~ /^(:)/o) {
|
|
print "COLON($1,$av_pend_colon)\n" if ($dbg_values > 1);
|
|
|
|
substr($var, length($res), 1, $av_pend_colon);
|
|
if ($av_pend_colon eq 'C' || $av_pend_colon eq 'L') {
|
|
$type = 'E';
|
|
} else {
|
|
$type = 'N';
|
|
}
|
|
$av_pend_colon = 'O';
|
|
|
|
} elsif ($cur =~ /^(\[)/o) {
|
|
print "CLOSE($1)\n" if ($dbg_values > 1);
|
|
$type = 'N';
|
|
|
|
} elsif ($cur =~ /^(-(?![->])|\+(?!\+)|\*|\&\&|\&)/o) {
|
|
my $variant;
|
|
|
|
print "OPV($1)\n" if ($dbg_values > 1);
|
|
if ($type eq 'V') {
|
|
$variant = 'B';
|
|
} else {
|
|
$variant = 'U';
|
|
}
|
|
|
|
substr($var, length($res), 1, $variant);
|
|
$type = 'N';
|
|
|
|
} elsif ($cur =~ /^($Operators)/o) {
|
|
print "OP($1)\n" if ($dbg_values > 1);
|
|
if ($1 ne '++' && $1 ne '--') {
|
|
$type = 'N';
|
|
}
|
|
|
|
} elsif ($cur =~ /(^.)/o) {
|
|
print "C($1)\n" if ($dbg_values > 1);
|
|
}
|
|
if (defined $1) {
|
|
$cur = substr($cur, length($1));
|
|
$res .= $type x length($1);
|
|
}
|
|
}
|
|
|
|
return ($res, $var);
|
|
}
|
|
|
|
sub possible {
|
|
my ($possible, $line) = @_;
|
|
my $notPermitted = qr{(?:
|
|
^(?:
|
|
$Modifier|
|
|
$Storage|
|
|
$Type|
|
|
DEFINE_\S+
|
|
)$|
|
|
^(?:
|
|
goto|
|
|
return|
|
|
case|
|
|
else|
|
|
asm|__asm__|
|
|
do|
|
|
\#|
|
|
\#\#|
|
|
)(?:\s|$)|
|
|
^(?:typedef|struct|enum)\b
|
|
)}x;
|
|
warn "CHECK<$possible> ($line)\n" if ($dbg_possible > 2);
|
|
if ($possible !~ $notPermitted) {
|
|
# Check for modifiers.
|
|
$possible =~ s/\s*$Storage\s*//g;
|
|
$possible =~ s/\s*$Sparse\s*//g;
|
|
if ($possible =~ /^\s*$/) {
|
|
|
|
} elsif ($possible =~ /\s/) {
|
|
$possible =~ s/\s*$Type\s*//g;
|
|
for my $modifier (split(' ', $possible)) {
|
|
if ($modifier !~ $notPermitted) {
|
|
warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible);
|
|
push(@modifierListFile, $modifier);
|
|
}
|
|
}
|
|
|
|
} else {
|
|
warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible);
|
|
push(@typeListFile, $possible);
|
|
}
|
|
build_types();
|
|
} else {
|
|
warn "NOTPOSS: $possible ($line)\n" if ($dbg_possible > 1);
|
|
}
|
|
}
|
|
|
|
my $prefix = '';
|
|
|
|
sub show_type {
|
|
my ($type) = @_;
|
|
|
|
return defined $use_type{$type} if (scalar keys %use_type > 0);
|
|
|
|
return !defined $ignore_type{$type};
|
|
}
|
|
|
|
sub report {
|
|
my ($level, $type, $msg) = @_;
|
|
|
|
if (!show_type($type) ||
|
|
(defined $tst_only && $msg !~ /\Q$tst_only\E/)) {
|
|
return 0;
|
|
}
|
|
my $output = '';
|
|
if (-t STDOUT && $color) {
|
|
if ($level eq 'ERROR') {
|
|
$output .= RED;
|
|
} elsif ($level eq 'WARNING') {
|
|
$output .= YELLOW;
|
|
} else {
|
|
$output .= GREEN;
|
|
}
|
|
}
|
|
$output .= $prefix . $level . ':';
|
|
if ($show_types) {
|
|
$output .= BLUE if (-t STDOUT && $color);
|
|
$output .= "$type:";
|
|
}
|
|
$output .= RESET if (-t STDOUT && $color);
|
|
$output .= ' ' . $msg . "\n";
|
|
|
|
if ($showfile) {
|
|
my @lines = split("\n", $output, -1);
|
|
splice(@lines, 1, 1);
|
|
$output = join("\n", @lines);
|
|
}
|
|
$output = (split('\n', $output))[0] . "\n" if ($terse);
|
|
|
|
push(our @report, $output);
|
|
|
|
return 1;
|
|
}
|
|
|
|
sub report_dump {
|
|
our @report;
|
|
}
|
|
|
|
sub fixup_current_range {
|
|
my ($lineRef, $offset, $length) = @_;
|
|
|
|
if ($$lineRef =~ /^\@\@ -\d+,\d+ \+(\d+),(\d+) \@\@/) {
|
|
my $o = $1;
|
|
my $l = $2;
|
|
my $no = $o + $offset;
|
|
my $nl = $l + $length;
|
|
$$lineRef =~ s/\+$o,$l \@\@/\+$no,$nl \@\@/;
|
|
}
|
|
}
|
|
|
|
sub fix_inserted_deleted_lines {
|
|
my ($linesRef, $insertedRef, $deletedRef) = @_;
|
|
|
|
my $range_last_linenr = 0;
|
|
my $delta_offset = 0;
|
|
|
|
my $old_linenr = 0;
|
|
my $new_linenr = 0;
|
|
|
|
my $next_insert = 0;
|
|
my $next_delete = 0;
|
|
|
|
my @lines = ();
|
|
|
|
my $inserted = @{$insertedRef}[$next_insert++];
|
|
my $deleted = @{$deletedRef}[$next_delete++];
|
|
|
|
foreach my $old_line (@{$linesRef}) {
|
|
my $save_line = 1;
|
|
my $line = $old_line; #don't modify the array
|
|
if ($line =~ /^(?:\+\+\+|\-\-\-)\s+\S+/) { #new filename
|
|
$delta_offset = 0;
|
|
} elsif ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@/) { #new hunk
|
|
$range_last_linenr = $new_linenr;
|
|
fixup_current_range(\$line, $delta_offset, 0);
|
|
}
|
|
|
|
while (defined($deleted) && ${$deleted}{'LINENR'} == $old_linenr) {
|
|
$deleted = @{$deletedRef}[$next_delete++];
|
|
$save_line = 0;
|
|
fixup_current_range(\$lines[$range_last_linenr], $delta_offset--, -1);
|
|
}
|
|
|
|
while (defined($inserted) && ${$inserted}{'LINENR'} == $old_linenr) {
|
|
push(@lines, ${$inserted}{'LINE'});
|
|
$inserted = @{$insertedRef}[$next_insert++];
|
|
$new_linenr++;
|
|
fixup_current_range(\$lines[$range_last_linenr], $delta_offset++, 1);
|
|
}
|
|
|
|
if ($save_line) {
|
|
push(@lines, $line);
|
|
$new_linenr++;
|
|
}
|
|
|
|
$old_linenr++;
|
|
}
|
|
|
|
return @lines;
|
|
}
|
|
|
|
sub fix_insert_line {
|
|
my ($linenr, $line) = @_;
|
|
|
|
my $inserted = {
|
|
LINENR => $linenr,
|
|
LINE => $line,
|
|
};
|
|
push(@fixed_inserted, $inserted);
|
|
}
|
|
|
|
sub fix_delete_line {
|
|
my ($linenr, $line) = @_;
|
|
|
|
my $deleted = {
|
|
LINENR => $linenr,
|
|
LINE => $line,
|
|
};
|
|
|
|
push(@fixed_deleted, $deleted);
|
|
}
|
|
|
|
sub ERROR {
|
|
my ($type, $msg) = @_;
|
|
|
|
if (report("ERROR", $type, $msg)) {
|
|
our $clean = 0;
|
|
our $cnt_error++;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
sub WARN {
|
|
my ($type, $msg) = @_;
|
|
|
|
if (report("WARNING", $type, $msg)) {
|
|
our $clean = 0;
|
|
our $cnt_warn++;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
sub CHK {
|
|
my ($type, $msg) = @_;
|
|
|
|
if ($check && report("CHECK", $type, $msg)) {
|
|
our $clean = 0;
|
|
our $cnt_chk++;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
sub check_absolute_file {
|
|
my ($absolute, $herecurr) = @_;
|
|
my $file = $absolute;
|
|
|
|
##print "absolute<$absolute>\n";
|
|
|
|
# See if any suffix of this path is a path within the tree.
|
|
while ($file =~ s@^[^/]*/@@) {
|
|
if (-f "$root/$file") {
|
|
##print "file<$file>\n";
|
|
last;
|
|
}
|
|
}
|
|
if (! -f _) {
|
|
return 0;
|
|
}
|
|
|
|
# It is, so see if the prefix is acceptable.
|
|
my $prefix = $absolute;
|
|
substr($prefix, -length($file)) = '';
|
|
|
|
##print "prefix<$prefix>\n";
|
|
if ($prefix ne ".../") {
|
|
WARN("USE_RELATIVE_PATH",
|
|
"use relative pathname instead of absolute in changelog text\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
sub trim {
|
|
my ($string) = @_;
|
|
|
|
$string =~ s/^\s+|\s+$//g;
|
|
|
|
return $string;
|
|
}
|
|
|
|
sub ltrim {
|
|
my ($string) = @_;
|
|
|
|
$string =~ s/^\s+//;
|
|
|
|
return $string;
|
|
}
|
|
|
|
sub rtrim {
|
|
my ($string) = @_;
|
|
|
|
$string =~ s/\s+$//;
|
|
|
|
return $string;
|
|
}
|
|
|
|
sub string_find_replace {
|
|
my ($string, $find, $replace) = @_;
|
|
|
|
$string =~ s/$find/$replace/g;
|
|
|
|
return $string;
|
|
}
|
|
|
|
sub tabify {
|
|
my ($leading) = @_;
|
|
|
|
my $source_indent = 8;
|
|
my $max_spaces_before_tab = $source_indent - 1;
|
|
my $spaces_to_tab = " " x $source_indent;
|
|
|
|
#convert leading spaces to tabs
|
|
1 while $leading =~ s@^([\t]*)$spaces_to_tab@$1\t@g;
|
|
#Remove spaces before a tab
|
|
1 while $leading =~ s@^([\t]*)( {1,$max_spaces_before_tab})\t@$1\t@g;
|
|
|
|
return "$leading";
|
|
}
|
|
|
|
sub cleanup_continuation_headers {
|
|
# Collapse any header-continuation lines into a single line so they
|
|
# can be parsed meaningfully, as the parser only has one line
|
|
# of context to work with.
|
|
my $again;
|
|
do {
|
|
$again = 0;
|
|
foreach my $n (0 .. scalar(@rawlines) - 2) {
|
|
if ($rawlines[$n]=~/^\s*$/) {
|
|
# A blank line means there's no more chance
|
|
# of finding headers. Shortcut to done.
|
|
return;
|
|
}
|
|
if ($rawlines[$n]=~/^[\x21-\x39\x3b-\x7e]+:/ &&
|
|
$rawlines[$n+1]=~/^\s+/) {
|
|
# Continuation header. Collapse it.
|
|
my $line = splice @rawlines, $n+1, 1;
|
|
$line=~s/^\s+/ /;
|
|
$rawlines[$n] .= $line;
|
|
# We've 'destabilized' the list, so restart.
|
|
$again = 1;
|
|
last;
|
|
}
|
|
}
|
|
} while ($again);
|
|
}
|
|
|
|
sub pos_last_openparen {
|
|
my ($line) = @_;
|
|
|
|
my $pos = 0;
|
|
|
|
my $opens = $line =~ tr/\(/\(/;
|
|
my $closes = $line =~ tr/\)/\)/;
|
|
|
|
my $last_openparen = 0;
|
|
|
|
if (($opens == 0) || ($closes >= $opens)) {
|
|
return -1;
|
|
}
|
|
|
|
my $len = length($line);
|
|
|
|
for ($pos = 0; $pos < $len; $pos++) {
|
|
my $string = substr($line, $pos);
|
|
if ($string =~ /^($FuncArg|$balanced_parens)/) {
|
|
$pos += length($1) - 1;
|
|
} elsif (substr($line, $pos, 1) eq '(') {
|
|
$last_openparen = $pos;
|
|
} elsif (index($string, '(') == -1) {
|
|
last;
|
|
}
|
|
}
|
|
|
|
return length(expand_tabs(substr($line, 0, $last_openparen))) + 1;
|
|
}
|
|
|
|
sub process {
|
|
my $filename = shift;
|
|
|
|
my $linenr=0;
|
|
my $prevline="";
|
|
my $prevrawline="";
|
|
my $stashline="";
|
|
my $stashrawline="";
|
|
my $subjectline="";
|
|
my $sublinenr="";
|
|
|
|
my $length;
|
|
my $indent;
|
|
my $previndent=0;
|
|
my $stashindent=0;
|
|
|
|
our $clean = 1;
|
|
my $signoff = 0;
|
|
my $is_patch = 0;
|
|
my $in_header_lines = $file ? 0 : 1;
|
|
my $in_commit_log = 0; #Scanning lines before patch
|
|
my $commit_log_possible_stack_dump = 0;
|
|
my $commit_log_long_line = 0;
|
|
my $commit_log_has_diff = 0;
|
|
my $reported_maintainer_file = 0;
|
|
my $non_utf8_charset = 0;
|
|
|
|
my $last_blank_line = 0;
|
|
my $last_coalesced_string_linenr = -1;
|
|
|
|
our @report = ();
|
|
our $cnt_lines = 0;
|
|
our $cnt_error = 0;
|
|
our $cnt_warn = 0;
|
|
our $cnt_chk = 0;
|
|
|
|
# Trace the real file/line as we go.
|
|
my $realfile = '';
|
|
my $realline = 0;
|
|
my $realcnt = 0;
|
|
my $here = '';
|
|
my $in_comment = 0;
|
|
my $comment_edge = 0;
|
|
my $first_line = 0;
|
|
my $p1_prefix = '';
|
|
|
|
my $prev_values = 'E';
|
|
|
|
# suppression flags
|
|
my %suppress_ifbraces;
|
|
my %suppress_whiletrailers;
|
|
my %suppress_export;
|
|
my $suppress_statement = 0;
|
|
|
|
my %signatures = ();
|
|
|
|
# Pre-scan the patch sanitizing the lines.
|
|
# Pre-scan the patch looking for any __setup documentation.
|
|
#
|
|
my @setup_docs = ();
|
|
my $setup_docs = 0;
|
|
|
|
my $camelcase_file_seeded = 0;
|
|
my $shorttext = BEFORE_SHORTTEXT;
|
|
my $shorttext_exspc = 0;
|
|
my $commit_text_present = 0;
|
|
|
|
sanitise_line_reset();
|
|
cleanup_continuation_headers();
|
|
my $line;
|
|
|
|
foreach my $rawline (@rawlines) {
|
|
$linenr++;
|
|
$line = $rawline;
|
|
|
|
push(@fixed, $rawline) if ($fix);
|
|
|
|
if ($rawline=~/^\+\+\+\s+(\S+)/) {
|
|
$setup_docs = 0;
|
|
if ($1 =~ m@Documentation/kernel-parameters.txt$@) {
|
|
$setup_docs = 1;
|
|
}
|
|
#next;
|
|
}
|
|
if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
|
|
$realline=$1-1;
|
|
if (defined $2) {
|
|
$realcnt=$3+1;
|
|
} else {
|
|
$realcnt=1+1;
|
|
}
|
|
$in_comment = 0;
|
|
|
|
# Guestimate if this is a continuing comment. Run
|
|
# the context looking for a comment "edge". If this
|
|
# edge is a close comment then we must be in a comment
|
|
# at context start.
|
|
my $edge;
|
|
my $cnt = $realcnt;
|
|
for (my $ln = $linenr + 1; $cnt > 0; $ln++) {
|
|
next if (defined $rawlines[$ln - 1] &&
|
|
$rawlines[$ln - 1] =~ /^-/);
|
|
$cnt--;
|
|
#print "RAW<$rawlines[$ln - 1]>\n";
|
|
last if (!defined $rawlines[$ln - 1]);
|
|
if ($rawlines[$ln - 1] =~ m@(/\*|\*/)@ &&
|
|
$rawlines[$ln - 1] !~ m@"[^"]*(?:/\*|\*/)[^"]*"@) {
|
|
($edge) = $1;
|
|
last;
|
|
}
|
|
}
|
|
if (defined $edge && $edge eq '*/') {
|
|
$in_comment = 1;
|
|
}
|
|
|
|
# Guestimate if this is a continuing comment. If this
|
|
# is the start of a diff block and this line starts
|
|
# ' *' then it is very likely a comment.
|
|
if (!defined $edge &&
|
|
$rawlines[$linenr] =~ m@^.\s*(?:\*\*+| \*)(?:\s|$)@)
|
|
{
|
|
$in_comment = 1;
|
|
}
|
|
|
|
##print "COMMENT:$in_comment edge<$edge> $rawline\n";
|
|
sanitise_line_reset($in_comment);
|
|
|
|
} elsif ($realcnt && $rawline =~ /^(?:\+| |$)/) {
|
|
# Standardise the strings and chars within the input to
|
|
# simplify matching -- only bother with positive lines.
|
|
$line = sanitise_line($rawline);
|
|
}
|
|
push(@lines, $line);
|
|
|
|
if ($realcnt > 1) {
|
|
$realcnt-- if ($line =~ /^(?:\+| |$)/);
|
|
} else {
|
|
$realcnt = 0;
|
|
}
|
|
|
|
#print "==>$rawline\n";
|
|
#print "-->$line\n";
|
|
|
|
if ($setup_docs && $line =~ /^\+/) {
|
|
push(@setup_docs, $line);
|
|
}
|
|
}
|
|
|
|
$prefix = '';
|
|
|
|
$realcnt = 0;
|
|
$linenr = 0;
|
|
$fixlinenr = -1;
|
|
foreach my $line (@lines) {
|
|
$linenr++;
|
|
$fixlinenr++;
|
|
my $sline = $line; #copy of $line
|
|
$sline =~ s/$;/ /g; #with comments as spaces
|
|
|
|
my $rawline = $rawlines[$linenr - 1];
|
|
|
|
#extract the line range in the file after the patch is applied
|
|
if (!$in_commit_log &&
|
|
$line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
|
|
$is_patch = 1;
|
|
$first_line = $linenr + 1;
|
|
$realline=$1-1;
|
|
if (defined $2) {
|
|
$realcnt=$3+1;
|
|
} else {
|
|
$realcnt=1+1;
|
|
}
|
|
annotate_reset();
|
|
$prev_values = 'E';
|
|
|
|
%suppress_ifbraces = ();
|
|
%suppress_whiletrailers = ();
|
|
%suppress_export = ();
|
|
$suppress_statement = 0;
|
|
next;
|
|
|
|
# track the line number as we move through the hunk, note that
|
|
# new versions of GNU diff omit the leading space on completely
|
|
# blank context lines so we need to count that too.
|
|
} elsif ($line =~ /^( |\+|$)/) {
|
|
$realline++;
|
|
$realcnt-- if ($realcnt != 0);
|
|
|
|
# Measure the line length and indent.
|
|
($length, $indent) = line_stats($rawline);
|
|
|
|
# Track the previous line.
|
|
($prevline, $stashline) = ($stashline, $line);
|
|
($previndent, $stashindent) = ($stashindent, $indent);
|
|
($prevrawline, $stashrawline) = ($stashrawline, $rawline);
|
|
|
|
#warn "line<$line>\n";
|
|
|
|
} elsif ($realcnt == 1) {
|
|
$realcnt--;
|
|
}
|
|
|
|
my $hunk_line = ($realcnt != 0);
|
|
|
|
$here = "#$linenr: " if (!$file);
|
|
$here = "#$realline: " if ($file);
|
|
|
|
my $found_file = 0;
|
|
# extract the filename as it passes
|
|
if ($line =~ /^diff --git.*?(\S+)$/) {
|
|
$realfile = $1;
|
|
$realfile =~ s@^([^/]*)/@@ if (!$file);
|
|
$in_commit_log = 0;
|
|
$found_file = 1;
|
|
} elsif ($line =~ /^\+\+\+\s+(\S+)/) {
|
|
$realfile = $1;
|
|
$realfile =~ s@^([^/]*)/@@ if (!$file);
|
|
$in_commit_log = 0;
|
|
|
|
$p1_prefix = $1;
|
|
if (!$file && $tree && $p1_prefix ne '' &&
|
|
-e "$root/$p1_prefix") {
|
|
WARN("PATCH_PREFIX",
|
|
"patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
|
|
}
|
|
|
|
if ($realfile =~ m@^include/asm/@) {
|
|
ERROR("MODIFIED_INCLUDE_ASM",
|
|
"do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n");
|
|
}
|
|
$found_file = 1;
|
|
}
|
|
|
|
#make up the handle for any error we report on this line
|
|
if ($showfile) {
|
|
$prefix = "$realfile:$realline: "
|
|
} elsif ($emacs) {
|
|
if ($file) {
|
|
$prefix = "$filename:$realline: ";
|
|
} else {
|
|
$prefix = "$filename:$linenr: ";
|
|
}
|
|
}
|
|
|
|
if ($found_file) {
|
|
if ($realfile =~ m@^(?:drivers/net/|net/|drivers/staging/)@) {
|
|
$check = 1;
|
|
} else {
|
|
$check = $check_orig;
|
|
}
|
|
next;
|
|
}
|
|
$here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
|
|
|
|
my $hereline = "$here\n$rawline\n";
|
|
my $herecurr = "$here\n$rawline\n";
|
|
my $hereprev = "$here\n$prevrawline\n$rawline\n";
|
|
|
|
if ($shorttext != AFTER_SHORTTEXT) {
|
|
if ($shorttext == IN_SHORTTEXT_BLANKLINE && $line=~/\S/) {
|
|
# the subject line was just processed,
|
|
# a blank line must be next
|
|
WARN("NONBLANK_AFTER_SUMMARY",
|
|
"non-blank line after summary line\n" . $herecurr);
|
|
$shorttext = IN_SHORTTEXT;
|
|
# this non-blank line may or may not be commit text -
|
|
# a warning has been generated so assume it is commit
|
|
# text and move on
|
|
$commit_text_present = 1;
|
|
# fall through and treat this line as IN_SHORTTEXT
|
|
}
|
|
if ($shorttext == IN_SHORTTEXT) {
|
|
if ($line=~/^---/ || $line=~/^diff.*/) {
|
|
if ($commit_text_present == 0) {
|
|
WARN("NO_COMMIT_TEXT",
|
|
"please add commit text explaining " .
|
|
"*why* the change is needed\n" .
|
|
$herecurr);
|
|
}
|
|
$shorttext = AFTER_SHORTTEXT;
|
|
} elsif (length($line) > (SHORTTEXT_LIMIT +
|
|
$shorttext_exspc)
|
|
&& $line !~ /^:([0-7]{6}\s){2}
|
|
([[:xdigit:]]+\.*
|
|
\s){2}\w+\s\w+/xms) {
|
|
WARN("LONG_COMMIT_TEXT",
|
|
"commit text line over " .
|
|
SHORTTEXT_LIMIT .
|
|
" characters\n" . $herecurr);
|
|
} elsif ($line=~/^\s*change-id:/i ||
|
|
$line=~/^\s*signed-off-by:/i ||
|
|
$line=~/^\s*crs-fixed:/i ||
|
|
$line=~/^\s*acked-by:/i) {
|
|
# this is a tag, there must be commit
|
|
# text by now
|
|
if ($commit_text_present == 0) {
|
|
WARN("NO_COMMIT_TEXT",
|
|
"please add commit text explaining " .
|
|
"*why* the change is needed\n" .
|
|
$herecurr);
|
|
# prevent duplicate warnings
|
|
$commit_text_present = 1;
|
|
}
|
|
} elsif ($line=~/\S/) {
|
|
$commit_text_present = 1;
|
|
}
|
|
} elsif ($shorttext == IN_SHORTTEXT_BLANKLINE) {
|
|
# case of non-blank line in this state handled above
|
|
$shorttext = IN_SHORTTEXT;
|
|
} elsif ($shorttext == CHECK_NEXT_SHORTTEXT) {
|
|
# The Subject line doesn't have to be the last header in the patch.
|
|
# Avoid moving to the IN_SHORTTEXT state until clear of all headers.
|
|
# Per RFC5322, continuation lines must be folded, so any left-justified
|
|
# text which looks like a header is definitely a header.
|
|
if ($line!~/^[\x21-\x39\x3b-\x7e]+:/) {
|
|
$shorttext = IN_SHORTTEXT;
|
|
# Check for Subject line followed by a blank line.
|
|
if (length($line) != 0) {
|
|
WARN("NONBLANK_AFTER_SUMMARY",
|
|
"non-blank line after " .
|
|
"summary line\n" .
|
|
$sublinenr . $here .
|
|
"\n" . $subjectline .
|
|
"\n" . $line . "\n");
|
|
# this non-blank line may or may not
|
|
# be commit text - a warning has been
|
|
# generated so assume it is commit
|
|
# text and move on
|
|
$commit_text_present = 1;
|
|
}
|
|
}
|
|
# The next two cases are BEFORE_SHORTTEXT.
|
|
} elsif ($line=~/^Subject: \[[^\]]*\] (.*)/) {
|
|
# This is the subject line. Go to
|
|
# CHECK_NEXT_SHORTTEXT to wait for the commit
|
|
# text to show up.
|
|
$shorttext = CHECK_NEXT_SHORTTEXT;
|
|
$subjectline = $line;
|
|
$sublinenr = "#$linenr & ";
|
|
# Check for Subject line less than line limit
|
|
if (length($1) > SHORTTEXT_LIMIT && !($1 =~ m/Revert\ \"/)) {
|
|
WARN("LONG_SUMMARY_LINE",
|
|
"summary line over " .
|
|
SHORTTEXT_LIMIT .
|
|
" characters\n" . $herecurr);
|
|
}
|
|
} elsif ($line=~/^ (.*)/) {
|
|
# Indented format, this must be the summary
|
|
# line (i.e. git show). There will be no more
|
|
# headers so we are now in the shorttext.
|
|
$shorttext = IN_SHORTTEXT_BLANKLINE;
|
|
$shorttext_exspc = 4;
|
|
if (length($1) > SHORTTEXT_LIMIT && !($1 =~ m/Revert\ \"/)) {
|
|
WARN("LONG_SUMMARY_LINE",
|
|
"summary line over " .
|
|
SHORTTEXT_LIMIT .
|
|
" characters\n" . $herecurr);
|
|
}
|
|
}
|
|
}
|
|
|
|
$cnt_lines++ if ($realcnt != 0);
|
|
|
|
# Check if the commit log has what seems like a diff which can confuse patch
|
|
if ($in_commit_log && !$commit_log_has_diff &&
|
|
(($line =~ m@^\s+diff\b.*a/([\w/]+)@ &&
|
|
$line =~ m@^\s+diff\b.*a/[\w/]+\s+b/$1\b@) ||
|
|
$line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
|
|
$line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
|
|
ERROR("DIFF_IN_COMMIT_MSG",
|
|
"Avoid using diff content in the commit message - patch(1) might not work\n" . $herecurr);
|
|
$commit_log_has_diff = 1;
|
|
}
|
|
|
|
# Check for incorrect file permissions
|
|
if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
|
|
my $permhere = $here . "FILE: $realfile\n";
|
|
if ($realfile !~ m@scripts/@ &&
|
|
$realfile !~ /\.(py|pl|awk|sh)$/) {
|
|
ERROR("EXECUTE_PERMISSIONS",
|
|
"do not set execute permissions for source files\n" . $permhere);
|
|
}
|
|
}
|
|
|
|
# Check the patch for a signoff:
|
|
if ($line =~ /^\s*signed-off-by:/i) {
|
|
$signoff++;
|
|
$in_commit_log = 0;
|
|
}
|
|
|
|
# Check if MAINTAINERS is being updated. If so, there's probably no need to
|
|
# emit the "does MAINTAINERS need updating?" message on file add/move/delete
|
|
if ($line =~ /^\s*MAINTAINERS\s*\|/) {
|
|
$reported_maintainer_file = 1;
|
|
}
|
|
|
|
# Check signature styles
|
|
if (!$in_header_lines &&
|
|
$line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) {
|
|
my $space_before = $1;
|
|
my $sign_off = $2;
|
|
my $space_after = $3;
|
|
my $email = $4;
|
|
my $ucfirst_sign_off = ucfirst(lc($sign_off));
|
|
|
|
if ($sign_off !~ /$signature_tags/) {
|
|
WARN("BAD_SIGN_OFF",
|
|
"Non-standard signature: $sign_off\n" . $herecurr);
|
|
}
|
|
if (defined $space_before && $space_before ne "") {
|
|
if (WARN("BAD_SIGN_OFF",
|
|
"Do not use whitespace before $ucfirst_sign_off\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =
|
|
"$ucfirst_sign_off $email";
|
|
}
|
|
}
|
|
if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
|
|
if (WARN("BAD_SIGN_OFF",
|
|
"'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =
|
|
"$ucfirst_sign_off $email";
|
|
}
|
|
|
|
}
|
|
if (!defined $space_after || $space_after ne " ") {
|
|
if (WARN("BAD_SIGN_OFF",
|
|
"Use a single space after $ucfirst_sign_off\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =
|
|
"$ucfirst_sign_off $email";
|
|
}
|
|
}
|
|
|
|
my ($email_name, $email_address, $comment) = parse_email($email);
|
|
my $suggested_email = format_email(($email_name, $email_address));
|
|
if ($suggested_email eq "") {
|
|
ERROR("BAD_SIGN_OFF",
|
|
"Unrecognized email address: '$email'\n" . $herecurr);
|
|
} else {
|
|
my $dequoted = $suggested_email;
|
|
$dequoted =~ s/^"//;
|
|
$dequoted =~ s/" </ </;
|
|
# Don't force email to have quotes
|
|
# Allow just an angle bracketed address
|
|
if ("$dequoted$comment" ne $email &&
|
|
"<$email_address>$comment" ne $email &&
|
|
"$suggested_email$comment" ne $email) {
|
|
WARN("BAD_SIGN_OFF",
|
|
"email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr);
|
|
}
|
|
}
|
|
if ($chk_author) {
|
|
if ($line =~ /^\s*signed-off-by:.*qca\.qualcomm\.com/i) {
|
|
$qca_sign_off = 1;
|
|
} elsif ($line =~ /^\s*signed-off-by:.*codeaurora\.org/i) {
|
|
$codeaurora_sign_off = 1;
|
|
} elsif ($line =~ /^\s*signed-off-by:.*(quicinc|qualcomm)\.com/i) {
|
|
WARN("BAD_SIGN_OFF",
|
|
"invalid Signed-off-by identity\n" . $line );
|
|
}
|
|
}
|
|
|
|
# Check for duplicate signatures
|
|
my $sig_nospace = $line;
|
|
$sig_nospace =~ s/\s//g;
|
|
$sig_nospace = lc($sig_nospace);
|
|
if (defined $signatures{$sig_nospace}) {
|
|
WARN("BAD_SIGN_OFF",
|
|
"Duplicate signature\n" . $herecurr);
|
|
} else {
|
|
$signatures{$sig_nospace} = 1;
|
|
}
|
|
}
|
|
|
|
# Check email subject for common tools that don't need to be mentioned
|
|
if ($in_header_lines &&
|
|
$line =~ /^Subject:.*\b(?:checkpatch|sparse|smatch)\b[^:]/i) {
|
|
WARN("EMAIL_SUBJECT",
|
|
"A patch subject line should describe the change not the tool that found it\n" . $herecurr);
|
|
}
|
|
|
|
# Check for old stable address
|
|
if ($line =~ /^\s*cc:\s*.*<?\bstable\@kernel\.org\b>?.*$/i) {
|
|
ERROR("STABLE_ADDRESS",
|
|
"The 'stable' address should be 'stable\@vger.kernel.org'\n" . $herecurr);
|
|
}
|
|
|
|
# Check if the commit log is in a possible stack dump
|
|
if ($in_commit_log && !$commit_log_possible_stack_dump &&
|
|
($line =~ /^\s*(?:WARNING:|BUG:)/ ||
|
|
$line =~ /^\s*\[\s*\d+\.\d{6,6}\s*\]/ ||
|
|
# timestamp
|
|
$line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/)) {
|
|
# stack dump address
|
|
$commit_log_possible_stack_dump = 1;
|
|
}
|
|
|
|
# Check for line lengths > 75 in commit log, warn once
|
|
if ($in_commit_log && !$commit_log_long_line &&
|
|
length($line) > 75 &&
|
|
!($line =~ /^\s*[a-zA-Z0-9_\/\.]+\s+\|\s+\d+/ ||
|
|
# file delta changes
|
|
$line =~ /^\s*(?:[\w\.\-]+\/)++[\w\.\-]+:/ ||
|
|
# filename then :
|
|
$line =~ /^\s*(?:Fixes:|Link:)/i ||
|
|
# A Fixes: or Link: line
|
|
$commit_log_possible_stack_dump)) {
|
|
WARN("COMMIT_LOG_LONG_LINE",
|
|
"Possible unwrapped commit description (prefer a maximum 75 chars per line)\n" . $herecurr);
|
|
$commit_log_long_line = 1;
|
|
}
|
|
|
|
# Reset possible stack dump if a blank line is found
|
|
if ($in_commit_log && $commit_log_possible_stack_dump &&
|
|
$line =~ /^\s*$/) {
|
|
$commit_log_possible_stack_dump = 0;
|
|
}
|
|
|
|
# Check for git id commit length and improperly formed commit descriptions
|
|
if ($in_commit_log && !$commit_log_possible_stack_dump &&
|
|
$line !~ /^This reverts commit [0-9a-f]{7,40}/ &&
|
|
($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
|
|
($line =~ /\b[0-9a-f]{12,40}\b/i &&
|
|
$line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i &&
|
|
$line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) {
|
|
my $init_char = "c";
|
|
my $orig_commit = "";
|
|
my $short = 1;
|
|
my $long = 0;
|
|
my $case = 1;
|
|
my $space = 1;
|
|
my $hasdesc = 0;
|
|
my $hasparens = 0;
|
|
my $id = '0123456789ab';
|
|
my $orig_desc = "commit description";
|
|
my $description = "";
|
|
|
|
if ($line =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
|
|
$init_char = $1;
|
|
$orig_commit = lc($2);
|
|
} elsif ($line =~ /\b([0-9a-f]{12,40})\b/i) {
|
|
$orig_commit = lc($1);
|
|
}
|
|
|
|
$short = 0 if ($line =~ /\bcommit\s+[0-9a-f]{12,40}/i);
|
|
$long = 1 if ($line =~ /\bcommit\s+[0-9a-f]{41,}/i);
|
|
$space = 0 if ($line =~ /\bcommit [0-9a-f]/i);
|
|
$case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
|
|
if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) {
|
|
$orig_desc = $1;
|
|
$hasparens = 1;
|
|
} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i &&
|
|
defined $rawlines[$linenr] &&
|
|
$rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) {
|
|
$orig_desc = $1;
|
|
$hasparens = 1;
|
|
} elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
|
|
defined $rawlines[$linenr] &&
|
|
$rawlines[$linenr] =~ /^\s*[^"]+"\)/) {
|
|
$line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
|
|
$orig_desc = $1;
|
|
$rawlines[$linenr] =~ /^\s*([^"]+)"\)/;
|
|
$orig_desc .= " " . $1;
|
|
$hasparens = 1;
|
|
}
|
|
|
|
($id, $description) = git_commit_info($orig_commit,
|
|
$id, $orig_desc);
|
|
|
|
if ($short || $long || $space || $case || ($orig_desc ne $description) || !$hasparens) {
|
|
ERROR("GIT_COMMIT_ID",
|
|
"Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
# Check for added, moved or deleted files
|
|
if (!$reported_maintainer_file && !$in_commit_log &&
|
|
($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ ||
|
|
$line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ ||
|
|
($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&
|
|
(defined($1) || defined($2))))) {
|
|
$reported_maintainer_file = 1;
|
|
WARN("FILE_PATH_CHANGES",
|
|
"added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);
|
|
}
|
|
|
|
#check the patch for invalid author credentials
|
|
if ($chk_author && !($line =~ /^From:.*qca\.qualcomm\.com/) &&
|
|
$line =~ /^From:.*(quicinc|qualcomm)\.com/) {
|
|
WARN("BAD_AUTHOR", "invalid author identity\n" . $line );
|
|
}
|
|
|
|
# Check for wrappage within a valid hunk of the file
|
|
if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
|
|
ERROR("CORRUPTED_PATCH",
|
|
"patch seems to be corrupt (line wrapped?)\n" .
|
|
$herecurr) if (!$emitted_corrupt++);
|
|
}
|
|
|
|
# Check for absolute kernel paths.
|
|
if ($tree) {
|
|
while ($line =~ m{(?:^|\s)(/\S*)}g) {
|
|
my $file = $1;
|
|
|
|
if ($file =~ m{^(.*?)(?::\d+)+:?$} &&
|
|
check_absolute_file($1, $herecurr)) {
|
|
#
|
|
} else {
|
|
check_absolute_file($file, $herecurr);
|
|
}
|
|
}
|
|
}
|
|
|
|
# UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
|
|
if (($realfile =~ /^$/ || $line =~ /^\+/) &&
|
|
$rawline !~ m/^$UTF8*$/) {
|
|
my ($utf8_prefix) = ($rawline =~ /^($UTF8*)/);
|
|
|
|
my $blank = copy_spacing($rawline);
|
|
my $ptr = substr($blank, 0, length($utf8_prefix)) . "^";
|
|
my $hereptr = "$hereline$ptr\n";
|
|
|
|
CHK("INVALID_UTF8",
|
|
"Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
|
|
}
|
|
|
|
# Check if it's the start of a commit log
|
|
# (not a header line and we haven't seen the patch filename)
|
|
if ($in_header_lines && $realfile =~ /^$/ &&
|
|
!($rawline =~ /^\s+\S/ ||
|
|
$rawline =~ /^(commit\b|from\b|[\w-]+:).*$/i)) {
|
|
$in_header_lines = 0;
|
|
$in_commit_log = 1;
|
|
}
|
|
|
|
# Check if there is UTF-8 in a commit log when a mail header has explicitly
|
|
# declined it, i.e defined some charset where it is missing.
|
|
if ($in_header_lines &&
|
|
$rawline =~ /^Content-Type:.+charset="(.+)".*$/ &&
|
|
$1 !~ /utf-8/i) {
|
|
$non_utf8_charset = 1;
|
|
}
|
|
|
|
if ($in_commit_log && $non_utf8_charset && $realfile =~ /^$/ &&
|
|
$rawline =~ /$NON_ASCII_UTF8/) {
|
|
WARN("UTF8_BEFORE_PATCH",
|
|
"8-bit UTF-8 used in possible commit log\n" . $herecurr);
|
|
}
|
|
|
|
# Check for various typo / spelling mistakes
|
|
if (defined($misspellings) &&
|
|
($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
|
|
while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:\b|$|[^a-z@])/gi) {
|
|
my $typo = $1;
|
|
my $typo_fix = $spelling_fix{lc($typo)};
|
|
$typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/);
|
|
$typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/);
|
|
my $msg_type = \&WARN;
|
|
$msg_type = \&CHK if ($file);
|
|
if (&{$msg_type}("TYPO_SPELLING",
|
|
"'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/;
|
|
}
|
|
}
|
|
}
|
|
|
|
# ignore non-hunk lines and lines being removed
|
|
next if (!$hunk_line || $line =~ /^-/);
|
|
|
|
#trailing whitespace
|
|
if ($line =~ /^\+.*\015/) {
|
|
my $herevet = "$here\n" . cat_vet($rawline) . "\n";
|
|
if (ERROR("DOS_LINE_ENDINGS",
|
|
"DOS line endings\n" . $herevet) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/[\s\015]+$//;
|
|
}
|
|
} elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
|
|
my $herevet = "$here\n" . cat_vet($rawline) . "\n";
|
|
if (ERROR("TRAILING_WHITESPACE",
|
|
"trailing whitespace\n" . $herevet) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\s+$//;
|
|
}
|
|
|
|
$rpt_cleaners = 1;
|
|
}
|
|
|
|
# Check for FSF mailing addresses.
|
|
if ($rawline =~ /\bwrite to the Free/i ||
|
|
$rawline =~ /\b59\s+Temple\s+Pl/i ||
|
|
$rawline =~ /\b51\s+Franklin\s+St/i) {
|
|
my $herevet = "$here\n" . cat_vet($rawline) . "\n";
|
|
my $msg_type = \&ERROR;
|
|
$msg_type = \&CHK if ($file);
|
|
&{$msg_type}("FSF_MAILING_ADDRESS",
|
|
"Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.\n" . $herevet)
|
|
}
|
|
|
|
# check for Kconfig help text having a real description
|
|
# Only applies when adding the entry originally, after that we do not have
|
|
# sufficient context to determine whether it is indeed long enough.
|
|
if ($realfile =~ /Kconfig/ &&
|
|
$line =~ /^\+\s*config\s+/) {
|
|
my $length = 0;
|
|
my $cnt = $realcnt;
|
|
my $ln = $linenr + 1;
|
|
my $f;
|
|
my $is_start = 0;
|
|
my $is_end = 0;
|
|
for (; $cnt > 0 && defined $lines[$ln - 1]; $ln++) {
|
|
$f = $lines[$ln - 1];
|
|
$cnt-- if ($lines[$ln - 1] !~ /^-/);
|
|
$is_end = $lines[$ln - 1] =~ /^\+/;
|
|
|
|
next if ($f =~ /^-/);
|
|
last if (!$file && $f =~ /^\@\@/);
|
|
|
|
if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate)\s*\"/) {
|
|
$is_start = 1;
|
|
} elsif ($lines[$ln - 1] =~ /^\+\s*(?:---)?help(?:---)?$/) {
|
|
$length = -1;
|
|
}
|
|
|
|
$f =~ s/^.//;
|
|
$f =~ s/#.*//;
|
|
$f =~ s/^\s+//;
|
|
next if ($f =~ /^$/);
|
|
if ($f =~ /^\s*config\s/) {
|
|
$is_end = 1;
|
|
last;
|
|
}
|
|
$length++;
|
|
}
|
|
if ($is_start && $is_end && $length < $min_conf_desc_length) {
|
|
WARN("CONFIG_DESCRIPTION",
|
|
"please write a paragraph that describes the config symbol fully\n" . $herecurr);
|
|
}
|
|
#print "is_start<$is_start> is_end<$is_end> length<$length>\n";
|
|
}
|
|
|
|
# discourage the addition of CONFIG_EXPERIMENTAL in Kconfig.
|
|
if ($realfile =~ /Kconfig/ &&
|
|
$line =~ /.\s*depends on\s+.*\bEXPERIMENTAL\b/) {
|
|
WARN("CONFIG_EXPERIMENTAL",
|
|
"Use of CONFIG_EXPERIMENTAL is deprecated. For alternatives, see https://lkml.org/lkml/2012/10/23/580\n");
|
|
}
|
|
|
|
# discourage the use of boolean for type definition attributes of Kconfig options
|
|
if ($realfile =~ /Kconfig/ &&
|
|
$line =~ /^\+\s*\bboolean\b/) {
|
|
WARN("CONFIG_TYPE_BOOLEAN",
|
|
"Use of boolean is deprecated, please use bool instead.\n" . $herecurr);
|
|
}
|
|
|
|
if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) &&
|
|
($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) {
|
|
my $flag = $1;
|
|
my $replacement = {
|
|
'EXTRA_AFLAGS' => 'asflags-y',
|
|
'EXTRA_CFLAGS' => 'ccflags-y',
|
|
'EXTRA_CPPFLAGS' => 'cppflags-y',
|
|
'EXTRA_LDFLAGS' => 'ldflags-y',
|
|
};
|
|
|
|
WARN("DEPRECATED_VARIABLE",
|
|
"Use of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacement->{$flag});
|
|
}
|
|
|
|
# check for DT compatible documentation
|
|
if (defined $root &&
|
|
(($realfile =~ /\.dtsi?$/ && $line =~ /^\+\s*compatible\s*=\s*\"/) ||
|
|
($realfile =~ /\.[ch]$/ && $line =~ /^\+.*\.compatible\s*=\s*\"/))) {
|
|
|
|
my @compats = $rawline =~ /\"([a-zA-Z0-9\-\,\.\+_]+)\"/g;
|
|
|
|
my $dt_path = $root . "/Documentation/devicetree/bindings/";
|
|
my $vp_file = $dt_path . "vendor-prefixes.txt";
|
|
|
|
foreach my $compat (@compats) {
|
|
my $compat2 = $compat;
|
|
$compat2 =~ s/\,[a-zA-Z0-9]*\-/\,<\.\*>\-/;
|
|
my $compat3 = $compat;
|
|
$compat3 =~ s/\,([a-z]*)[0-9]*\-/\,$1<\.\*>\-/;
|
|
`grep -Erq "$compat|$compat2|$compat3" $dt_path`;
|
|
if ( $? >> 8 ) {
|
|
WARN("UNDOCUMENTED_DT_STRING",
|
|
"DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr);
|
|
}
|
|
|
|
next if $compat !~ /^([a-zA-Z0-9\-]+)\,/;
|
|
my $vendor = $1;
|
|
`grep -Eq "^$vendor\\b" $vp_file`;
|
|
if ( $? >> 8 ) {
|
|
WARN("UNDOCUMENTED_DT_STRING",
|
|
"DT compatible string vendor \"$vendor\" appears un-documented -- check $vp_file\n" . $herecurr);
|
|
}
|
|
}
|
|
}
|
|
|
|
# check we are in a valid source file if not then ignore this hunk
|
|
next if ($realfile !~ /\.(h|c|s|S|pl|sh|dtsi|dts)$/);
|
|
|
|
# line length limit (with some exclusions)
|
|
#
|
|
# There are a few types of lines that may extend beyond $max_line_length:
|
|
# logging functions like pr_info that end in a string
|
|
# lines with a single string
|
|
# #defines that are a single string
|
|
#
|
|
# There are 3 different line length message types:
|
|
# LONG_LINE_COMMENT a comment starts before but extends beyond $max_linelength
|
|
# LONG_LINE_STRING a string starts before but extends beyond $max_line_length
|
|
# LONG_LINE all other lines longer than $max_line_length
|
|
#
|
|
# if LONG_LINE is ignored, the other 2 types are also ignored
|
|
#
|
|
if ($line =~ /^\+/ && $length > $max_line_length && $realfile ne "scripts/checkpatch.pl") {
|
|
my $msg_type = "LONG_LINE";
|
|
|
|
# Check the allowed long line types first
|
|
|
|
# logging functions that end in a string that starts
|
|
# before $max_line_length
|
|
if ($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(?:KERN_\S+\s*|[^"]*))?($String\s*(?:|,|\)\s*;)\s*)$/ &&
|
|
length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
|
|
$msg_type = "";
|
|
|
|
# lines with only strings (w/ possible termination)
|
|
# #defines with only strings
|
|
} elsif ($line =~ /^\+\s*$String\s*(?:\s*|,|\)\s*;)\s*$/ ||
|
|
$line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) {
|
|
$msg_type = "";
|
|
|
|
# Otherwise set the alternate message types
|
|
|
|
# a comment starts before $max_line_length
|
|
} elsif ($line =~ /($;[\s$;]*)$/ &&
|
|
length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
|
|
$msg_type = "LONG_LINE_COMMENT"
|
|
|
|
# a quoted string starts before $max_line_length
|
|
} elsif ($sline =~ /\s*($String(?:\s*(?:\\|,\s*|\)\s*;\s*))?)$/ &&
|
|
length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
|
|
$msg_type = "LONG_LINE_STRING"
|
|
}
|
|
|
|
if ($msg_type ne "" &&
|
|
(show_type("LONG_LINE") || show_type($msg_type))) {
|
|
WARN($msg_type,
|
|
"line over $max_line_length characters\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
# check for adding lines without a newline.
|
|
if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
|
|
WARN("MISSING_EOF_NEWLINE",
|
|
"adding a line without newline at end of file\n" . $herecurr);
|
|
}
|
|
|
|
# Blackfin: use hi/lo macros
|
|
if ($realfile =~ m@arch/blackfin/.*\.S$@) {
|
|
if ($line =~ /\.[lL][[:space:]]*=.*&[[:space:]]*0x[fF][fF][fF][fF]/) {
|
|
my $herevet = "$here\n" . cat_vet($line) . "\n";
|
|
ERROR("LO_MACRO",
|
|
"use the LO() macro, not (... & 0xFFFF)\n" . $herevet);
|
|
}
|
|
if ($line =~ /\.[hH][[:space:]]*=.*>>[[:space:]]*16/) {
|
|
my $herevet = "$here\n" . cat_vet($line) . "\n";
|
|
ERROR("HI_MACRO",
|
|
"use the HI() macro, not (... >> 16)\n" . $herevet);
|
|
}
|
|
}
|
|
|
|
# check we are in a valid source file C or perl if not then ignore this hunk
|
|
next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/);
|
|
|
|
# at the beginning of a line any tabs must come first and anything
|
|
# more than 8 must use tabs.
|
|
if ($rawline =~ /^\+\s* \t\s*\S/ ||
|
|
$rawline =~ /^\+\s* \s*/) {
|
|
my $herevet = "$here\n" . cat_vet($rawline) . "\n";
|
|
$rpt_cleaners = 1;
|
|
if (ERROR("CODE_INDENT",
|
|
"code indent should use tabs where possible\n" . $herevet) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
|
|
}
|
|
}
|
|
|
|
# check for space before tabs.
|
|
if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
|
|
my $herevet = "$here\n" . cat_vet($rawline) . "\n";
|
|
if (WARN("SPACE_BEFORE_TAB",
|
|
"please, no space before tabs\n" . $herevet) &&
|
|
$fix) {
|
|
while ($fixed[$fixlinenr] =~
|
|
s/(^\+.*) {8,8}\t/$1\t\t/) {}
|
|
while ($fixed[$fixlinenr] =~
|
|
s/(^\+.*) +\t/$1\t/) {}
|
|
}
|
|
}
|
|
|
|
# check for && or || at the start of a line
|
|
if ($rawline =~ /^\+\s*(&&|\|\|)/) {
|
|
CHK("LOGICAL_CONTINUATIONS",
|
|
"Logical continuations should be on the previous line\n" . $hereprev);
|
|
}
|
|
|
|
# check multi-line statement indentation matches previous line
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
$prevline =~ /^\+([ \t]*)((?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|$Ident\s*=\s*$Ident\s*)\(.*(\&\&|\|\||,)\s*$/) {
|
|
$prevline =~ /^\+(\t*)(.*)$/;
|
|
my $oldindent = $1;
|
|
my $rest = $2;
|
|
|
|
my $pos = pos_last_openparen($rest);
|
|
if ($pos >= 0) {
|
|
$line =~ /^(\+| )([ \t]*)/;
|
|
my $newindent = $2;
|
|
|
|
my $goodtabindent = $oldindent .
|
|
"\t" x ($pos / 8) .
|
|
" " x ($pos % 8);
|
|
my $goodspaceindent = $oldindent . " " x $pos;
|
|
|
|
if ($newindent ne $goodtabindent &&
|
|
$newindent ne $goodspaceindent) {
|
|
|
|
if (CHK("PARENTHESIS_ALIGNMENT",
|
|
"Alignment should match open parenthesis\n" . $hereprev) &&
|
|
$fix && $line =~ /^\+/) {
|
|
$fixed[$fixlinenr] =~
|
|
s/^\+[ \t]*/\+$goodtabindent/;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
# check for space after cast like "(int) foo" or "(struct foo) bar"
|
|
# avoid checking a few false positives:
|
|
# "sizeof(<type>)" or "__alignof__(<type>)"
|
|
# function pointer declarations like "(*foo)(int) = bar;"
|
|
# structure definitions like "(struct foo) { 0 };"
|
|
# multiline macros that define functions
|
|
# known attributes or the __attribute__ keyword
|
|
if ($line =~ /^\+(.*)\(\s*$Type\s*\)([ \t]++)((?![={]|\\$|$Attribute|__attribute__))/ &&
|
|
(!defined($1) || $1 !~ /\b(?:sizeof|__alignof__)\s*$/)) {
|
|
if (CHK("SPACING",
|
|
"No space is necessary after a cast\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~
|
|
s/(\(\s*$Type\s*\))[ \t]+/$1/;
|
|
}
|
|
}
|
|
|
|
# Block comment styles
|
|
# Networking with an initial /*
|
|
if ($realfile =~ m@^(drivers/net/|net/)@ &&
|
|
$prevrawline =~ /^\+[ \t]*\/\*[ \t]*$/ &&
|
|
$rawline =~ /^\+[ \t]*\*/ &&
|
|
$realline > 2) {
|
|
WARN("NETWORKING_BLOCK_COMMENT_STYLE",
|
|
"networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
|
|
}
|
|
|
|
# Block comments use * on subsequent lines
|
|
if ($prevline =~ /$;[ \t]*$/ && #ends in comment
|
|
$prevrawline =~ /^\+.*?\/\*/ && #starting /*
|
|
$prevrawline !~ /\*\/[ \t]*$/ && #no trailing */
|
|
$rawline =~ /^\+/ && #line is new
|
|
$rawline !~ /^\+[ \t]*\*/) { #no leading *
|
|
WARN("BLOCK_COMMENT_STYLE",
|
|
"Block comments use * on subsequent lines\n" . $hereprev);
|
|
}
|
|
|
|
# Block comments use */ on trailing lines
|
|
if ($rawline !~ m@^\+[ \t]*\*/[ \t]*$@ && #trailing */
|
|
$rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/
|
|
$rawline !~ m@^\+.*\*{2,}/[ \t]*$@ && #trailing **/
|
|
$rawline =~ m@^\+[ \t]*.+\*\/[ \t]*$@) { #non blank */
|
|
WARN("BLOCK_COMMENT_STYLE",
|
|
"Block comments use a trailing */ on a separate line\n" . $herecurr);
|
|
}
|
|
|
|
# check for missing blank lines after struct/union declarations
|
|
# with exceptions for various attributes and macros
|
|
if ($prevline =~ /^[\+ ]};?\s*$/ &&
|
|
$line =~ /^\+/ &&
|
|
!($line =~ /^\+\s*$/ ||
|
|
$line =~ /^\+\s*EXPORT_SYMBOL/ ||
|
|
$line =~ /^\+\s*MODULE_/i ||
|
|
$line =~ /^\+\s*\#\s*(?:end|elif|else)/ ||
|
|
$line =~ /^\+[a-z_]*init/ ||
|
|
$line =~ /^\+\s*(?:static\s+)?[A-Z_]*ATTR/ ||
|
|
$line =~ /^\+\s*DECLARE/ ||
|
|
$line =~ /^\+\s*__setup/)) {
|
|
if (CHK("LINE_SPACING",
|
|
"Please use a blank line after function/struct/union/enum declarations\n" . $hereprev) &&
|
|
$fix) {
|
|
fix_insert_line($fixlinenr, "\+");
|
|
}
|
|
}
|
|
|
|
# check for multiple consecutive blank lines
|
|
if ($prevline =~ /^[\+ ]\s*$/ &&
|
|
$line =~ /^\+\s*$/ &&
|
|
$last_blank_line != ($linenr - 1)) {
|
|
if (CHK("LINE_SPACING",
|
|
"Please don't use multiple blank lines\n" . $hereprev) &&
|
|
$fix) {
|
|
fix_delete_line($fixlinenr, $rawline);
|
|
}
|
|
|
|
$last_blank_line = $linenr;
|
|
}
|
|
|
|
# check for missing blank lines after declarations
|
|
if ($sline =~ /^\+\s+\S/ && #Not at char 1
|
|
# actual declarations
|
|
($prevline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
|
|
# function pointer declarations
|
|
$prevline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
|
|
# foo bar; where foo is some local typedef or #define
|
|
$prevline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
|
|
# known declaration macros
|
|
$prevline =~ /^\+\s+$declaration_macros/) &&
|
|
# for "else if" which can look like "$Ident $Ident"
|
|
!($prevline =~ /^\+\s+$c90_Keywords\b/ ||
|
|
# other possible extensions of declaration lines
|
|
$prevline =~ /(?:$Compare|$Assignment|$Operators)\s*$/ ||
|
|
# not starting a section or a macro "\" extended line
|
|
$prevline =~ /(?:\{\s*|\\)$/) &&
|
|
# looks like a declaration
|
|
!($sline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
|
|
# function pointer declarations
|
|
$sline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
|
|
# foo bar; where foo is some local typedef or #define
|
|
$sline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
|
|
# known declaration macros
|
|
$sline =~ /^\+\s+$declaration_macros/ ||
|
|
# start of struct or union or enum
|
|
$sline =~ /^\+\s+(?:union|struct|enum|typedef)\b/ ||
|
|
# start or end of block or continuation of declaration
|
|
$sline =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ ||
|
|
# bitfield continuation
|
|
$sline =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ ||
|
|
# other possible extensions of declaration lines
|
|
$sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/) &&
|
|
# indentation of previous and current line are the same
|
|
(($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/)) {
|
|
if (WARN("LINE_SPACING",
|
|
"Missing a blank line after declarations\n" . $hereprev) &&
|
|
$fix) {
|
|
fix_insert_line($fixlinenr, "\+");
|
|
}
|
|
}
|
|
|
|
# check for spaces at the beginning of a line.
|
|
# Exceptions:
|
|
# 1) within comments
|
|
# 2) indented preprocessor commands
|
|
# 3) hanging labels
|
|
if ($rawline =~ /^\+ / && $line !~ /^\+ *(?:$;|#|$Ident:)/) {
|
|
my $herevet = "$here\n" . cat_vet($rawline) . "\n";
|
|
if (WARN("LEADING_SPACE",
|
|
"please, no spaces at the start of a line\n" . $herevet) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
|
|
}
|
|
}
|
|
|
|
# check we are in a valid C source file if not then ignore this hunk
|
|
next if ($realfile !~ /\.(h|c)$/);
|
|
|
|
# check indentation of any line with a bare else
|
|
# (but not if it is a multiple line "if (foo) return bar; else return baz;")
|
|
# if the previous line is a break or return and is indented 1 tab more...
|
|
if ($sline =~ /^\+([\t]+)(?:}[ \t]*)?else(?:[ \t]*{)?\s*$/) {
|
|
my $tabs = length($1) + 1;
|
|
if ($prevline =~ /^\+\t{$tabs,$tabs}break\b/ ||
|
|
($prevline =~ /^\+\t{$tabs,$tabs}return\b/ &&
|
|
defined $lines[$linenr] &&
|
|
$lines[$linenr] !~ /^[ \+]\t{$tabs,$tabs}return/)) {
|
|
WARN("UNNECESSARY_ELSE",
|
|
"else is not generally useful after a break or return\n" . $hereprev);
|
|
}
|
|
}
|
|
|
|
# check indentation of a line with a break;
|
|
# if the previous line is a goto or return and is indented the same # of tabs
|
|
if ($sline =~ /^\+([\t]+)break\s*;\s*$/) {
|
|
my $tabs = $1;
|
|
if ($prevline =~ /^\+$tabs(?:goto|return)\b/) {
|
|
WARN("UNNECESSARY_BREAK",
|
|
"break is not useful after a goto or return\n" . $hereprev);
|
|
}
|
|
}
|
|
|
|
# discourage the addition of CONFIG_EXPERIMENTAL in #if(def).
|
|
if ($line =~ /^\+\s*\#\s*if.*\bCONFIG_EXPERIMENTAL\b/) {
|
|
WARN("CONFIG_EXPERIMENTAL",
|
|
"Use of CONFIG_EXPERIMENTAL is deprecated. For alternatives, see https://lkml.org/lkml/2012/10/23/580\n");
|
|
}
|
|
|
|
# check for RCS/CVS revision markers
|
|
if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) {
|
|
WARN("CVS_KEYWORD",
|
|
"CVS style keyword markers, these will _not_ be updated\n". $herecurr);
|
|
}
|
|
|
|
# Blackfin: don't use __builtin_bfin_[cs]sync
|
|
if ($line =~ /__builtin_bfin_csync/) {
|
|
my $herevet = "$here\n" . cat_vet($line) . "\n";
|
|
ERROR("CSYNC",
|
|
"use the CSYNC() macro in asm/blackfin.h\n" . $herevet);
|
|
}
|
|
if ($line =~ /__builtin_bfin_ssync/) {
|
|
my $herevet = "$here\n" . cat_vet($line) . "\n";
|
|
ERROR("SSYNC",
|
|
"use the SSYNC() macro in asm/blackfin.h\n" . $herevet);
|
|
}
|
|
|
|
# check for old HOTPLUG __dev<foo> section markings
|
|
if ($line =~ /\b(__dev(init|exit)(data|const|))\b/) {
|
|
WARN("HOTPLUG_SECTION",
|
|
"Using $1 is unnecessary\n" . $herecurr);
|
|
}
|
|
|
|
# Check for potential 'bare' types
|
|
my ($stat, $cond, $line_nr_next, $remain_next, $off_next,
|
|
$realline_next);
|
|
#print "LINE<$line>\n";
|
|
if ($linenr >= $suppress_statement &&
|
|
$realcnt && $sline =~ /.\s*\S/) {
|
|
($stat, $cond, $line_nr_next, $remain_next, $off_next) =
|
|
ctx_statement_block($linenr, $realcnt, 0);
|
|
$stat =~ s/\n./\n /g;
|
|
$cond =~ s/\n./\n /g;
|
|
|
|
#print "linenr<$linenr> <$stat>\n";
|
|
# If this statement has no statement boundaries within
|
|
# it there is no point in retrying a statement scan
|
|
# until we hit end of it.
|
|
my $frag = $stat; $frag =~ s/;+\s*$//;
|
|
if ($frag !~ /(?:{|;)/) {
|
|
#print "skip<$line_nr_next>\n";
|
|
$suppress_statement = $line_nr_next;
|
|
}
|
|
|
|
# Find the real next line.
|
|
$realline_next = $line_nr_next;
|
|
if (defined $realline_next &&
|
|
(!defined $lines[$realline_next - 1] ||
|
|
substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
|
|
$realline_next++;
|
|
}
|
|
|
|
my $s = $stat;
|
|
$s =~ s/{.*$//s;
|
|
|
|
# Ignore goto labels.
|
|
if ($s =~ /$Ident:\*$/s) {
|
|
|
|
# Ignore functions being called
|
|
} elsif ($s =~ /^.\s*$Ident\s*\(/s) {
|
|
|
|
} elsif ($s =~ /^.\s*else\b/s) {
|
|
|
|
# declarations always start with types
|
|
} elsif ($prev_values eq 'E' && $s =~ /^.\s*(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?((?:\s*$Ident)+?)\b(?:\s+$Sparse)?\s*\**\s*(?:$Ident|\(\*[^\)]*\))(?:\s*$Modifier)?\s*(?:;|=|,|\()/s) {
|
|
my $type = $1;
|
|
$type =~ s/\s+/ /g;
|
|
possible($type, "A:" . $s);
|
|
|
|
# definitions in global scope can only start with types
|
|
} elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b\s*(?!:)/s) {
|
|
possible($1, "B:" . $s);
|
|
}
|
|
|
|
# any (foo ... *) is a pointer cast, and foo is a type
|
|
while ($s =~ /\(($Ident)(?:\s+$Sparse)*[\s\*]+\s*\)/sg) {
|
|
possible($1, "C:" . $s);
|
|
}
|
|
|
|
# Check for any sort of function declaration.
|
|
# int foo(something bar, other baz);
|
|
# void (*store_gdt)(x86_descr_ptr *);
|
|
if ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/s) {
|
|
my ($name_len) = length($1);
|
|
|
|
my $ctx = $s;
|
|
substr($ctx, 0, $name_len + 1, '');
|
|
$ctx =~ s/\)[^\)]*$//;
|
|
|
|
for my $arg (split(/\s*,\s*/, $ctx)) {
|
|
if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/s || $arg =~ /^($Ident)$/s) {
|
|
|
|
possible($1, "D:" . $s);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
#
|
|
# Checks which may be anchored in the context.
|
|
#
|
|
|
|
# Check for switch () and associated case and default
|
|
# statements should be at the same indent.
|
|
if ($line=~/\bswitch\s*\(.*\)/) {
|
|
my $err = '';
|
|
my $sep = '';
|
|
my @ctx = ctx_block_outer($linenr, $realcnt);
|
|
shift(@ctx);
|
|
for my $ctx (@ctx) {
|
|
my ($clen, $cindent) = line_stats($ctx);
|
|
if ($ctx =~ /^\+\s*(case\s+|default:)/ &&
|
|
$indent != $cindent) {
|
|
$err .= "$sep$ctx\n";
|
|
$sep = '';
|
|
} else {
|
|
$sep = "[...]\n";
|
|
}
|
|
}
|
|
if ($err ne '') {
|
|
ERROR("SWITCH_CASE_INDENT_LEVEL",
|
|
"switch and case should be at the same indent\n$hereline$err");
|
|
}
|
|
}
|
|
|
|
# if/while/etc brace do not go on next line, unless defining a do while loop,
|
|
# or if that brace on the next line is for something else
|
|
if ($line =~ /(.*)\b((?:if|while|for|switch|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) {
|
|
my $pre_ctx = "$1$2";
|
|
|
|
my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0);
|
|
|
|
if ($line =~ /^\+\t{6,}/) {
|
|
WARN("DEEP_INDENTATION",
|
|
"Too many leading tabs - consider code refactoring\n" . $herecurr);
|
|
}
|
|
|
|
my $ctx_cnt = $realcnt - $#ctx - 1;
|
|
my $ctx = join("\n", @ctx);
|
|
|
|
my $ctx_ln = $linenr;
|
|
my $ctx_skip = $realcnt;
|
|
|
|
while ($ctx_skip > $ctx_cnt || ($ctx_skip == $ctx_cnt &&
|
|
defined $lines[$ctx_ln - 1] &&
|
|
$lines[$ctx_ln - 1] =~ /^-/)) {
|
|
##print "SKIP<$ctx_skip> CNT<$ctx_cnt>\n";
|
|
$ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/);
|
|
$ctx_ln++;
|
|
}
|
|
|
|
#print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
|
|
#print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
|
|
|
|
if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
|
|
ERROR("OPEN_BRACE",
|
|
"that open brace { should be on the previous line\n" .
|
|
"$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
|
|
}
|
|
if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
|
|
$ctx =~ /\)\s*\;\s*$/ &&
|
|
defined $lines[$ctx_ln - 1])
|
|
{
|
|
my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
|
|
if ($nindent > $indent) {
|
|
WARN("TRAILING_SEMICOLON",
|
|
"trailing semicolon indicates no statements, indent implies otherwise\n" .
|
|
"$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
# Check relative indent for conditionals and blocks.
|
|
if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
|
|
($stat, $cond, $line_nr_next, $remain_next, $off_next) =
|
|
ctx_statement_block($linenr, $realcnt, 0)
|
|
if (!defined $stat);
|
|
my ($s, $c) = ($stat, $cond);
|
|
|
|
substr($s, 0, length($c), '');
|
|
|
|
# remove inline comments
|
|
$s =~ s/$;/ /g;
|
|
$c =~ s/$;/ /g;
|
|
|
|
# Find out how long the conditional actually is.
|
|
my @newlines = ($c =~ /\n/gs);
|
|
my $cond_lines = 1 + $#newlines;
|
|
|
|
# Make sure we remove the line prefixes as we have
|
|
# none on the first line, and are going to readd them
|
|
# where necessary.
|
|
$s =~ s/\n./\n/gs;
|
|
while ($s =~ /\n\s+\\\n/) {
|
|
$cond_lines += $s =~ s/\n\s+\\\n/\n/g;
|
|
}
|
|
|
|
# We want to check the first line inside the block
|
|
# starting at the end of the conditional, so remove:
|
|
# 1) any blank line termination
|
|
# 2) any opening brace { on end of the line
|
|
# 3) any do (...) {
|
|
my $continuation = 0;
|
|
my $check = 0;
|
|
$s =~ s/^.*\bdo\b//;
|
|
$s =~ s/^\s*{//;
|
|
if ($s =~ s/^\s*\\//) {
|
|
$continuation = 1;
|
|
}
|
|
if ($s =~ s/^\s*?\n//) {
|
|
$check = 1;
|
|
$cond_lines++;
|
|
}
|
|
|
|
# Also ignore a loop construct at the end of a
|
|
# preprocessor statement.
|
|
if (($prevline =~ /^.\s*#\s*define\s/ ||
|
|
$prevline =~ /\\\s*$/) && $continuation == 0) {
|
|
$check = 0;
|
|
}
|
|
|
|
my $cond_ptr = -1;
|
|
$continuation = 0;
|
|
while ($cond_ptr != $cond_lines) {
|
|
$cond_ptr = $cond_lines;
|
|
|
|
# If we see an #else/#elif then the code
|
|
# is not linear.
|
|
if ($s =~ /^\s*\#\s*(?:else|elif)/) {
|
|
$check = 0;
|
|
}
|
|
|
|
# Ignore:
|
|
# 1) blank lines, they should be at 0,
|
|
# 2) preprocessor lines, and
|
|
# 3) labels.
|
|
if ($continuation ||
|
|
$s =~ /^\s*?\n/ ||
|
|
$s =~ /^\s*#\s*?/ ||
|
|
$s =~ /^\s*$Ident\s*:/) {
|
|
$continuation = ($s =~ /^.*?\\\n/) ? 1 : 0;
|
|
if ($s =~ s/^.*?\n//) {
|
|
$cond_lines++;
|
|
}
|
|
}
|
|
}
|
|
|
|
my (undef, $sindent) = line_stats("+" . $s);
|
|
my $stat_real = raw_line($linenr, $cond_lines);
|
|
|
|
# Check if either of these lines are modified, else
|
|
# this is not this patch's fault.
|
|
if (!defined($stat_real) ||
|
|
$stat !~ /^\+/ && $stat_real !~ /^\+/) {
|
|
$check = 0;
|
|
}
|
|
if (defined($stat_real) && $cond_lines > 1) {
|
|
$stat_real = "[...]\n$stat_real";
|
|
}
|
|
|
|
#print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n";
|
|
|
|
if ($check && $s ne '' &&
|
|
(($sindent % 8) != 0 ||
|
|
($sindent < $indent) ||
|
|
($sindent > $indent + 8))) {
|
|
WARN("SUSPECT_CODE_INDENT",
|
|
"suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
|
|
}
|
|
}
|
|
|
|
# Track the 'values' across context and added lines.
|
|
my $opline = $line; $opline =~ s/^./ /;
|
|
my ($curr_values, $curr_vars) =
|
|
annotate_values($opline . "\n", $prev_values);
|
|
$curr_values = $prev_values . $curr_values;
|
|
if ($dbg_values) {
|
|
my $outline = $opline; $outline =~ s/\t/ /g;
|
|
print "$linenr > .$outline\n";
|
|
print "$linenr > $curr_values\n";
|
|
print "$linenr > $curr_vars\n";
|
|
}
|
|
$prev_values = substr($curr_values, -1);
|
|
|
|
#ignore lines not being added
|
|
next if ($line =~ /^[^\+]/);
|
|
|
|
# TEST: allow direct testing of the type matcher.
|
|
if ($dbg_type) {
|
|
if ($line =~ /^.\s*$Declare\s*$/) {
|
|
ERROR("TEST_TYPE",
|
|
"TEST: is type\n" . $herecurr);
|
|
} elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) {
|
|
ERROR("TEST_NOT_TYPE",
|
|
"TEST: is not type ($1 is)\n". $herecurr);
|
|
}
|
|
next;
|
|
}
|
|
# TEST: allow direct testing of the attribute matcher.
|
|
if ($dbg_attr) {
|
|
if ($line =~ /^.\s*$Modifier\s*$/) {
|
|
ERROR("TEST_ATTR",
|
|
"TEST: is attr\n" . $herecurr);
|
|
} elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) {
|
|
ERROR("TEST_NOT_ATTR",
|
|
"TEST: is not attr ($1 is)\n". $herecurr);
|
|
}
|
|
next;
|
|
}
|
|
|
|
# check for initialisation to aggregates open brace on the next line
|
|
if ($line =~ /^.\s*{/ &&
|
|
$prevline =~ /(?:^|[^=])=\s*$/) {
|
|
if (ERROR("OPEN_BRACE",
|
|
"that open brace { should be on the previous line\n" . $hereprev) &&
|
|
$fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
|
|
fix_delete_line($fixlinenr - 1, $prevrawline);
|
|
fix_delete_line($fixlinenr, $rawline);
|
|
my $fixedline = $prevrawline;
|
|
$fixedline =~ s/\s*=\s*$/ = {/;
|
|
fix_insert_line($fixlinenr, $fixedline);
|
|
$fixedline = $line;
|
|
$fixedline =~ s/^(.\s*)\{\s*/$1/;
|
|
fix_insert_line($fixlinenr, $fixedline);
|
|
}
|
|
}
|
|
|
|
#
|
|
# Checks which are anchored on the added line.
|
|
#
|
|
|
|
# check for malformed paths in #include statements (uses RAW line)
|
|
if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) {
|
|
my $path = $1;
|
|
if ($path =~ m{//}) {
|
|
ERROR("MALFORMED_INCLUDE",
|
|
"malformed #include filename\n" . $herecurr);
|
|
}
|
|
if ($path =~ "^uapi/" && $realfile =~ m@\binclude/uapi/@) {
|
|
ERROR("UAPI_INCLUDE",
|
|
"No #include in ...include/uapi/... should use a uapi/ path prefix\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
# no C99 // comments
|
|
if ($line =~ m{//}) {
|
|
if (ERROR("C99_COMMENTS",
|
|
"do not use C99 // comments\n" . $herecurr) &&
|
|
$fix) {
|
|
my $line = $fixed[$fixlinenr];
|
|
if ($line =~ /\/\/(.*)$/) {
|
|
my $comment = trim($1);
|
|
$fixed[$fixlinenr] =~ s@\/\/(.*)$@/\* $comment \*/@;
|
|
}
|
|
}
|
|
}
|
|
# Remove C99 comments.
|
|
$line =~ s@//.*@@;
|
|
$opline =~ s@//.*@@;
|
|
|
|
# EXPORT_SYMBOL should immediately follow the thing it is exporting, consider
|
|
# the whole statement.
|
|
#print "APW <$lines[$realline_next - 1]>\n";
|
|
if (defined $realline_next &&
|
|
exists $lines[$realline_next - 1] &&
|
|
!defined $suppress_export{$realline_next} &&
|
|
($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
|
|
$lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
|
|
# Handle definitions which produce identifiers with
|
|
# a prefix:
|
|
# XXX(foo);
|
|
# EXPORT_SYMBOL(something_foo);
|
|
my $name = $1;
|
|
if ($stat =~ /^(?:.\s*}\s*\n)?.([A-Z_]+)\s*\(\s*($Ident)/ &&
|
|
$name =~ /^${Ident}_$2/) {
|
|
#print "FOO C name<$name>\n";
|
|
$suppress_export{$realline_next} = 1;
|
|
|
|
} elsif ($stat !~ /(?:
|
|
\n.}\s*$|
|
|
^.DEFINE_$Ident\(\Q$name\E\)|
|
|
^.DECLARE_$Ident\(\Q$name\E\)|
|
|
^.LIST_HEAD\(\Q$name\E\)|
|
|
^.(?:$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(|
|
|
\b\Q$name\E(?:\s+$Attribute)*\s*(?:;|=|\[|\()
|
|
)/x) {
|
|
#print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
|
|
$suppress_export{$realline_next} = 2;
|
|
} else {
|
|
$suppress_export{$realline_next} = 1;
|
|
}
|
|
}
|
|
if (!defined $suppress_export{$linenr} &&
|
|
$prevline =~ /^.\s*$/ &&
|
|
($line =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
|
|
$line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
|
|
#print "FOO B <$lines[$linenr - 1]>\n";
|
|
$suppress_export{$linenr} = 2;
|
|
}
|
|
if (defined $suppress_export{$linenr} &&
|
|
$suppress_export{$linenr} == 2) {
|
|
WARN("EXPORT_SYMBOL",
|
|
"EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
|
|
}
|
|
|
|
# check for global initialisers.
|
|
if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/) {
|
|
if (ERROR("GLOBAL_INITIALISERS",
|
|
"do not initialise globals to $1\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/(^.$Type\s*$Ident(?:\s+$Modifier)*)\s*=\s*$zero_initializer\s*;/$1;/;
|
|
}
|
|
}
|
|
# check for static initialisers.
|
|
if ($line =~ /^\+.*\bstatic\s.*=\s*($zero_initializer)\s*;/) {
|
|
if (ERROR("INITIALISED_STATIC",
|
|
"do not initialise statics to $1\n" .
|
|
$herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/(\bstatic\s.*?)\s*=\s*$zero_initializer\s*;/$1;/;
|
|
}
|
|
}
|
|
|
|
# check for misordered declarations of char/short/int/long with signed/unsigned
|
|
while ($sline =~ m{(\b$TypeMisordered\b)}g) {
|
|
my $tmp = trim($1);
|
|
WARN("MISORDERED_TYPE",
|
|
"type '$tmp' should be specified in [[un]signed] [short|int|long|long long] order\n" . $herecurr);
|
|
}
|
|
|
|
# check for static const char * arrays.
|
|
if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
|
|
WARN("STATIC_CONST_CHAR_ARRAY",
|
|
"static const char * array should probably be static const char * const\n" .
|
|
$herecurr);
|
|
}
|
|
|
|
# check for static char foo[] = "bar" declarations.
|
|
if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
|
|
WARN("STATIC_CONST_CHAR_ARRAY",
|
|
"static char array declaration should probably be static const char\n" .
|
|
$herecurr);
|
|
}
|
|
|
|
# check for const <foo> const where <foo> is not a pointer or array type
|
|
if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) {
|
|
my $found = $1;
|
|
if ($sline =~ /\bconst\s+\Q$found\E\s+const\b\s*\*/) {
|
|
WARN("CONST_CONST",
|
|
"'const $found const *' should probably be 'const $found * const'\n" . $herecurr);
|
|
} elsif ($sline !~ /\bconst\s+\Q$found\E\s+const\s+\w+\s*\[/) {
|
|
WARN("CONST_CONST",
|
|
"'const $found const' should probably be 'const $found'\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
# check for non-global char *foo[] = {"bar", ...} declarations.
|
|
if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) {
|
|
WARN("STATIC_CONST_CHAR_ARRAY",
|
|
"char * array declaration might be better as static const\n" .
|
|
$herecurr);
|
|
}
|
|
|
|
# check for sizeof(foo)/sizeof(foo[0]) that could be ARRAY_SIZE(foo)
|
|
if ($line =~ m@\bsizeof\s*\(\s*($Lval)\s*\)@) {
|
|
my $array = $1;
|
|
if ($line =~ m@\b(sizeof\s*\(\s*\Q$array\E\s*\)\s*/\s*sizeof\s*\(\s*\Q$array\E\s*\[\s*0\s*\]\s*\))@) {
|
|
my $array_div = $1;
|
|
if (WARN("ARRAY_SIZE",
|
|
"Prefer ARRAY_SIZE($array)\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\Q$array_div\E/ARRAY_SIZE($array)/;
|
|
}
|
|
}
|
|
}
|
|
|
|
# check for function declarations without arguments like "int foo()"
|
|
if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) {
|
|
if (ERROR("FUNCTION_WITHOUT_ARGS",
|
|
"Bad function definition - $1() should probably be $1(void)\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/(\b($Type)\s+($Ident))\s*\(\s*\)/$2 $3(void)/;
|
|
}
|
|
}
|
|
|
|
# check for uses of DEFINE_PCI_DEVICE_TABLE
|
|
if ($line =~ /\bDEFINE_PCI_DEVICE_TABLE\s*\(\s*(\w+)\s*\)\s*=/) {
|
|
if (WARN("DEFINE_PCI_DEVICE_TABLE",
|
|
"Prefer struct pci_device_id over deprecated DEFINE_PCI_DEVICE_TABLE\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\b(?:static\s+|)DEFINE_PCI_DEVICE_TABLE\s*\(\s*(\w+)\s*\)\s*=\s*/static const struct pci_device_id $1\[\] = /;
|
|
}
|
|
}
|
|
|
|
# check for new typedefs, only function parameters and sparse annotations
|
|
# make sense.
|
|
if ($line =~ /\btypedef\s/ &&
|
|
$line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
|
|
$line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
|
|
$line !~ /\b$typeTypedefs\b/ &&
|
|
$line !~ /\b__bitwise(?:__|)\b/) {
|
|
WARN("NEW_TYPEDEFS",
|
|
"do not add new typedefs\n" . $herecurr);
|
|
}
|
|
|
|
# * goes on variable not on type
|
|
# (char*[ const])
|
|
while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {
|
|
#print "AA<$1>\n";
|
|
my ($ident, $from, $to) = ($1, $2, $2);
|
|
|
|
# Should start with a space.
|
|
$to =~ s/^(\S)/ $1/;
|
|
# Should not end with a space.
|
|
$to =~ s/\s+$//;
|
|
# '*'s should not have spaces between.
|
|
while ($to =~ s/\*\s+\*/\*\*/) {
|
|
}
|
|
|
|
## print "1: from<$from> to<$to> ident<$ident>\n";
|
|
if ($from ne $to) {
|
|
if (ERROR("POINTER_LOCATION",
|
|
"\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr) &&
|
|
$fix) {
|
|
my $sub_from = $ident;
|
|
my $sub_to = $ident;
|
|
$sub_to =~ s/\Q$from\E/$to/;
|
|
$fixed[$fixlinenr] =~
|
|
s@\Q$sub_from\E@$sub_to@;
|
|
}
|
|
}
|
|
}
|
|
while ($line =~ m{(\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident))}g) {
|
|
#print "BB<$1>\n";
|
|
my ($match, $from, $to, $ident) = ($1, $2, $2, $3);
|
|
|
|
# Should start with a space.
|
|
$to =~ s/^(\S)/ $1/;
|
|
# Should not end with a space.
|
|
$to =~ s/\s+$//;
|
|
# '*'s should not have spaces between.
|
|
while ($to =~ s/\*\s+\*/\*\*/) {
|
|
}
|
|
# Modifiers should have spaces.
|
|
$to =~ s/(\b$Modifier$)/$1 /;
|
|
|
|
## print "2: from<$from> to<$to> ident<$ident>\n";
|
|
if ($from ne $to && $ident !~ /^$Modifier$/) {
|
|
if (ERROR("POINTER_LOCATION",
|
|
"\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr) &&
|
|
$fix) {
|
|
|
|
my $sub_from = $match;
|
|
my $sub_to = $match;
|
|
$sub_to =~ s/\Q$from\E/$to/;
|
|
$fixed[$fixlinenr] =~
|
|
s@\Q$sub_from\E@$sub_to@;
|
|
}
|
|
}
|
|
}
|
|
|
|
# avoid BUG() or BUG_ON()
|
|
if ($line =~ /\b(?:BUG|BUG_ON)\b/) {
|
|
my $msg_type = \&WARN;
|
|
$msg_type = \&CHK if ($file);
|
|
&{$msg_type}("AVOID_BUG",
|
|
"Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON()\n" . $herecurr);
|
|
}
|
|
|
|
# avoid LINUX_VERSION_CODE
|
|
if ($line =~ /\bLINUX_VERSION_CODE\b/) {
|
|
WARN("LINUX_VERSION_CODE",
|
|
"LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr);
|
|
}
|
|
|
|
# check for uses of printk_ratelimit
|
|
if ($line =~ /\bprintk_ratelimit\s*\(/) {
|
|
WARN("PRINTK_RATELIMITED",
|
|
"Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr);
|
|
}
|
|
|
|
# printk should use KERN_* levels. Note that follow on printk's on the
|
|
# same line do not need a level, so we use the current block context
|
|
# to try and find and validate the current printk. In summary the current
|
|
# printk includes all preceding printk's which have no newline on the end.
|
|
# we assume the first bad printk is the one to report.
|
|
if ($line =~ /\bprintk\((?!KERN_)\s*"/) {
|
|
my $ok = 0;
|
|
for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) {
|
|
#print "CHECK<$lines[$ln - 1]\n";
|
|
# we have a preceding printk if it ends
|
|
# with "\n" ignore it, else it is to blame
|
|
if ($lines[$ln - 1] =~ m{\bprintk\(}) {
|
|
if ($rawlines[$ln - 1] !~ m{\\n"}) {
|
|
$ok = 1;
|
|
}
|
|
last;
|
|
}
|
|
}
|
|
if ($ok == 0) {
|
|
WARN("PRINTK_WITHOUT_KERN_LEVEL",
|
|
"printk() should include KERN_ facility level\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
if ($line =~ /\bprintk\s*\(\s*KERN_([A-Z]+)/) {
|
|
my $orig = $1;
|
|
my $level = lc($orig);
|
|
$level = "warn" if ($level eq "warning");
|
|
my $level2 = $level;
|
|
$level2 = "dbg" if ($level eq "debug");
|
|
WARN("PREFER_PR_LEVEL",
|
|
"Prefer [subsystem eg: netdev]_$level2([subsystem]dev, ... then dev_$level2(dev, ... then pr_$level(... to printk(KERN_$orig ...\n" . $herecurr);
|
|
}
|
|
|
|
if ($line =~ /\bpr_warning\s*\(/) {
|
|
if (WARN("PREFER_PR_LEVEL",
|
|
"Prefer pr_warn(... to pr_warning(...\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~
|
|
s/\bpr_warning\b/pr_warn/;
|
|
}
|
|
}
|
|
|
|
if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) {
|
|
my $orig = $1;
|
|
my $level = lc($orig);
|
|
$level = "warn" if ($level eq "warning");
|
|
$level = "dbg" if ($level eq "debug");
|
|
WARN("PREFER_DEV_LEVEL",
|
|
"Prefer dev_$level(... to dev_printk(KERN_$orig, ...\n" . $herecurr);
|
|
}
|
|
|
|
# ENOSYS means "bad syscall nr" and nothing else. This will have a small
|
|
# number of false positives, but assembly files are not checked, so at
|
|
# least the arch entry code will not trigger this warning.
|
|
if ($line =~ /\bENOSYS\b/) {
|
|
WARN("ENOSYS",
|
|
"ENOSYS means 'invalid syscall nr' and nothing else\n" . $herecurr);
|
|
}
|
|
|
|
# function brace can't be on same line, except for #defines of do while,
|
|
# or if closed on same line
|
|
if (($line=~/$Type\s*$Ident\(.*\).*\s*{/) and
|
|
!($line=~/\#\s*define.*do\s\{/) and !($line=~/}/)) {
|
|
if (ERROR("OPEN_BRACE",
|
|
"open brace '{' following function declarations go on the next line\n" . $herecurr) &&
|
|
$fix) {
|
|
fix_delete_line($fixlinenr, $rawline);
|
|
my $fixed_line = $rawline;
|
|
$fixed_line =~ /(^..*$Type\s*$Ident\(.*\)\s*)\{(.*)$/;
|
|
my $line1 = $1;
|
|
my $line2 = $2;
|
|
fix_insert_line($fixlinenr, ltrim($line1));
|
|
fix_insert_line($fixlinenr, "\+{");
|
|
if ($line2 !~ /^\s*$/) {
|
|
fix_insert_line($fixlinenr, "\+\t" . trim($line2));
|
|
}
|
|
}
|
|
}
|
|
|
|
# open braces for enum, union and struct go on the same line.
|
|
if ($line =~ /^.\s*{/ &&
|
|
$prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
|
|
if (ERROR("OPEN_BRACE",
|
|
"open brace '{' following $1 go on the same line\n" . $hereprev) &&
|
|
$fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
|
|
fix_delete_line($fixlinenr - 1, $prevrawline);
|
|
fix_delete_line($fixlinenr, $rawline);
|
|
my $fixedline = rtrim($prevrawline) . " {";
|
|
fix_insert_line($fixlinenr, $fixedline);
|
|
$fixedline = $rawline;
|
|
$fixedline =~ s/^(.\s*)\{\s*/$1\t/;
|
|
if ($fixedline !~ /^\+\s*$/) {
|
|
fix_insert_line($fixlinenr, $fixedline);
|
|
}
|
|
}
|
|
}
|
|
|
|
# missing space after union, struct or enum definition
|
|
if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident){1,2}[=\{]/) {
|
|
if (WARN("SPACING",
|
|
"missing space after $1 definition\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~
|
|
s/^(.\s*(?:typedef\s+)?(?:enum|union|struct)(?:\s+$Ident){1,2})([=\{])/$1 $2/;
|
|
}
|
|
}
|
|
|
|
# Function pointer declarations
|
|
# check spacing between type, funcptr, and args
|
|
# canonical declaration is "type (*funcptr)(args...)"
|
|
if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)($Ident)(\s*)\)(\s*)\(/) {
|
|
my $declare = $1;
|
|
my $pre_pointer_space = $2;
|
|
my $post_pointer_space = $3;
|
|
my $funcname = $4;
|
|
my $post_funcname_space = $5;
|
|
my $pre_args_space = $6;
|
|
|
|
# the $Declare variable will capture all spaces after the type
|
|
# so check it for a missing trailing missing space but pointer return types
|
|
# don't need a space so don't warn for those.
|
|
my $post_declare_space = "";
|
|
if ($declare =~ /(\s+)$/) {
|
|
$post_declare_space = $1;
|
|
$declare = rtrim($declare);
|
|
}
|
|
if ($declare !~ /\*$/ && $post_declare_space =~ /^$/) {
|
|
WARN("SPACING",
|
|
"missing space after return type\n" . $herecurr);
|
|
$post_declare_space = " ";
|
|
}
|
|
|
|
# unnecessary space "type (*funcptr)(args...)"
|
|
# This test is not currently implemented because these declarations are
|
|
# equivalent to
|
|
# int foo(int bar, ...)
|
|
# and this is form shouldn't/doesn't generate a checkpatch warning.
|
|
#
|
|
# elsif ($declare =~ /\s{2,}$/) {
|
|
# WARN("SPACING",
|
|
# "Multiple spaces after return type\n" . $herecurr);
|
|
# }
|
|
|
|
# unnecessary space "type ( *funcptr)(args...)"
|
|
if (defined $pre_pointer_space &&
|
|
$pre_pointer_space =~ /^\s/) {
|
|
WARN("SPACING",
|
|
"Unnecessary space after function pointer open parenthesis\n" . $herecurr);
|
|
}
|
|
|
|
# unnecessary space "type (* funcptr)(args...)"
|
|
if (defined $post_pointer_space &&
|
|
$post_pointer_space =~ /^\s/) {
|
|
WARN("SPACING",
|
|
"Unnecessary space before function pointer name\n" . $herecurr);
|
|
}
|
|
|
|
# unnecessary space "type (*funcptr )(args...)"
|
|
if (defined $post_funcname_space &&
|
|
$post_funcname_space =~ /^\s/) {
|
|
WARN("SPACING",
|
|
"Unnecessary space after function pointer name\n" . $herecurr);
|
|
}
|
|
|
|
# unnecessary space "type (*funcptr) (args...)"
|
|
if (defined $pre_args_space &&
|
|
$pre_args_space =~ /^\s/) {
|
|
WARN("SPACING",
|
|
"Unnecessary space before function pointer arguments\n" . $herecurr);
|
|
}
|
|
|
|
if (show_type("SPACING") && $fix) {
|
|
$fixed[$fixlinenr] =~
|
|
s/^(.\s*)$Declare\s*\(\s*\*\s*$Ident\s*\)\s*\(/$1 . $declare . $post_declare_space . '(*' . $funcname . ')('/ex;
|
|
}
|
|
}
|
|
|
|
# check for spacing round square brackets; allowed:
|
|
# 1. with a type on the left -- int [] a;
|
|
# 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
|
|
# 3. inside a curly brace -- = { [0...10] = 5 }
|
|
while ($line =~ /(.*?\s)\[/g) {
|
|
my ($where, $prefix) = ($-[1], $1);
|
|
if ($prefix !~ /$Type\s+$/ &&
|
|
($where != 0 || $prefix !~ /^.\s+$/) &&
|
|
$prefix !~ /[{,]\s+$/) {
|
|
if (ERROR("BRACKET_SPACE",
|
|
"space prohibited before open square bracket '['\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~
|
|
s/^(\+.*?)\s+\[/$1\[/;
|
|
}
|
|
}
|
|
}
|
|
|
|
# check for spaces between functions and their parentheses.
|
|
while ($line =~ /($Ident)\s+\(/g) {
|
|
my $name = $1;
|
|
my $ctx_before = substr($line, 0, $-[1]);
|
|
my $ctx = "$ctx_before$name";
|
|
|
|
# Ignore those directives where spaces _are_ permitted.
|
|
if ($name =~ /^(?:
|
|
if|for|while|switch|return|case|
|
|
volatile|__volatile__|
|
|
__attribute__|format|__extension__|
|
|
asm|__asm__)$/x)
|
|
{
|
|
# cpp #define statements have non-optional spaces, ie
|
|
# if there is a space between the name and the open
|
|
# parenthesis it is simply not a parameter group.
|
|
} elsif ($ctx_before =~ /^.\s*\#\s*define\s*$/) {
|
|
|
|
# cpp #elif statement condition may start with a (
|
|
} elsif ($ctx =~ /^.\s*\#\s*elif\s*$/) {
|
|
|
|
# If this whole things ends with a type its most
|
|
# likely a typedef for a function.
|
|
} elsif ($ctx =~ /$Type$/) {
|
|
|
|
} else {
|
|
if (WARN("SPACING",
|
|
"space prohibited between function name and open parenthesis '('\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~
|
|
s/\b$name\s+\(/$name\(/;
|
|
}
|
|
}
|
|
}
|
|
|
|
# Check operator spacing.
|
|
if (!($line=~/\#\s*include/)) {
|
|
my $fixed_line = "";
|
|
my $line_fixed = 0;
|
|
|
|
my $ops = qr{
|
|
<<=|>>=|<=|>=|==|!=|
|
|
\+=|-=|\*=|\/=|%=|\^=|\|=|&=|
|
|
=>|->|<<|>>|<|>|=|!|~|
|
|
&&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%|
|
|
\?:|\?|:
|
|
}x;
|
|
my @elements = split(/($ops|;)/, $opline);
|
|
|
|
## print("element count: <" . $#elements . ">\n");
|
|
## foreach my $el (@elements) {
|
|
## print("el: <$el>\n");
|
|
## }
|
|
|
|
my @fix_elements = ();
|
|
my $off = 0;
|
|
|
|
foreach my $el (@elements) {
|
|
push(@fix_elements, substr($rawline, $off, length($el)));
|
|
$off += length($el);
|
|
}
|
|
|
|
$off = 0;
|
|
|
|
my $blank = copy_spacing($opline);
|
|
my $last_after = -1;
|
|
|
|
for (my $n = 0; $n < $#elements; $n += 2) {
|
|
|
|
my $good = $fix_elements[$n] . $fix_elements[$n + 1];
|
|
|
|
## print("n: <$n> good: <$good>\n");
|
|
|
|
$off += length($elements[$n]);
|
|
|
|
# Pick up the preceding and succeeding characters.
|
|
my $ca = substr($opline, 0, $off);
|
|
my $cc = '';
|
|
if (length($opline) >= ($off + length($elements[$n + 1]))) {
|
|
$cc = substr($opline, $off + length($elements[$n + 1]));
|
|
}
|
|
my $cb = "$ca$;$cc";
|
|
|
|
my $a = '';
|
|
$a = 'V' if ($elements[$n] ne '');
|
|
$a = 'W' if ($elements[$n] =~ /\s$/);
|
|
$a = 'C' if ($elements[$n] =~ /$;$/);
|
|
$a = 'B' if ($elements[$n] =~ /(\[|\()$/);
|
|
$a = 'O' if ($elements[$n] eq '');
|
|
$a = 'E' if ($ca =~ /^\s*$/);
|
|
|
|
my $op = $elements[$n + 1];
|
|
|
|
my $c = '';
|
|
if (defined $elements[$n + 2]) {
|
|
$c = 'V' if ($elements[$n + 2] ne '');
|
|
$c = 'W' if ($elements[$n + 2] =~ /^\s/);
|
|
$c = 'C' if ($elements[$n + 2] =~ /^$;/);
|
|
$c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/);
|
|
$c = 'O' if ($elements[$n + 2] eq '');
|
|
$c = 'E' if ($elements[$n + 2] =~ /^\s*\\$/);
|
|
} else {
|
|
$c = 'E';
|
|
}
|
|
|
|
my $ctx = "${a}x${c}";
|
|
|
|
my $at = "(ctx:$ctx)";
|
|
|
|
my $ptr = substr($blank, 0, $off) . "^";
|
|
my $hereptr = "$hereline$ptr\n";
|
|
|
|
# Pull out the value of this operator.
|
|
my $op_type = substr($curr_values, $off + 1, 1);
|
|
|
|
# Get the full operator variant.
|
|
my $opv = $op . substr($curr_vars, $off, 1);
|
|
|
|
# Ignore operators passed as parameters.
|
|
if ($op_type ne 'V' &&
|
|
$ca =~ /\s$/ && $cc =~ /^\s*[,\)]/) {
|
|
|
|
# # Ignore comments
|
|
# } elsif ($op =~ /^$;+$/) {
|
|
|
|
# ; should have either the end of line or a space or \ after it
|
|
} elsif ($op eq ';') {
|
|
if ($ctx !~ /.x[WEBC]/ &&
|
|
$cc !~ /^\\/ && $cc !~ /^;/) {
|
|
if (ERROR("SPACING",
|
|
"space required after that '$op' $at\n" . $hereptr)) {
|
|
$good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " ";
|
|
$line_fixed = 1;
|
|
}
|
|
}
|
|
|
|
# // is a comment
|
|
} elsif ($op eq '//') {
|
|
|
|
# : when part of a bitfield
|
|
} elsif ($opv eq ':B') {
|
|
# skip the bitfield test for now
|
|
|
|
# No spaces for:
|
|
# ->
|
|
} elsif ($op eq '->') {
|
|
if ($ctx =~ /Wx.|.xW/) {
|
|
if (ERROR("SPACING",
|
|
"spaces prohibited around that '$op' $at\n" . $hereptr)) {
|
|
$good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
|
|
if (defined $fix_elements[$n + 2]) {
|
|
$fix_elements[$n + 2] =~ s/^\s+//;
|
|
}
|
|
$line_fixed = 1;
|
|
}
|
|
}
|
|
|
|
# , must not have a space before and must have a space on the right.
|
|
} elsif ($op eq ',') {
|
|
my $rtrim_before = 0;
|
|
my $space_after = 0;
|
|
if ($ctx =~ /Wx./) {
|
|
if (ERROR("SPACING",
|
|
"space prohibited before that '$op' $at\n" . $hereptr)) {
|
|
$line_fixed = 1;
|
|
$rtrim_before = 1;
|
|
}
|
|
}
|
|
if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
|
|
if (ERROR("SPACING",
|
|
"space required after that '$op' $at\n" . $hereptr)) {
|
|
$line_fixed = 1;
|
|
$last_after = $n;
|
|
$space_after = 1;
|
|
}
|
|
}
|
|
if ($rtrim_before || $space_after) {
|
|
if ($rtrim_before) {
|
|
$good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
|
|
} else {
|
|
$good = $fix_elements[$n] . trim($fix_elements[$n + 1]);
|
|
}
|
|
if ($space_after) {
|
|
$good .= " ";
|
|
}
|
|
}
|
|
|
|
# '*' as part of a type definition -- reported already.
|
|
} elsif ($opv eq '*_') {
|
|
#warn "'*' is part of type\n";
|
|
|
|
# unary operators should have a space before and
|
|
# none after. May be left adjacent to another
|
|
# unary operator, or a cast
|
|
} elsif ($op eq '!' || $op eq '~' ||
|
|
$opv eq '*U' || $opv eq '-U' ||
|
|
$opv eq '&U' || $opv eq '&&U') {
|
|
if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
|
|
if (ERROR("SPACING",
|
|
"space required before that '$op' $at\n" . $hereptr)) {
|
|
if ($n != $last_after + 2) {
|
|
$good = $fix_elements[$n] . " " . ltrim($fix_elements[$n + 1]);
|
|
$line_fixed = 1;
|
|
}
|
|
}
|
|
}
|
|
if ($op eq '*' && $cc =~/\s*$Modifier\b/) {
|
|
# A unary '*' may be const
|
|
|
|
} elsif ($ctx =~ /.xW/) {
|
|
if (ERROR("SPACING",
|
|
"space prohibited after that '$op' $at\n" . $hereptr)) {
|
|
$good = $fix_elements[$n] . rtrim($fix_elements[$n + 1]);
|
|
if (defined $fix_elements[$n + 2]) {
|
|
$fix_elements[$n + 2] =~ s/^\s+//;
|
|
}
|
|
$line_fixed = 1;
|
|
}
|
|
}
|
|
|
|
# unary ++ and unary -- are allowed no space on one side.
|
|
} elsif ($op eq '++' or $op eq '--') {
|
|
if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) {
|
|
if (ERROR("SPACING",
|
|
"space required one side of that '$op' $at\n" . $hereptr)) {
|
|
$good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " ";
|
|
$line_fixed = 1;
|
|
}
|
|
}
|
|
if ($ctx =~ /Wx[BE]/ ||
|
|
($ctx =~ /Wx./ && $cc =~ /^;/)) {
|
|
if (ERROR("SPACING",
|
|
"space prohibited before that '$op' $at\n" . $hereptr)) {
|
|
$good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
|
|
$line_fixed = 1;
|
|
}
|
|
}
|
|
if ($ctx =~ /ExW/) {
|
|
if (ERROR("SPACING",
|
|
"space prohibited after that '$op' $at\n" . $hereptr)) {
|
|
$good = $fix_elements[$n] . trim($fix_elements[$n + 1]);
|
|
if (defined $fix_elements[$n + 2]) {
|
|
$fix_elements[$n + 2] =~ s/^\s+//;
|
|
}
|
|
$line_fixed = 1;
|
|
}
|
|
}
|
|
|
|
# << and >> may either have or not have spaces both sides
|
|
} elsif ($op eq '<<' or $op eq '>>' or
|
|
$op eq '&' or $op eq '^' or $op eq '|' or
|
|
$op eq '+' or $op eq '-' or
|
|
$op eq '*' or $op eq '/' or
|
|
$op eq '%')
|
|
{
|
|
if ($check) {
|
|
if (defined $fix_elements[$n + 2] && $ctx !~ /[EW]x[EW]/) {
|
|
if (CHK("SPACING",
|
|
"spaces preferred around that '$op' $at\n" . $hereptr)) {
|
|
$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
|
|
$fix_elements[$n + 2] =~ s/^\s+//;
|
|
$line_fixed = 1;
|
|
}
|
|
} elsif (!defined $fix_elements[$n + 2] && $ctx !~ /Wx[OE]/) {
|
|
if (CHK("SPACING",
|
|
"space preferred before that '$op' $at\n" . $hereptr)) {
|
|
$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]);
|
|
$line_fixed = 1;
|
|
}
|
|
}
|
|
} elsif ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
|
|
if (ERROR("SPACING",
|
|
"need consistent spacing around '$op' $at\n" . $hereptr)) {
|
|
$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
|
|
if (defined $fix_elements[$n + 2]) {
|
|
$fix_elements[$n + 2] =~ s/^\s+//;
|
|
}
|
|
$line_fixed = 1;
|
|
}
|
|
}
|
|
|
|
# A colon needs no spaces before when it is
|
|
# terminating a case value or a label.
|
|
} elsif ($opv eq ':C' || $opv eq ':L') {
|
|
if ($ctx =~ /Wx./) {
|
|
if (ERROR("SPACING",
|
|
"space prohibited before that '$op' $at\n" . $hereptr)) {
|
|
$good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
|
|
$line_fixed = 1;
|
|
}
|
|
}
|
|
|
|
# All the others need spaces both sides.
|
|
} elsif ($ctx !~ /[EWC]x[CWE]/) {
|
|
my $ok = 0;
|
|
|
|
# Ignore email addresses <foo@bar>
|
|
if (($op eq '<' &&
|
|
$cc =~ /^\S+\@\S+>/) ||
|
|
($op eq '>' &&
|
|
$ca =~ /<\S+\@\S+$/))
|
|
{
|
|
$ok = 1;
|
|
}
|
|
|
|
# for asm volatile statements
|
|
# ignore a colon with another
|
|
# colon immediately before or after
|
|
if (($op eq ':') &&
|
|
($ca =~ /:$/ || $cc =~ /^:/)) {
|
|
$ok = 1;
|
|
}
|
|
|
|
# messages are ERROR, but ?: are CHK
|
|
if ($ok == 0) {
|
|
my $msg_type = \&ERROR;
|
|
$msg_type = \&CHK if (($op eq '?:' || $op eq '?' || $op eq ':') && $ctx =~ /VxV/);
|
|
|
|
if (&{$msg_type}("SPACING",
|
|
"spaces required around that '$op' $at\n" . $hereptr)) {
|
|
$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
|
|
if (defined $fix_elements[$n + 2]) {
|
|
$fix_elements[$n + 2] =~ s/^\s+//;
|
|
}
|
|
$line_fixed = 1;
|
|
}
|
|
}
|
|
}
|
|
$off += length($elements[$n + 1]);
|
|
|
|
## print("n: <$n> GOOD: <$good>\n");
|
|
|
|
$fixed_line = $fixed_line . $good;
|
|
}
|
|
|
|
if (($#elements % 2) == 0) {
|
|
$fixed_line = $fixed_line . $fix_elements[$#elements];
|
|
}
|
|
|
|
if ($fix && $line_fixed && $fixed_line ne $fixed[$fixlinenr]) {
|
|
$fixed[$fixlinenr] = $fixed_line;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
# check for whitespace before a non-naked semicolon
|
|
if ($line =~ /^\+.*\S\s+;\s*$/) {
|
|
if (WARN("SPACING",
|
|
"space prohibited before semicolon\n" . $herecurr) &&
|
|
$fix) {
|
|
1 while $fixed[$fixlinenr] =~
|
|
s/^(\+.*\S)\s+;/$1;/;
|
|
}
|
|
}
|
|
|
|
# check for multiple assignments
|
|
if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) {
|
|
CHK("MULTIPLE_ASSIGNMENTS",
|
|
"multiple assignments should be avoided\n" . $herecurr);
|
|
}
|
|
|
|
## # check for multiple declarations, allowing for a function declaration
|
|
## # continuation.
|
|
## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
|
|
## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
|
|
##
|
|
## # Remove any bracketed sections to ensure we do not
|
|
## # falsly report the parameters of functions.
|
|
## my $ln = $line;
|
|
## while ($ln =~ s/\([^\(\)]*\)//g) {
|
|
## }
|
|
## if ($ln =~ /,/) {
|
|
## WARN("MULTIPLE_DECLARATION",
|
|
## "declaring multiple variables together should be avoided\n" . $herecurr);
|
|
## }
|
|
## }
|
|
|
|
#need space before brace following if, while, etc
|
|
if (($line =~ /\(.*\)\{/ && $line !~ /\($Type\){/) ||
|
|
$line =~ /do\{/) {
|
|
if (ERROR("SPACING",
|
|
"space required before the open brace '{'\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/^(\+.*(?:do|\)))\{/$1 {/;
|
|
}
|
|
}
|
|
|
|
## # check for blank lines before declarations
|
|
## if ($line =~ /^.\t+$Type\s+$Ident(?:\s*=.*)?;/ &&
|
|
## $prevrawline =~ /^.\s*$/) {
|
|
## WARN("SPACING",
|
|
## "No blank lines before declarations\n" . $hereprev);
|
|
## }
|
|
##
|
|
|
|
# closing brace should have a space following it when it has anything
|
|
# on the line
|
|
if ($line =~ /}(?!(?:,|;|\)))\S/) {
|
|
if (ERROR("SPACING",
|
|
"space required after that close brace '}'\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~
|
|
s/}((?!(?:,|;|\)))\S)/} $1/;
|
|
}
|
|
}
|
|
|
|
# check spacing on square brackets
|
|
if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
|
|
if (ERROR("SPACING",
|
|
"space prohibited after that open square bracket '['\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~
|
|
s/\[\s+/\[/;
|
|
}
|
|
}
|
|
if ($line =~ /\s\]/) {
|
|
if (ERROR("SPACING",
|
|
"space prohibited before that close square bracket ']'\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~
|
|
s/\s+\]/\]/;
|
|
}
|
|
}
|
|
|
|
# check spacing on parentheses
|
|
if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
|
|
$line !~ /for\s*\(\s+;/ && $line !~ /^\+\s*[A-Z_][A-Z\d_]*\(\s*\d+(\,.*)?\)\,?$/) {
|
|
if (ERROR("SPACING",
|
|
"space prohibited after that open parenthesis '('\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~
|
|
s/\(\s+/\(/;
|
|
}
|
|
}
|
|
if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
|
|
$line !~ /for\s*\(.*;\s+\)/ &&
|
|
$line !~ /:\s+\)/) {
|
|
if (ERROR("SPACING",
|
|
"space prohibited before that close parenthesis ')'\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~
|
|
s/\s+\)/\)/;
|
|
}
|
|
}
|
|
|
|
# check unnecessary parentheses around addressof/dereference single $Lvals
|
|
# ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar
|
|
|
|
while ($line =~ /(?:[^&]&\s*|\*)\(\s*($Ident\s*(?:$Member\s*)+)\s*\)/g) {
|
|
my $var = $1;
|
|
if (CHK("UNNECESSARY_PARENTHESES",
|
|
"Unnecessary parentheses around $var\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\(\s*\Q$var\E\s*\)/$var/;
|
|
}
|
|
}
|
|
|
|
# check for unnecessary parentheses around function pointer uses
|
|
# ie: (foo->bar)(); should be foo->bar();
|
|
# but not "if (foo->bar) (" to avoid some false positives
|
|
if ($line =~ /(\bif\s*|)(\(\s*$Ident\s*(?:$Member\s*)+\))[ \t]*\(/ && $1 !~ /^if/) {
|
|
my $var = $2;
|
|
if (CHK("UNNECESSARY_PARENTHESES",
|
|
"Unnecessary parentheses around function pointer $var\n" . $herecurr) &&
|
|
$fix) {
|
|
my $var2 = deparenthesize($var);
|
|
$var2 =~ s/\s//g;
|
|
$fixed[$fixlinenr] =~ s/\Q$var\E/$var2/;
|
|
}
|
|
}
|
|
|
|
#goto labels aren't indented, allow a single space however
|
|
if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
|
|
!($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
|
|
if (WARN("INDENTED_LABEL",
|
|
"labels should not be indented\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~
|
|
s/^(.)\s+/$1/;
|
|
}
|
|
}
|
|
|
|
# return is not a function
|
|
if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
|
|
my $spacing = $1;
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
$stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) {
|
|
my $value = $1;
|
|
$value = deparenthesize($value);
|
|
if ($value =~ m/^\s*$FuncArg\s*(?:\?|$)/) {
|
|
ERROR("RETURN_PARENTHESES",
|
|
"return is not a function, parentheses are not required\n" . $herecurr);
|
|
}
|
|
} elsif ($spacing !~ /\s+/) {
|
|
ERROR("SPACING",
|
|
"space required before the open parenthesis '('\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
# unnecessary return in a void function
|
|
# at end-of-function, with the previous line a single leading tab, then return;
|
|
# and the line before that not a goto label target like "out:"
|
|
if ($sline =~ /^[ \+]}\s*$/ &&
|
|
$prevline =~ /^\+\treturn\s*;\s*$/ &&
|
|
$linenr >= 3 &&
|
|
$lines[$linenr - 3] =~ /^[ +]/ &&
|
|
$lines[$linenr - 3] !~ /^[ +]\s*$Ident\s*:/) {
|
|
WARN("RETURN_VOID",
|
|
"void function return statements are not generally useful\n" . $hereprev);
|
|
}
|
|
|
|
# if statements using unnecessary parentheses - ie: if ((foo == bar))
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
$line =~ /\bif\s*((?:\(\s*){2,})/) {
|
|
my $openparens = $1;
|
|
my $count = $openparens =~ tr@\(@\(@;
|
|
my $msg = "";
|
|
if ($line =~ /\bif\s*(?:\(\s*){$count,$count}$LvalOrFunc\s*($Compare)\s*$LvalOrFunc(?:\s*\)){$count,$count}/) {
|
|
my $comp = $4; #Not $1 because of $LvalOrFunc
|
|
$msg = " - maybe == should be = ?" if ($comp eq "==");
|
|
WARN("UNNECESSARY_PARENTHESES",
|
|
"Unnecessary parentheses$msg\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
# comparisons with a constant or upper case identifier on the left
|
|
# avoid cases like "foo + BAR < baz"
|
|
# only fix matches surrounded by parentheses to avoid incorrect
|
|
# conversions like "FOO < baz() + 5" being "misfixed" to "baz() > FOO + 5"
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
$line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) {
|
|
my $lead = $1;
|
|
my $const = $2;
|
|
my $comp = $3;
|
|
my $to = $4;
|
|
my $newcomp = $comp;
|
|
if ($lead !~ /$Operators\s*$/ &&
|
|
$to !~ /^(?:Constant|[A-Z_][A-Z0-9_]*)$/ &&
|
|
WARN("CONSTANT_COMPARISON",
|
|
"Comparisons should place the constant on the right side of the test\n" . $herecurr) &&
|
|
$fix) {
|
|
if ($comp eq "<") {
|
|
$newcomp = ">";
|
|
} elsif ($comp eq "<=") {
|
|
$newcomp = ">=";
|
|
} elsif ($comp eq ">") {
|
|
$newcomp = "<";
|
|
} elsif ($comp eq ">=") {
|
|
$newcomp = "<=";
|
|
}
|
|
$fixed[$fixlinenr] =~ s/\(\s*\Q$const\E\s*$Compare\s*\Q$to\E\s*\)/($to $newcomp $const)/;
|
|
}
|
|
}
|
|
|
|
# Return of what appears to be an errno should normally be negative
|
|
if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) {
|
|
my $name = $1;
|
|
if ($name ne 'EOF' && $name ne 'ERROR') {
|
|
WARN("USE_NEGATIVE_ERRNO",
|
|
"return of an errno should typically be negative (ie: return -$1)\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
# Need a space before open parenthesis after if, while etc
|
|
if ($line =~ /\b(if|while|for|switch)\(/) {
|
|
if (ERROR("SPACING",
|
|
"space required before the open parenthesis '('\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~
|
|
s/\b(if|while|for|switch)\(/$1 \(/;
|
|
}
|
|
}
|
|
|
|
# Check for illegal assignment in if conditional -- and check for trailing
|
|
# statements after the conditional.
|
|
if ($line =~ /do\s*(?!{)/) {
|
|
($stat, $cond, $line_nr_next, $remain_next, $off_next) =
|
|
ctx_statement_block($linenr, $realcnt, 0)
|
|
if (!defined $stat);
|
|
my ($stat_next) = ctx_statement_block($line_nr_next,
|
|
$remain_next, $off_next);
|
|
$stat_next =~ s/\n./\n /g;
|
|
##print "stat<$stat> stat_next<$stat_next>\n";
|
|
|
|
if ($stat_next =~ /^\s*while\b/) {
|
|
# If the statement carries leading newlines,
|
|
# then count those as offsets.
|
|
my ($whitespace) =
|
|
($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
|
|
my $offset =
|
|
statement_rawlines($whitespace) - 1;
|
|
|
|
$suppress_whiletrailers{$line_nr_next +
|
|
$offset} = 1;
|
|
}
|
|
}
|
|
if (!defined $suppress_whiletrailers{$linenr} &&
|
|
defined($stat) && defined($cond) &&
|
|
$line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
|
|
my ($s, $c) = ($stat, $cond);
|
|
|
|
if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) {
|
|
ERROR("ASSIGN_IN_IF",
|
|
"do not use assignment in if condition\n" . $herecurr);
|
|
}
|
|
|
|
# Find out what is on the end of the line after the
|
|
# conditional.
|
|
substr($s, 0, length($c), '');
|
|
$s =~ s/\n.*//g;
|
|
$s =~ s/$;//g; # Remove any comments
|
|
if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
|
|
$c !~ /}\s*while\s*/)
|
|
{
|
|
# Find out how long the conditional actually is.
|
|
my @newlines = ($c =~ /\n/gs);
|
|
my $cond_lines = 1 + $#newlines;
|
|
my $stat_real = '';
|
|
|
|
$stat_real = raw_line($linenr, $cond_lines)
|
|
. "\n" if ($cond_lines);
|
|
if (defined($stat_real) && $cond_lines > 1) {
|
|
$stat_real = "[...]\n$stat_real";
|
|
}
|
|
|
|
ERROR("TRAILING_STATEMENTS",
|
|
"trailing statements should be on next line\n" . $herecurr . $stat_real);
|
|
}
|
|
}
|
|
|
|
# Check for bitwise tests written as boolean
|
|
if ($line =~ /
|
|
(?:
|
|
(?:\[|\(|\&\&|\|\|)
|
|
\s*0[xX][0-9]+\s*
|
|
(?:\&\&|\|\|)
|
|
|
|
|
(?:\&\&|\|\|)
|
|
\s*0[xX][0-9]+\s*
|
|
(?:\&\&|\|\||\)|\])
|
|
)/x)
|
|
{
|
|
WARN("HEXADECIMAL_BOOLEAN_TEST",
|
|
"boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr);
|
|
}
|
|
|
|
# if and else should not have general statements after it
|
|
if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) {
|
|
my $s = $1;
|
|
$s =~ s/$;//g; # Remove any comments
|
|
if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
|
|
ERROR("TRAILING_STATEMENTS",
|
|
"trailing statements should be on next line\n" . $herecurr);
|
|
}
|
|
}
|
|
# if should not continue a brace
|
|
if ($line =~ /}\s*if\b/) {
|
|
ERROR("TRAILING_STATEMENTS",
|
|
"trailing statements should be on next line (or did you mean 'else if'?)\n" .
|
|
$herecurr);
|
|
}
|
|
# case and default should not have general statements after them
|
|
if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g &&
|
|
$line !~ /\G(?:
|
|
(?:\s*$;*)(?:\s*{)?(?:\s*$;*)(?:\s*\\)?\s*$|
|
|
\s*return\s+
|
|
)/xg)
|
|
{
|
|
ERROR("TRAILING_STATEMENTS",
|
|
"trailing statements should be on next line\n" . $herecurr);
|
|
}
|
|
|
|
# Check for }<nl>else {, these must be at the same
|
|
# indent level to be relevant to each other.
|
|
if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ &&
|
|
$previndent == $indent) {
|
|
if (ERROR("ELSE_AFTER_BRACE",
|
|
"else should follow close brace '}'\n" . $hereprev) &&
|
|
$fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
|
|
fix_delete_line($fixlinenr - 1, $prevrawline);
|
|
fix_delete_line($fixlinenr, $rawline);
|
|
my $fixedline = $prevrawline;
|
|
$fixedline =~ s/}\s*$//;
|
|
if ($fixedline !~ /^\+\s*$/) {
|
|
fix_insert_line($fixlinenr, $fixedline);
|
|
}
|
|
$fixedline = $rawline;
|
|
$fixedline =~ s/^(.\s*)else/$1} else/;
|
|
fix_insert_line($fixlinenr, $fixedline);
|
|
}
|
|
}
|
|
|
|
if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ &&
|
|
$previndent == $indent) {
|
|
my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0);
|
|
|
|
# Find out what is on the end of the line after the
|
|
# conditional.
|
|
substr($s, 0, length($c), '');
|
|
$s =~ s/\n.*//g;
|
|
|
|
if ($s =~ /^\s*;/) {
|
|
if (ERROR("WHILE_AFTER_BRACE",
|
|
"while should follow close brace '}'\n" . $hereprev) &&
|
|
$fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
|
|
fix_delete_line($fixlinenr - 1, $prevrawline);
|
|
fix_delete_line($fixlinenr, $rawline);
|
|
my $fixedline = $prevrawline;
|
|
my $trailing = $rawline;
|
|
$trailing =~ s/^\+//;
|
|
$trailing = trim($trailing);
|
|
$fixedline =~ s/}\s*$/} $trailing/;
|
|
fix_insert_line($fixlinenr, $fixedline);
|
|
}
|
|
}
|
|
}
|
|
|
|
#Specific variable tests
|
|
while ($line =~ m{($Constant|$Lval)}g) {
|
|
my $var = $1;
|
|
|
|
#gcc binary extension
|
|
if ($var =~ /^$Binary$/) {
|
|
if (WARN("GCC_BINARY_CONSTANT",
|
|
"Avoid gcc v4.3+ binary constant extension: <$var>\n" . $herecurr) &&
|
|
$fix) {
|
|
my $hexval = sprintf("0x%x", oct($var));
|
|
$fixed[$fixlinenr] =~
|
|
s/\b$var\b/$hexval/;
|
|
}
|
|
}
|
|
|
|
#CamelCase
|
|
if ($var !~ /^$Constant$/ &&
|
|
$var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
|
|
#Ignore Page<foo> variants
|
|
$var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
|
|
#Ignore SI style variants like nS, mV and dB (ie: max_uV, regulator_min_uA_show)
|
|
$var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/ &&
|
|
#Ignore some three character SI units explicitly, like MiB and KHz
|
|
$var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
|
|
while ($var =~ m{($Ident)}g) {
|
|
my $word = $1;
|
|
next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
|
|
if ($check) {
|
|
seed_camelcase_includes();
|
|
if (!$file && !$camelcase_file_seeded) {
|
|
seed_camelcase_file($realfile);
|
|
$camelcase_file_seeded = 1;
|
|
}
|
|
}
|
|
if (!defined $camelcase{$word}) {
|
|
$camelcase{$word} = 1;
|
|
CHK("CAMELCASE",
|
|
"Avoid CamelCase: <$word>\n" . $herecurr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#no spaces allowed after \ in define
|
|
if ($line =~ /\#\s*define.*\\\s+$/) {
|
|
if (WARN("WHITESPACE_AFTER_LINE_CONTINUATION",
|
|
"Whitespace after \\ makes next lines useless\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\s+$//;
|
|
}
|
|
}
|
|
|
|
# warn if <asm/foo.h> is #included and <linux/foo.h> is available and includes
|
|
# itself <asm/foo.h> (uses RAW line)
|
|
if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) {
|
|
my $file = "$1.h";
|
|
my $checkfile = "include/linux/$file";
|
|
if (-f "$root/$checkfile" &&
|
|
$realfile ne $checkfile &&
|
|
$1 !~ /$allowed_asm_includes/)
|
|
{
|
|
my $asminclude = `grep -Ec "#include\\s+<asm/$file>" $root/$checkfile`;
|
|
if ($asminclude > 0) {
|
|
if ($realfile =~ m{^arch/}) {
|
|
CHK("ARCH_INCLUDE_LINUX",
|
|
"Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
|
|
} else {
|
|
WARN("INCLUDE_LINUX",
|
|
"Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
# multi-statement macros should be enclosed in a do while loop, grab the
|
|
# first statement and ensure its the whole macro if its not enclosed
|
|
# in a known good container
|
|
if ($realfile !~ m@/vmlinux.lds.h$@ &&
|
|
$line =~ /^.\s*\#\s*define\s*$Ident(\()?/) {
|
|
my $ln = $linenr;
|
|
my $cnt = $realcnt - 1;
|
|
my ($off, $dstat, $dcond, $rest);
|
|
my $ctx = '';
|
|
my $has_flow_statement = 0;
|
|
my $has_arg_concat = 0;
|
|
($dstat, $dcond, $ln, $cnt, $off) =
|
|
ctx_statement_block($linenr, $realcnt, 0);
|
|
$ctx = $dstat;
|
|
#print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n";
|
|
#print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
|
|
|
|
$has_flow_statement = 1 if ($ctx =~ /\b(goto|return)\b/);
|
|
$has_arg_concat = 1 if ($ctx =~ /\#\#/);
|
|
|
|
$dstat =~ s/^.\s*\#\s*define\s+$Ident(?:\([^\)]*\))?\s*//;
|
|
$dstat =~ s/$;//g;
|
|
$dstat =~ s/\\\n.//g;
|
|
$dstat =~ s/^\s*//s;
|
|
$dstat =~ s/\s*$//s;
|
|
|
|
# Flatten any parentheses and braces
|
|
while ($dstat =~ s/\([^\(\)]*\)/1/ ||
|
|
$dstat =~ s/\{[^\{\}]*\}/1/ ||
|
|
$dstat =~ s/\[[^\[\]]*\]/1/)
|
|
{
|
|
}
|
|
|
|
# Extremely long macros may fall off the end of the
|
|
# available context without closing. Give a dangling
|
|
# backslash the benefit of the doubt and allow it
|
|
# to gobble any hanging open-parens.
|
|
$dstat =~ s/\(.+\\$/1/;
|
|
|
|
# Flatten any obvious string concatentation.
|
|
while ($dstat =~ s/($String)\s*$Ident/$1/ ||
|
|
$dstat =~ s/$Ident\s*($String)/$1/)
|
|
{
|
|
}
|
|
|
|
my $exceptions = qr{
|
|
$Declare|
|
|
module_param_named|
|
|
MODULE_PARM_DESC|
|
|
DECLARE_PER_CPU|
|
|
DEFINE_PER_CPU|
|
|
CLK_[A-Z\d_]+|
|
|
__typeof__\(|
|
|
union|
|
|
struct|
|
|
\.$Ident\s*=\s*|
|
|
^\"|\"$
|
|
}x;
|
|
#print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
|
|
if ($dstat ne '' &&
|
|
$dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(),
|
|
$dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo();
|
|
$dstat !~ /^[!~-]?(?:$Lval|$Constant)$/ && # 10 // foo() // !foo // ~foo // -foo // foo->bar // foo.bar->baz
|
|
$dstat !~ /^'X'$/ && $dstat !~ /^'XX'$/ && # character constants
|
|
$dstat !~ /$exceptions/ &&
|
|
$dstat !~ /^\.$Ident\s*=/ && # .foo =
|
|
$dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ && # stringification #foo
|
|
$dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ && # do {...} while (...); // do {...} while (...)
|
|
$dstat !~ /^for\s*$Constant$/ && # for (...)
|
|
$dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar()
|
|
$dstat !~ /^do\s*{/ && # do {...
|
|
$dstat !~ /^\(\{/ && # ({...
|
|
$ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/)
|
|
{
|
|
$ctx =~ s/\n*$//;
|
|
my $herectx = $here . "\n";
|
|
my $cnt = statement_rawlines($ctx);
|
|
|
|
for (my $n = 0; $n < $cnt; $n++) {
|
|
$herectx .= raw_line($linenr, $n) . "\n";
|
|
}
|
|
|
|
if ($dstat =~ /;/) {
|
|
ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE",
|
|
"Macros with multiple statements should be enclosed in a do - while loop\n" . "$herectx");
|
|
} else {
|
|
ERROR("COMPLEX_MACRO",
|
|
"Macros with complex values should be enclosed in parentheses\n" . "$herectx");
|
|
}
|
|
}
|
|
|
|
# check for macros with flow control, but without ## concatenation
|
|
# ## concatenation is commonly a macro that defines a function so ignore those
|
|
if ($has_flow_statement && !$has_arg_concat) {
|
|
my $herectx = $here . "\n";
|
|
my $cnt = statement_rawlines($ctx);
|
|
|
|
for (my $n = 0; $n < $cnt; $n++) {
|
|
$herectx .= raw_line($linenr, $n) . "\n";
|
|
}
|
|
WARN("MACRO_WITH_FLOW_CONTROL",
|
|
"Macros with flow control statements should be avoided\n" . "$herectx");
|
|
}
|
|
|
|
# check for line continuations outside of #defines, preprocessor #, and asm
|
|
|
|
} else {
|
|
if ($prevline !~ /^..*\\$/ &&
|
|
$line !~ /^\+\s*\#.*\\$/ && # preprocessor
|
|
$line !~ /^\+.*\b(__asm__|asm)\b.*\\$/ && # asm
|
|
$line =~ /^\+.*\\$/) {
|
|
WARN("LINE_CONTINUATIONS",
|
|
"Avoid unnecessary line continuations\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
# do {} while (0) macro tests:
|
|
# single-statement macros do not need to be enclosed in do while (0) loop,
|
|
# macro should not end with a semicolon
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
$realfile !~ m@/vmlinux.lds.h$@ &&
|
|
$line =~ /^.\s*\#\s*define\s+$Ident(\()?/) {
|
|
my $ln = $linenr;
|
|
my $cnt = $realcnt;
|
|
my ($off, $dstat, $dcond, $rest);
|
|
my $ctx = '';
|
|
($dstat, $dcond, $ln, $cnt, $off) =
|
|
ctx_statement_block($linenr, $realcnt, 0);
|
|
$ctx = $dstat;
|
|
|
|
$dstat =~ s/\\\n.//g;
|
|
$dstat =~ s/$;/ /g;
|
|
|
|
if ($dstat =~ /^\+\s*#\s*define\s+$Ident\s*${balanced_parens}\s*do\s*{(.*)\s*}\s*while\s*\(\s*0\s*\)\s*([;\s]*)\s*$/) {
|
|
my $stmts = $2;
|
|
my $semis = $3;
|
|
|
|
$ctx =~ s/\n*$//;
|
|
my $cnt = statement_rawlines($ctx);
|
|
my $herectx = $here . "\n";
|
|
|
|
for (my $n = 0; $n < $cnt; $n++) {
|
|
$herectx .= raw_line($linenr, $n) . "\n";
|
|
}
|
|
|
|
if (($stmts =~ tr/;/;/) == 1 &&
|
|
$stmts !~ /^\s*(if|while|for|switch)\b/) {
|
|
WARN("SINGLE_STATEMENT_DO_WHILE_MACRO",
|
|
"Single statement macros should not use a do {} while (0) loop\n" . "$herectx");
|
|
}
|
|
if (defined $semis && $semis ne "") {
|
|
WARN("DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON",
|
|
"do {} while (0) macros should not be semicolon terminated\n" . "$herectx");
|
|
}
|
|
} elsif ($dstat =~ /^\+\s*#\s*define\s+$Ident.*;\s*$/) {
|
|
$ctx =~ s/\n*$//;
|
|
my $cnt = statement_rawlines($ctx);
|
|
my $herectx = $here . "\n";
|
|
|
|
for (my $n = 0; $n < $cnt; $n++) {
|
|
$herectx .= raw_line($linenr, $n) . "\n";
|
|
}
|
|
|
|
WARN("TRAILING_SEMICOLON",
|
|
"macros should not use a trailing semicolon\n" . "$herectx");
|
|
}
|
|
}
|
|
|
|
# make sure symbols are always wrapped with VMLINUX_SYMBOL() ...
|
|
# all assignments may have only one of the following with an assignment:
|
|
# .
|
|
# ALIGN(...)
|
|
# VMLINUX_SYMBOL(...)
|
|
if ($realfile eq 'vmlinux.lds.h' && $line =~ /(?:(?:^|\s)$Ident\s*=|=\s*$Ident(?:\s|$))/) {
|
|
WARN("MISSING_VMLINUX_SYMBOL",
|
|
"vmlinux.lds.h needs VMLINUX_SYMBOL() around C-visible symbols\n" . $herecurr);
|
|
}
|
|
|
|
# check for redundant bracing round if etc
|
|
if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) {
|
|
my ($level, $endln, @chunks) =
|
|
ctx_statement_full($linenr, $realcnt, 1);
|
|
#print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
|
|
#print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n";
|
|
if ($#chunks > 0 && $level == 0) {
|
|
my @allowed = ();
|
|
my $allow = 0;
|
|
my $seen = 0;
|
|
my $herectx = $here . "\n";
|
|
my $ln = $linenr - 1;
|
|
for my $chunk (@chunks) {
|
|
my ($cond, $block) = @{$chunk};
|
|
|
|
# If the condition carries leading newlines, then count those as offsets.
|
|
my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
|
|
my $offset = statement_rawlines($whitespace) - 1;
|
|
|
|
$allowed[$allow] = 0;
|
|
#print "COND<$cond> whitespace<$whitespace> offset<$offset>\n";
|
|
|
|
# We have looked at and allowed this specific line.
|
|
$suppress_ifbraces{$ln + $offset} = 1;
|
|
|
|
$herectx .= "$rawlines[$ln + $offset]\n[...]\n";
|
|
$ln += statement_rawlines($block) - 1;
|
|
|
|
substr($block, 0, length($cond), '');
|
|
|
|
$seen++ if ($block =~ /^\s*{/);
|
|
|
|
#print "cond<$cond> block<$block> allowed<$allowed[$allow]>\n";
|
|
if (statement_lines($cond) > 1) {
|
|
#print "APW: ALLOWED: cond<$cond>\n";
|
|
$allowed[$allow] = 1;
|
|
}
|
|
if ($block =~/\b(?:if|for|while)\b/) {
|
|
#print "APW: ALLOWED: block<$block>\n";
|
|
$allowed[$allow] = 1;
|
|
}
|
|
if (statement_block_size($block) > 1) {
|
|
#print "APW: ALLOWED: lines block<$block>\n";
|
|
$allowed[$allow] = 1;
|
|
}
|
|
$allow++;
|
|
}
|
|
if ($seen) {
|
|
my $sum_allowed = 0;
|
|
foreach (@allowed) {
|
|
$sum_allowed += $_;
|
|
}
|
|
if ($sum_allowed == 0) {
|
|
WARN("BRACES",
|
|
"braces {} are not necessary for any arm of this statement\n" . $herectx);
|
|
} elsif ($sum_allowed != $allow &&
|
|
$seen != $allow) {
|
|
CHK("BRACES",
|
|
"braces {} should be used on all arms of this statement\n" . $herectx);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!defined $suppress_ifbraces{$linenr - 1} &&
|
|
$line =~ /\b(if|while|for|else)\b/) {
|
|
my $allowed = 0;
|
|
|
|
# Check the pre-context.
|
|
if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
|
|
#print "APW: ALLOWED: pre<$1>\n";
|
|
$allowed = 1;
|
|
}
|
|
|
|
my ($level, $endln, @chunks) =
|
|
ctx_statement_full($linenr, $realcnt, $-[0]);
|
|
|
|
# Check the condition.
|
|
my ($cond, $block) = @{$chunks[0]};
|
|
#print "CHECKING<$linenr> cond<$cond> block<$block>\n";
|
|
if (defined $cond) {
|
|
substr($block, 0, length($cond), '');
|
|
}
|
|
if (statement_lines($cond) > 1) {
|
|
#print "APW: ALLOWED: cond<$cond>\n";
|
|
$allowed = 1;
|
|
}
|
|
if ($block =~/\b(?:if|for|while)\b/) {
|
|
#print "APW: ALLOWED: block<$block>\n";
|
|
$allowed = 1;
|
|
}
|
|
if (statement_block_size($block) > 1) {
|
|
#print "APW: ALLOWED: lines block<$block>\n";
|
|
$allowed = 1;
|
|
}
|
|
# Check the post-context.
|
|
if (defined $chunks[1]) {
|
|
my ($cond, $block) = @{$chunks[1]};
|
|
if (defined $cond) {
|
|
substr($block, 0, length($cond), '');
|
|
}
|
|
if ($block =~ /^\s*\{/) {
|
|
#print "APW: ALLOWED: chunk-1 block<$block>\n";
|
|
$allowed = 1;
|
|
}
|
|
}
|
|
if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
|
|
my $herectx = $here . "\n";
|
|
my $cnt = statement_rawlines($block);
|
|
|
|
for (my $n = 0; $n < $cnt; $n++) {
|
|
$herectx .= raw_line($linenr, $n) . "\n";
|
|
}
|
|
|
|
WARN("BRACES",
|
|
"braces {} are not necessary for single statement blocks\n" . $herectx);
|
|
}
|
|
}
|
|
|
|
# check for unnecessary blank lines around braces
|
|
if (($line =~ /^.\s*}\s*$/ && $prevrawline =~ /^.\s*$/)) {
|
|
if (CHK("BRACES",
|
|
"Blank lines aren't necessary before a close brace '}'\n" . $hereprev) &&
|
|
$fix && $prevrawline =~ /^\+/) {
|
|
fix_delete_line($fixlinenr - 1, $prevrawline);
|
|
}
|
|
}
|
|
if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) {
|
|
if (CHK("BRACES",
|
|
"Blank lines aren't necessary after an open brace '{'\n" . $hereprev) &&
|
|
$fix) {
|
|
fix_delete_line($fixlinenr, $rawline);
|
|
}
|
|
}
|
|
|
|
# no volatiles please
|
|
my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
|
|
if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
|
|
WARN("VOLATILE",
|
|
"Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr);
|
|
}
|
|
|
|
# Check for user-visible strings broken across lines, which breaks the ability
|
|
# to grep for the string. Make exceptions when the previous string ends in a
|
|
# newline (multiple lines in one string constant) or '\t', '\r', ';', or '{'
|
|
# (common in inline assembly) or is a octal \123 or hexadecimal \xaf value
|
|
if ($line =~ /^\+\s*$String/ &&
|
|
$prevline =~ /"\s*$/ &&
|
|
$prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) {
|
|
if (WARN("SPLIT_STRING",
|
|
"quoted string split across lines\n" . $hereprev) &&
|
|
$fix &&
|
|
$prevrawline =~ /^\+.*"\s*$/ &&
|
|
$last_coalesced_string_linenr != $linenr - 1) {
|
|
my $extracted_string = get_quoted_string($line, $rawline);
|
|
my $comma_close = "";
|
|
if ($rawline =~ /\Q$extracted_string\E(\s*\)\s*;\s*$|\s*,\s*)/) {
|
|
$comma_close = $1;
|
|
}
|
|
|
|
fix_delete_line($fixlinenr - 1, $prevrawline);
|
|
fix_delete_line($fixlinenr, $rawline);
|
|
my $fixedline = $prevrawline;
|
|
$fixedline =~ s/"\s*$//;
|
|
$fixedline .= substr($extracted_string, 1) . trim($comma_close);
|
|
fix_insert_line($fixlinenr - 1, $fixedline);
|
|
$fixedline = $rawline;
|
|
$fixedline =~ s/\Q$extracted_string\E\Q$comma_close\E//;
|
|
if ($fixedline !~ /\+\s*$/) {
|
|
fix_insert_line($fixlinenr, $fixedline);
|
|
}
|
|
$last_coalesced_string_linenr = $linenr;
|
|
}
|
|
}
|
|
|
|
# check for missing a space in a string concatenation
|
|
if ($prevrawline =~ /[^\\]\w"$/ && $rawline =~ /^\+[\t ]+"\w/) {
|
|
WARN('MISSING_SPACE',
|
|
"break quoted strings at a space character\n" . $hereprev);
|
|
}
|
|
|
|
# check for spaces before a quoted newline
|
|
if ($rawline =~ /^.*\".*\s\\n/) {
|
|
if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
|
|
"unnecessary whitespace before a quoted newline\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/^(\+.*\".*)\s+\\n/$1\\n/;
|
|
}
|
|
|
|
}
|
|
|
|
# concatenated string without spaces between elements
|
|
if ($line =~ /$String[A-Z_]/ || $line =~ /[A-Za-z0-9_]$String/) {
|
|
CHK("CONCATENATED_STRING",
|
|
"Concatenated strings should use spaces between elements\n" . $herecurr);
|
|
}
|
|
|
|
# uncoalesced string fragments
|
|
if ($line =~ /$String\s*"/) {
|
|
WARN("STRING_FRAGMENTS",
|
|
"Consecutive strings are generally better as a single string\n" . $herecurr);
|
|
}
|
|
|
|
# check for %L{u,d,i} and 0x%[udi] in strings
|
|
my $string;
|
|
while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {
|
|
$string = substr($rawline, $-[1], $+[1] - $-[1]);
|
|
$string =~ s/%%/__/g;
|
|
if ($string =~ /(?<!%)%[\*\d\.\$]*L[udi]/) {
|
|
WARN("PRINTF_L",
|
|
"\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr);
|
|
last;
|
|
}
|
|
if ($string =~ /0x%[\*\d\.\$\Llzth]*[udi]/) {
|
|
ERROR("PRINTF_0xDECIMAL",
|
|
"Prefixing 0x with decimal output is defective\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
# check for line continuations in quoted strings with odd counts of "
|
|
if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) {
|
|
WARN("LINE_CONTINUATIONS",
|
|
"Avoid line continuations in quoted strings\n" . $herecurr);
|
|
}
|
|
|
|
# sys_open/read/write/close are not allowed in the kernel
|
|
if ($line =~ /\b(sys_(?:open|read|write|close))\b/) {
|
|
ERROR("FILE_OPS",
|
|
"$1 is inappropriate in kernel code.\n" .
|
|
$herecurr);
|
|
}
|
|
|
|
# filp_open is a backdoor for sys_open
|
|
if ($line =~ /\b(filp_open)\b/) {
|
|
ERROR("FILE_OPS",
|
|
"$1 is inappropriate in kernel code.\n" .
|
|
$herecurr);
|
|
}
|
|
|
|
# read[bwl] & write[bwl] use too many barriers, use the _relaxed variants
|
|
if ($line =~ /\b((?:read|write)[bwl])\b/) {
|
|
ERROR("NON_RELAXED_IO",
|
|
"Use of $1 is deprecated: use $1_relaxed\n\t" .
|
|
"with appropriate memory barriers instead.\n" .
|
|
$herecurr);
|
|
}
|
|
|
|
# likewise, in/out[bwl] should be __raw_read/write[bwl]...
|
|
if ($line =~ /\b((in|out)([bwl]))\b/) {
|
|
my ($all, $pref, $suf) = ($1, $2, $3);
|
|
$pref =~ s/in/read/;
|
|
$pref =~ s/out/write/;
|
|
ERROR("NON_RELAXED_IO",
|
|
"Use of $all is deprecated: use " .
|
|
"__raw_$pref$suf\n\t" .
|
|
"with appropriate memory barriers instead.\n" .
|
|
$herecurr);
|
|
}
|
|
|
|
# dsb is too ARMish, and should usually be mb.
|
|
if ($line =~ /[^-_>*\.]\bdsb\b[^-_\.;]/) {
|
|
WARN("ARM_BARRIER",
|
|
"Use of dsb is discouranged: prefer mb.\n" .
|
|
$herecurr);
|
|
}
|
|
|
|
# MSM - check if a non board-gpiomux file has any gpiomux declarations
|
|
if ($realfile =~ /\/mach-msm\/board-[0-9]+/ &&
|
|
$realfile !~ /camera/ && $realfile !~ /gpiomux/ &&
|
|
$line =~ /\s*struct msm_gpiomux_config\s*/ ) {
|
|
WARN("GPIOMUX_IN_BOARD",
|
|
"Non gpiomux board file cannot have a gpiomux config declarations. Please declare gpiomux configs in board-*-gpiomux.c file.\n" . $herecurr);
|
|
}
|
|
|
|
# MSM - check if vreg_xxx function are used
|
|
if ($line =~ /\b(vreg_(get|put|set_level|enable|disable))\b/) {
|
|
WARN("DEPRECATED_VREG_APIS",
|
|
"Use of $1 API is deprecated: " .
|
|
"use regulator APIs\n" . $herecurr);
|
|
}
|
|
|
|
# unbounded string functions are overflow risks
|
|
my %str_fns = (
|
|
"sprintf" => "snprintf",
|
|
"strcpy" => "strlcpy",
|
|
"strncpy" => "strlcpy",
|
|
"strcat" => "strlcat",
|
|
"strncat" => "strlcat",
|
|
"vsprintf" => "vsnprintf",
|
|
"strchr" => "strnchr",
|
|
"strstr" => "strnstr",
|
|
);
|
|
foreach my $k (keys %str_fns) {
|
|
if ($line =~ /\b$k\b/) {
|
|
ERROR("UNBOUNDED_STRING_FNS",
|
|
"Use of $k is deprecated: " .
|
|
"use $str_fns{$k} instead.\n" .
|
|
$herecurr);
|
|
}
|
|
}
|
|
|
|
# warn about #if 0
|
|
if ($line =~ /^.\s*\#\s*if\s+0\b/) {
|
|
WARN("IF_0",
|
|
"if this code is redundant consider removing it\n"
|
|
. $herecurr);
|
|
}
|
|
|
|
# warn about #if 1
|
|
if ($line =~ /^.\s*\#\s*if\s+1\b/) {
|
|
WARN("IF_1",
|
|
"if this code is required consider removing"
|
|
. " #if 1\n" . $herecurr);
|
|
}
|
|
|
|
# check for needless "if (<foo>) fn(<foo>)" uses
|
|
if ($prevline =~ /\bif\s*\(\s*($Lval)\s*\)/) {
|
|
my $tested = quotemeta($1);
|
|
my $expr = '\s*\(\s*' . $tested . '\s*\)\s*;';
|
|
if ($line =~ /\b(kfree|usb_free_urb|debugfs_remove(?:_recursive)?|(?:kmem_cache|mempool|dma_pool)_destroy)$expr/) {
|
|
my $func = $1;
|
|
if (WARN('NEEDLESS_IF',
|
|
"$func(NULL) is safe and this check is probably not required\n" . $hereprev) &&
|
|
$fix) {
|
|
my $do_fix = 1;
|
|
my $leading_tabs = "";
|
|
my $new_leading_tabs = "";
|
|
if ($lines[$linenr - 2] =~ /^\+(\t*)if\s*\(\s*$tested\s*\)\s*$/) {
|
|
$leading_tabs = $1;
|
|
} else {
|
|
$do_fix = 0;
|
|
}
|
|
if ($lines[$linenr - 1] =~ /^\+(\t+)$func\s*\(\s*$tested\s*\)\s*;\s*$/) {
|
|
$new_leading_tabs = $1;
|
|
if (length($leading_tabs) + 1 ne length($new_leading_tabs)) {
|
|
$do_fix = 0;
|
|
}
|
|
} else {
|
|
$do_fix = 0;
|
|
}
|
|
if ($do_fix) {
|
|
fix_delete_line($fixlinenr - 1, $prevrawline);
|
|
$fixed[$fixlinenr] =~ s/^\+$new_leading_tabs/\+$leading_tabs/;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
# check for unnecessary "Out of Memory" messages
|
|
if ($line =~ /^\+.*\b$logFunctions\s*\(/ &&
|
|
$prevline =~ /^[ \+]\s*if\s*\(\s*(\!\s*|NULL\s*==\s*)?($Lval)(\s*==\s*NULL\s*)?\s*\)/ &&
|
|
(defined $1 || defined $3) &&
|
|
$linenr > 3) {
|
|
my $testval = $2;
|
|
my $testline = $lines[$linenr - 3];
|
|
|
|
my ($s, $c) = ctx_statement_block($linenr - 3, $realcnt, 0);
|
|
# print("line: <$line>\nprevline: <$prevline>\ns: <$s>\nc: <$c>\n\n\n");
|
|
|
|
if ($c =~ /(?:^|\n)[ \+]\s*(?:$Type\s*)?\Q$testval\E\s*=\s*(?:\([^\)]*\)\s*)?\s*(?:devm_)?(?:[kv][czm]alloc(?:_node|_array)?\b|kstrdup|(?:dev_)?alloc_skb)/) {
|
|
WARN("OOM_MESSAGE",
|
|
"Possible unnecessary 'out of memory' message\n" . $hereprev);
|
|
}
|
|
}
|
|
|
|
# check for logging functions with KERN_<LEVEL>
|
|
if ($line !~ /printk(?:_ratelimited|_once)?\s*\(/ &&
|
|
$line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) {
|
|
my $level = $1;
|
|
if (WARN("UNNECESSARY_KERN_LEVEL",
|
|
"Possible unnecessary $level\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\s*$level\s*//;
|
|
}
|
|
}
|
|
|
|
# check for mask then right shift without a parentheses
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
$line =~ /$LvalOrFunc\s*\&\s*($LvalOrFunc)\s*>>/ &&
|
|
$4 !~ /^\&/) { # $LvalOrFunc may be &foo, ignore if so
|
|
WARN("MASK_THEN_SHIFT",
|
|
"Possible precedence defect with mask then right shift - may need parentheses\n" . $herecurr);
|
|
}
|
|
|
|
# check for pointer comparisons to NULL
|
|
if ($^V && $^V ge 5.10.0) {
|
|
while ($line =~ /\b$LvalOrFunc\s*(==|\!=)\s*NULL\b/g) {
|
|
my $val = $1;
|
|
my $equal = "!";
|
|
$equal = "" if ($4 eq "!=");
|
|
if (CHK("COMPARISON_TO_NULL",
|
|
"Comparison to NULL could be written \"${equal}${val}\"\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\b\Q$val\E\s*(?:==|\!=)\s*NULL\b/$equal$val/;
|
|
}
|
|
}
|
|
}
|
|
|
|
# check for bad placement of section $InitAttribute (e.g.: __initdata)
|
|
if ($line =~ /(\b$InitAttribute\b)/) {
|
|
my $attr = $1;
|
|
if ($line =~ /^\+\s*static\s+(?:const\s+)?(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])?)\s*[=;]/) {
|
|
my $ptr = $1;
|
|
my $var = $2;
|
|
if ((($ptr =~ /\b(union|struct)\s+$attr\b/ &&
|
|
ERROR("MISPLACED_INIT",
|
|
"$attr should be placed after $var\n" . $herecurr)) ||
|
|
($ptr !~ /\b(union|struct)\s+$attr\b/ &&
|
|
WARN("MISPLACED_INIT",
|
|
"$attr should be placed after $var\n" . $herecurr))) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/(\bstatic\s+(?:const\s+)?)(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])?)\s*([=;])\s*/"$1" . trim(string_find_replace($2, "\\s*$attr\\s*", " ")) . " " . trim(string_find_replace($3, "\\s*$attr\\s*", "")) . " $attr" . ("$4" eq ";" ? ";" : " = ")/e;
|
|
}
|
|
}
|
|
}
|
|
|
|
# check for $InitAttributeData (ie: __initdata) with const
|
|
if ($line =~ /\bconst\b/ && $line =~ /($InitAttributeData)/) {
|
|
my $attr = $1;
|
|
$attr =~ /($InitAttributePrefix)(.*)/;
|
|
my $attr_prefix = $1;
|
|
my $attr_type = $2;
|
|
if (ERROR("INIT_ATTRIBUTE",
|
|
"Use of const init definition must use ${attr_prefix}initconst\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~
|
|
s/$InitAttributeData/${attr_prefix}initconst/;
|
|
}
|
|
}
|
|
|
|
# check for $InitAttributeConst (ie: __initconst) without const
|
|
if ($line !~ /\bconst\b/ && $line =~ /($InitAttributeConst)/) {
|
|
my $attr = $1;
|
|
if (ERROR("INIT_ATTRIBUTE",
|
|
"Use of $attr requires a separate use of const\n" . $herecurr) &&
|
|
$fix) {
|
|
my $lead = $fixed[$fixlinenr] =~
|
|
/(^\+\s*(?:static\s+))/;
|
|
$lead = rtrim($1);
|
|
$lead = "$lead " if ($lead !~ /^\+$/);
|
|
$lead = "${lead}const ";
|
|
$fixed[$fixlinenr] =~ s/(^\+\s*(?:static\s+))/$lead/;
|
|
}
|
|
}
|
|
|
|
# check for __read_mostly with const non-pointer (should just be const)
|
|
if ($line =~ /\b__read_mostly\b/ &&
|
|
$line =~ /($Type)\s*$Ident/ && $1 !~ /\*\s*$/ && $1 =~ /\bconst\b/) {
|
|
if (ERROR("CONST_READ_MOSTLY",
|
|
"Invalid use of __read_mostly with const type\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\s+__read_mostly\b//;
|
|
}
|
|
}
|
|
|
|
# don't use __constant_<foo> functions outside of include/uapi/
|
|
if ($realfile !~ m@^include/uapi/@ &&
|
|
$line =~ /(__constant_(?:htons|ntohs|[bl]e(?:16|32|64)_to_cpu|cpu_to_[bl]e(?:16|32|64)))\s*\(/) {
|
|
my $constant_func = $1;
|
|
my $func = $constant_func;
|
|
$func =~ s/^__constant_//;
|
|
if (WARN("CONSTANT_CONVERSION",
|
|
"$constant_func should be $func\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\b$constant_func\b/$func/g;
|
|
}
|
|
}
|
|
|
|
# prefer usleep_range over udelay
|
|
if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
|
|
my $delay = $1;
|
|
# ignore udelay's < 10, however
|
|
if (! ($delay < 10) ) {
|
|
CHK("USLEEP_RANGE",
|
|
"usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $herecurr);
|
|
}
|
|
if ($delay > 2000) {
|
|
WARN("LONG_UDELAY",
|
|
"long udelay - prefer mdelay; see arch/arm/include/asm/delay.h\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
# warn about unexpectedly long msleep's
|
|
if ($line =~ /\bmsleep\s*\((\d+)\);/) {
|
|
if ($1 < 20) {
|
|
WARN("MSLEEP",
|
|
"msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
# check for comparisons of jiffies
|
|
if ($line =~ /\bjiffies\s*$Compare|$Compare\s*jiffies\b/) {
|
|
WARN("JIFFIES_COMPARISON",
|
|
"Comparing jiffies is almost always wrong; prefer time_after, time_before and friends\n" . $herecurr);
|
|
}
|
|
|
|
# check for comparisons of get_jiffies_64()
|
|
if ($line =~ /\bget_jiffies_64\s*\(\s*\)\s*$Compare|$Compare\s*get_jiffies_64\s*\(\s*\)/) {
|
|
WARN("JIFFIES_COMPARISON",
|
|
"Comparing get_jiffies_64() is almost always wrong; prefer time_after64, time_before64 and friends\n" . $herecurr);
|
|
}
|
|
|
|
# check the patch for use of mdelay
|
|
if ($line =~ /\bmdelay\s*\(/) {
|
|
WARN("MDELAY",
|
|
"use of mdelay() found: msleep() is the preferred API.\n" . $herecurr );
|
|
}
|
|
|
|
# warn about #ifdefs in C files
|
|
# if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
|
|
# print "#ifdef in C files should be avoided\n";
|
|
# print "$herecurr";
|
|
# $clean = 0;
|
|
# }
|
|
|
|
# warn about spacing in #ifdefs
|
|
if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) {
|
|
if (ERROR("SPACING",
|
|
"exactly one space required after that #$1\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~
|
|
s/^(.\s*\#\s*(ifdef|ifndef|elif))\s{2,}/$1 /;
|
|
}
|
|
|
|
}
|
|
|
|
# check for spinlock_t definitions without a comment.
|
|
if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/ ||
|
|
$line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) {
|
|
my $which = $1;
|
|
if (!ctx_has_comment($first_line, $linenr)) {
|
|
CHK("UNCOMMENTED_DEFINITION",
|
|
"$1 definition without comment\n" . $herecurr);
|
|
}
|
|
}
|
|
# check for memory barriers without a comment.
|
|
if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
|
|
if (!ctx_has_comment($first_line, $linenr)) {
|
|
WARN("MEMORY_BARRIER",
|
|
"memory barrier without comment\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
# check for waitqueue_active without a comment.
|
|
if ($line =~ /\bwaitqueue_active\s*\(/) {
|
|
if (!ctx_has_comment($first_line, $linenr)) {
|
|
WARN("WAITQUEUE_ACTIVE",
|
|
"waitqueue_active without comment\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
# Check for expedited grace periods that interrupt non-idle non-nohz
|
|
# online CPUs. These expedited can therefore degrade real-time response
|
|
# if used carelessly, and should be avoided where not absolutely
|
|
# needed. It is always OK to use synchronize_rcu_expedited() and
|
|
# synchronize_sched_expedited() at boot time (before real-time applications
|
|
# start) and in error situations where real-time response is compromised in
|
|
# any case. Note that synchronize_srcu_expedited() does -not- interrupt
|
|
# other CPUs, so don't warn on uses of synchronize_srcu_expedited().
|
|
# Of course, nothing comes for free, and srcu_read_lock() and
|
|
# srcu_read_unlock() do contain full memory barriers in payment for
|
|
# synchronize_srcu_expedited() non-interruption properties.
|
|
if ($line =~ /\b(synchronize_rcu_expedited|synchronize_sched_expedited)\(/) {
|
|
WARN("EXPEDITED_RCU_GRACE_PERIOD",
|
|
"expedited RCU grace periods should be avoided where they can degrade real-time response\n" . $herecurr);
|
|
|
|
}
|
|
|
|
# check of hardware specific defines
|
|
if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
|
|
CHK("ARCH_DEFINES",
|
|
"architecture specific defines should be avoided\n" . $herecurr);
|
|
}
|
|
|
|
# Check that the storage class is at the beginning of a declaration
|
|
if ($line =~ /\b$Storage\b/ && $line !~ /^.\s*$Storage\b/) {
|
|
WARN("STORAGE_CLASS",
|
|
"storage class should be at the beginning of the declaration\n" . $herecurr)
|
|
}
|
|
|
|
# check the location of the inline attribute, that it is between
|
|
# storage class and type.
|
|
if ($line =~ /\b$Type\s+$Inline\b/ ||
|
|
$line =~ /\b$Inline\s+$Storage\b/) {
|
|
ERROR("INLINE_LOCATION",
|
|
"inline keyword should sit between storage class and type\n" . $herecurr);
|
|
}
|
|
|
|
# Check for __inline__ and __inline, prefer inline
|
|
if ($realfile !~ m@\binclude/uapi/@ &&
|
|
$line =~ /\b(__inline__|__inline)\b/) {
|
|
if (WARN("INLINE",
|
|
"plain inline is preferred over $1\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\b(__inline__|__inline)\b/inline/;
|
|
|
|
}
|
|
}
|
|
|
|
# Check for __attribute__ packed, prefer __packed
|
|
if ($realfile !~ m@\binclude/uapi/@ &&
|
|
$line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
|
|
WARN("PREFER_PACKED",
|
|
"__packed is preferred over __attribute__((packed))\n" . $herecurr);
|
|
}
|
|
|
|
# Check for __attribute__ aligned, prefer __aligned
|
|
if ($realfile !~ m@\binclude/uapi/@ &&
|
|
$line =~ /\b__attribute__\s*\(\s*\(.*aligned/) {
|
|
WARN("PREFER_ALIGNED",
|
|
"__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr);
|
|
}
|
|
|
|
# Check for __attribute__ format(printf, prefer __printf
|
|
if ($realfile !~ m@\binclude/uapi/@ &&
|
|
$line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) {
|
|
if (WARN("PREFER_PRINTF",
|
|
"__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf\s*,\s*(.*)\)\s*\)\s*\)/"__printf(" . trim($1) . ")"/ex;
|
|
|
|
}
|
|
}
|
|
|
|
# Check for __attribute__ format(scanf, prefer __scanf
|
|
if ($realfile !~ m@\binclude/uapi/@ &&
|
|
$line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) {
|
|
if (WARN("PREFER_SCANF",
|
|
"__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\s*,\s*(.*)\)\s*\)\s*\)/"__scanf(" . trim($1) . ")"/ex;
|
|
}
|
|
}
|
|
|
|
# Check for __attribute__ weak, or __weak declarations (may have link issues)
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
$line =~ /(?:$Declare|$DeclareMisordered)\s*$Ident\s*$balanced_parens\s*(?:$Attribute)?\s*;/ &&
|
|
($line =~ /\b__attribute__\s*\(\s*\(.*\bweak\b/ ||
|
|
$line =~ /\b__weak\b/)) {
|
|
ERROR("WEAK_DECLARATION",
|
|
"Using weak declarations can have unintended link defects\n" . $herecurr);
|
|
}
|
|
|
|
# check for c99 types like uint8_t used outside of uapi/
|
|
if ($realfile !~ m@\binclude/uapi/@ &&
|
|
$line =~ /\b($Declare)\s*$Ident\s*[=;,\[]/) {
|
|
my $type = $1;
|
|
if ($type =~ /\b($typeC99Typedefs)\b/) {
|
|
$type = $1;
|
|
my $kernel_type = 'u';
|
|
$kernel_type = 's' if ($type =~ /^_*[si]/);
|
|
$type =~ /(\d+)/;
|
|
$kernel_type .= $1;
|
|
if (CHK("PREFER_KERNEL_TYPES",
|
|
"Prefer kernel type '$kernel_type' over '$type'\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\b$type\b/$kernel_type/;
|
|
}
|
|
}
|
|
}
|
|
|
|
# check for sizeof(&)
|
|
if ($line =~ /\bsizeof\s*\(\s*\&/) {
|
|
WARN("SIZEOF_ADDRESS",
|
|
"sizeof(& should be avoided\n" . $herecurr);
|
|
}
|
|
|
|
# check for sizeof without parenthesis
|
|
if ($line =~ /\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/) {
|
|
if (WARN("SIZEOF_PARENTHESIS",
|
|
"sizeof $1 should be sizeof($1)\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/"sizeof(" . trim($1) . ")"/ex;
|
|
}
|
|
}
|
|
|
|
# check for struct spinlock declarations
|
|
if ($line =~ /^.\s*\bstruct\s+spinlock\s+\w+\s*;/) {
|
|
WARN("USE_SPINLOCK_T",
|
|
"struct spinlock should be spinlock_t\n" . $herecurr);
|
|
}
|
|
|
|
# check for seq_printf uses that could be seq_puts
|
|
if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) {
|
|
my $fmt = get_quoted_string($line, $rawline);
|
|
$fmt =~ s/%%//g;
|
|
if ($fmt !~ /%/) {
|
|
if (WARN("PREFER_SEQ_PUTS",
|
|
"Prefer seq_puts to seq_printf\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\bseq_printf\b/seq_puts/;
|
|
}
|
|
}
|
|
}
|
|
|
|
# Check for misused memsets
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
defined $stat &&
|
|
$stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/) {
|
|
|
|
my $ms_addr = $2;
|
|
my $ms_val = $7;
|
|
my $ms_size = $12;
|
|
|
|
if ($ms_size =~ /^(0x|)0$/i) {
|
|
ERROR("MEMSET",
|
|
"memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$stat\n");
|
|
} elsif ($ms_size =~ /^(0x|)1$/i) {
|
|
WARN("MEMSET",
|
|
"single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n");
|
|
}
|
|
}
|
|
|
|
# Check for memcpy(foo, bar, ETH_ALEN) that could be ether_addr_copy(foo, bar)
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
defined $stat &&
|
|
$stat =~ /^\+(?:.*?)\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
|
|
if (WARN("PREFER_ETHER_ADDR_COPY",
|
|
"Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)\n" . "$here\n$stat\n") &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/ether_addr_copy($2, $7)/;
|
|
}
|
|
}
|
|
|
|
# Check for memcmp(foo, bar, ETH_ALEN) that could be ether_addr_equal*(foo, bar)
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
defined $stat &&
|
|
$stat =~ /^\+(?:.*?)\bmemcmp\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
|
|
WARN("PREFER_ETHER_ADDR_EQUAL",
|
|
"Prefer ether_addr_equal() or ether_addr_equal_unaligned() over memcmp()\n" . "$here\n$stat\n")
|
|
}
|
|
|
|
# check for memset(foo, 0x0, ETH_ALEN) that could be eth_zero_addr
|
|
# check for memset(foo, 0xFF, ETH_ALEN) that could be eth_broadcast_addr
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
defined $stat &&
|
|
$stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
|
|
|
|
my $ms_val = $7;
|
|
|
|
if ($ms_val =~ /^(?:0x|)0+$/i) {
|
|
if (WARN("PREFER_ETH_ZERO_ADDR",
|
|
"Prefer eth_zero_addr over memset()\n" . "$here\n$stat\n") &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_zero_addr($2)/;
|
|
}
|
|
} elsif ($ms_val =~ /^(?:0xff|255)$/i) {
|
|
if (WARN("PREFER_ETH_BROADCAST_ADDR",
|
|
"Prefer eth_broadcast_addr() over memset()\n" . "$here\n$stat\n") &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_broadcast_addr($2)/;
|
|
}
|
|
}
|
|
}
|
|
|
|
# typecasts on min/max could be min_t/max_t
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
defined $stat &&
|
|
$stat =~ /^\+(?:.*?)\b(min|max)\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) {
|
|
if (defined $2 || defined $7) {
|
|
my $call = $1;
|
|
my $cast1 = deparenthesize($2);
|
|
my $arg1 = $3;
|
|
my $cast2 = deparenthesize($7);
|
|
my $arg2 = $8;
|
|
my $cast;
|
|
|
|
if ($cast1 ne "" && $cast2 ne "" && $cast1 ne $cast2) {
|
|
$cast = "$cast1 or $cast2";
|
|
} elsif ($cast1 ne "") {
|
|
$cast = $cast1;
|
|
} else {
|
|
$cast = $cast2;
|
|
}
|
|
WARN("MINMAX",
|
|
"$call() should probably be ${call}_t($cast, $arg1, $arg2)\n" . "$here\n$stat\n");
|
|
}
|
|
}
|
|
|
|
# check usleep_range arguments
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
defined $stat &&
|
|
$stat =~ /^\+(?:.*?)\busleep_range\s*\(\s*($FuncArg)\s*,\s*($FuncArg)\s*\)/) {
|
|
my $min = $1;
|
|
my $max = $7;
|
|
if ($min eq $max) {
|
|
WARN("USLEEP_RANGE",
|
|
"usleep_range should not use min == max args; see Documentation/timers/timers-howto.txt\n" . "$here\n$stat\n");
|
|
} elsif ($min =~ /^\d+$/ && $max =~ /^\d+$/ &&
|
|
$min > $max) {
|
|
WARN("USLEEP_RANGE",
|
|
"usleep_range args reversed, use min then max; see Documentation/timers/timers-howto.txt\n" . "$here\n$stat\n");
|
|
}
|
|
}
|
|
|
|
# check for naked sscanf
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
defined $stat &&
|
|
$line =~ /\bsscanf\b/ &&
|
|
($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ &&
|
|
$stat !~ /\bsscanf\s*$balanced_parens\s*(?:$Compare)/ &&
|
|
$stat !~ /(?:$Compare)\s*\bsscanf\s*$balanced_parens/)) {
|
|
my $lc = $stat =~ tr@\n@@;
|
|
$lc = $lc + $linenr;
|
|
my $stat_real = raw_line($linenr, 0);
|
|
for (my $count = $linenr + 1; $count <= $lc; $count++) {
|
|
$stat_real = $stat_real . "\n" . raw_line($count, 0);
|
|
}
|
|
WARN("NAKED_SSCANF",
|
|
"unchecked sscanf return value\n" . "$here\n$stat_real\n");
|
|
}
|
|
|
|
# check for simple sscanf that should be kstrto<foo>
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
defined $stat &&
|
|
$line =~ /\bsscanf\b/) {
|
|
my $lc = $stat =~ tr@\n@@;
|
|
$lc = $lc + $linenr;
|
|
my $stat_real = raw_line($linenr, 0);
|
|
for (my $count = $linenr + 1; $count <= $lc; $count++) {
|
|
$stat_real = $stat_real . "\n" . raw_line($count, 0);
|
|
}
|
|
if ($stat_real =~ /\bsscanf\b\s*\(\s*$FuncArg\s*,\s*("[^"]+")/) {
|
|
my $format = $6;
|
|
my $count = $format =~ tr@%@%@;
|
|
if ($count == 1 &&
|
|
$format =~ /^"\%(?i:ll[udxi]|[udxi]ll|ll|[hl]h?[udxi]|[udxi][hl]h?|[hl]h?|[udxi])"$/) {
|
|
WARN("SSCANF_TO_KSTRTO",
|
|
"Prefer kstrto<type> to single variable sscanf\n" . "$here\n$stat_real\n");
|
|
}
|
|
}
|
|
}
|
|
|
|
# check for new externs in .h files.
|
|
if ($realfile =~ /\.h$/ &&
|
|
$line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) {
|
|
if (CHK("AVOID_EXTERNS",
|
|
"extern prototypes should be avoided in .h files\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/(.*)\bextern\b\s*(.*)/$1$2/;
|
|
}
|
|
}
|
|
|
|
# check for new externs in .c files.
|
|
if ($realfile =~ /\.c$/ && defined $stat &&
|
|
$stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
|
|
{
|
|
my $function_name = $1;
|
|
my $paren_space = $2;
|
|
|
|
my $s = $stat;
|
|
if (defined $cond) {
|
|
substr($s, 0, length($cond), '');
|
|
}
|
|
if ($s =~ /^\s*;/ &&
|
|
$function_name ne 'uninitialized_var')
|
|
{
|
|
WARN("AVOID_EXTERNS",
|
|
"externs should be avoided in .c files\n" . $herecurr);
|
|
}
|
|
|
|
if ($paren_space =~ /\n/) {
|
|
WARN("FUNCTION_ARGUMENTS",
|
|
"arguments for function declarations should follow identifier\n" . $herecurr);
|
|
}
|
|
|
|
} elsif ($realfile =~ /\.c$/ && defined $stat &&
|
|
$stat =~ /^.\s*extern\s+/)
|
|
{
|
|
WARN("AVOID_EXTERNS",
|
|
"externs should be avoided in .c files\n" . $herecurr);
|
|
}
|
|
|
|
# checks for new __setup's
|
|
if ($rawline =~ /\b__setup\("([^"]*)"/) {
|
|
my $name = $1;
|
|
|
|
if (!grep(/$name/, @setup_docs)) {
|
|
CHK("UNDOCUMENTED_SETUP",
|
|
"__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
# check for pointless casting of kmalloc return
|
|
if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) {
|
|
WARN("UNNECESSARY_CASTS",
|
|
"unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
|
|
}
|
|
|
|
# alloc style
|
|
# p = alloc(sizeof(struct foo), ...) should be p = alloc(sizeof(*p), ...)
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
$line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*([kv][mz]alloc(?:_node)?)\s*\(\s*(sizeof\s*\(\s*struct\s+$Lval\s*\))/) {
|
|
CHK("ALLOC_SIZEOF_STRUCT",
|
|
"Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
|
|
}
|
|
|
|
# check for k[mz]alloc with multiplies that could be kmalloc_array/kcalloc
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
$line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) {
|
|
my $oldfunc = $3;
|
|
my $a1 = $4;
|
|
my $a2 = $10;
|
|
my $newfunc = "kmalloc_array";
|
|
$newfunc = "kcalloc" if ($oldfunc eq "kzalloc");
|
|
my $r1 = $a1;
|
|
my $r2 = $a2;
|
|
if ($a1 =~ /^sizeof\s*\S/) {
|
|
$r1 = $a2;
|
|
$r2 = $a1;
|
|
}
|
|
if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ &&
|
|
!($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) {
|
|
if (WARN("ALLOC_WITH_MULTIPLY",
|
|
"Prefer $newfunc over $oldfunc with multiply\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
# check for krealloc arg reuse
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
$line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*\1\s*,/) {
|
|
WARN("KREALLOC_ARG_REUSE",
|
|
"Reusing the krealloc arg is almost always a bug\n" . $herecurr);
|
|
}
|
|
|
|
# check for alloc argument mismatch
|
|
if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) {
|
|
WARN("ALLOC_ARRAY_ARGS",
|
|
"$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
|
|
}
|
|
|
|
# check for multiple semicolons
|
|
if ($line =~ /;\s*;\s*$/) {
|
|
if (WARN("ONE_SEMICOLON",
|
|
"Statements terminations use 1 semicolon\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/(\s*;\s*){2,}$/;/g;
|
|
}
|
|
}
|
|
|
|
# check for #defines like: 1 << <digit> that could be BIT(digit)
|
|
if ($line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) {
|
|
my $ull = "";
|
|
$ull = "_ULL" if (defined($1) && $1 =~ /ll/i);
|
|
if (CHK("BIT_MACRO",
|
|
"Prefer using the BIT$ull macro\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\(?\s*1\s*[ulUL]*\s*<<\s*(\d+|$Ident)\s*\)?/BIT${ull}($1)/;
|
|
}
|
|
}
|
|
|
|
# check for case / default statements not preceded by break/fallthrough/switch
|
|
if ($line =~ /^.\s*(?:case\s+(?:$Ident|$Constant)\s*|default):/) {
|
|
my $has_break = 0;
|
|
my $has_statement = 0;
|
|
my $count = 0;
|
|
my $prevline = $linenr;
|
|
while ($prevline > 1 && ($file || $count < 3) && !$has_break) {
|
|
$prevline--;
|
|
my $rline = $rawlines[$prevline - 1];
|
|
my $fline = $lines[$prevline - 1];
|
|
last if ($fline =~ /^\@\@/);
|
|
next if ($fline =~ /^\-/);
|
|
next if ($fline =~ /^.(?:\s*(?:case\s+(?:$Ident|$Constant)[\s$;]*|default):[\s$;]*)*$/);
|
|
$has_break = 1 if ($rline =~ /fall[\s_-]*(through|thru)/i);
|
|
next if ($fline =~ /^.[\s$;]*$/);
|
|
$has_statement = 1;
|
|
$count++;
|
|
$has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|return\b|goto\b|continue\b)/);
|
|
}
|
|
if (!$has_break && $has_statement) {
|
|
WARN("MISSING_BREAK",
|
|
"Possible switch case/default not preceeded by break or fallthrough comment\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
# check for switch/default statements without a break;
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
defined $stat &&
|
|
$stat =~ /^\+[$;\s]*(?:case[$;\s]+\w+[$;\s]*:[$;\s]*|)*[$;\s]*\bdefault[$;\s]*:[$;\s]*;/g) {
|
|
my $ctx = '';
|
|
my $herectx = $here . "\n";
|
|
my $cnt = statement_rawlines($stat);
|
|
for (my $n = 0; $n < $cnt; $n++) {
|
|
$herectx .= raw_line($linenr, $n) . "\n";
|
|
}
|
|
WARN("DEFAULT_NO_BREAK",
|
|
"switch default: should use break\n" . $herectx);
|
|
}
|
|
|
|
# check for return codes on error paths
|
|
if ($line =~ /\breturn\s+-\d+/) {
|
|
ERROR("NO_ERROR_CODE",
|
|
"illegal return value, please use an error code\n" . $herecurr);
|
|
}
|
|
|
|
# check for gcc specific __FUNCTION__
|
|
if ($line =~ /\b__FUNCTION__\b/) {
|
|
if (WARN("USE_FUNC",
|
|
"__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr) &&
|
|
$fix) {
|
|
$fixed[$fixlinenr] =~ s/\b__FUNCTION__\b/__func__/g;
|
|
}
|
|
}
|
|
|
|
# check for uses of __DATE__, __TIME__, __TIMESTAMP__
|
|
while ($line =~ /\b(__(?:DATE|TIME|TIMESTAMP)__)\b/g) {
|
|
ERROR("DATE_TIME",
|
|
"Use of the '$1' macro makes the build non-deterministic\n" . $herecurr);
|
|
}
|
|
|
|
# check for use of yield()
|
|
if ($line =~ /\byield\s*\(\s*\)/) {
|
|
WARN("YIELD",
|
|
"Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr);
|
|
}
|
|
|
|
# check for comparisons against true and false
|
|
if ($line =~ /\+\s*(.*?)\b(true|false|$Lval)\s*(==|\!=)\s*(true|false|$Lval)\b(.*)$/i) {
|
|
my $lead = $1;
|
|
my $arg = $2;
|
|
my $test = $3;
|
|
my $otype = $4;
|
|
my $trail = $5;
|
|
my $op = "!";
|
|
|
|
($arg, $otype) = ($otype, $arg) if ($arg =~ /^(?:true|false)$/i);
|
|
|
|
my $type = lc($otype);
|
|
if ($type =~ /^(?:true|false)$/) {
|
|
if (("$test" eq "==" && "$type" eq "true") ||
|
|
("$test" eq "!=" && "$type" eq "false")) {
|
|
$op = "";
|
|
}
|
|
|
|
CHK("BOOL_COMPARISON",
|
|
"Using comparison to $otype is error prone\n" . $herecurr);
|
|
|
|
## maybe suggesting a correct construct would better
|
|
## "Using comparison to $otype is error prone. Perhaps use '${lead}${op}${arg}${trail}'\n" . $herecurr);
|
|
|
|
}
|
|
}
|
|
|
|
# check for semaphores initialized locked
|
|
if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
|
|
WARN("CONSIDER_COMPLETION",
|
|
"consider using a completion\n" . $herecurr);
|
|
}
|
|
|
|
# recommend kstrto* over simple_strto* and strict_strto*
|
|
if ($line =~ /\b((simple|strict)_(strto(l|ll|ul|ull)))\s*\(/) {
|
|
WARN("CONSIDER_KSTRTO",
|
|
"$1 is obsolete, use k$3 instead\n" . $herecurr);
|
|
}
|
|
|
|
# check for __initcall(), use device_initcall() explicitly or more appropriate function please
|
|
if ($line =~ /^.\s*__initcall\s*\(/) {
|
|
WARN("USE_DEVICE_INITCALL",
|
|
"please use device_initcall() or more appropriate function instead of __initcall() (see include/linux/init.h)\n" . $herecurr);
|
|
}
|
|
|
|
# check for various structs that are normally const (ops, kgdb, device_tree)
|
|
my $const_structs = qr{
|
|
acpi_dock_ops|
|
|
address_space_operations|
|
|
backlight_ops|
|
|
block_device_operations|
|
|
dentry_operations|
|
|
dev_pm_ops|
|
|
dma_map_ops|
|
|
extent_io_ops|
|
|
file_lock_operations|
|
|
file_operations|
|
|
hv_ops|
|
|
ide_dma_ops|
|
|
intel_dvo_dev_ops|
|
|
item_operations|
|
|
iwl_ops|
|
|
kgdb_arch|
|
|
kgdb_io|
|
|
kset_uevent_ops|
|
|
lock_manager_operations|
|
|
microcode_ops|
|
|
mtrr_ops|
|
|
neigh_ops|
|
|
nlmsvc_binding|
|
|
of_device_id|
|
|
pci_raw_ops|
|
|
pipe_buf_operations|
|
|
platform_hibernation_ops|
|
|
platform_suspend_ops|
|
|
proto_ops|
|
|
rpc_pipe_ops|
|
|
seq_operations|
|
|
snd_ac97_build_ops|
|
|
soc_pcmcia_socket_ops|
|
|
stacktrace_ops|
|
|
sysfs_ops|
|
|
tty_operations|
|
|
uart_ops|
|
|
usb_mon_operations|
|
|
wd_ops}x;
|
|
if ($line !~ /\bconst\b/ &&
|
|
$line =~ /\bstruct\s+($const_structs)\b/) {
|
|
WARN("CONST_STRUCT",
|
|
"struct $1 should normally be const\n" .
|
|
$herecurr);
|
|
}
|
|
|
|
# use of NR_CPUS is usually wrong
|
|
# ignore definitions of NR_CPUS and usage to define arrays as likely right
|
|
if ($line =~ /\bNR_CPUS\b/ &&
|
|
$line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ &&
|
|
$line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ &&
|
|
$line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ &&
|
|
$line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ &&
|
|
$line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/)
|
|
{
|
|
WARN("NR_CPUS",
|
|
"usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);
|
|
}
|
|
|
|
# Use of __ARCH_HAS_<FOO> or ARCH_HAVE_<BAR> is wrong.
|
|
if ($line =~ /\+\s*#\s*define\s+((?:__)?ARCH_(?:HAS|HAVE)\w*)\b/) {
|
|
ERROR("DEFINE_ARCH_HAS",
|
|
"#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr);
|
|
}
|
|
|
|
# likely/unlikely comparisons similar to "(likely(foo) > 0)"
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
$line =~ /\b((?:un)?likely)\s*\(\s*$FuncArg\s*\)\s*$Compare/) {
|
|
WARN("LIKELY_MISUSE",
|
|
"Using $1 should generally have parentheses around the comparison\n" . $herecurr);
|
|
}
|
|
|
|
# whine mightly about in_atomic
|
|
if ($line =~ /\bin_atomic\s*\(/) {
|
|
if ($realfile =~ m@^drivers/@) {
|
|
ERROR("IN_ATOMIC",
|
|
"do not use in_atomic in drivers\n" . $herecurr);
|
|
} elsif ($realfile !~ m@^kernel/@) {
|
|
WARN("IN_ATOMIC",
|
|
"use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
# check for lockdep_set_novalidate_class
|
|
if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
|
|
$line =~ /__lockdep_no_validate__\s*\)/ ) {
|
|
if ($realfile !~ m@^kernel/lockdep@ &&
|
|
$realfile !~ m@^include/linux/lockdep@ &&
|
|
$realfile !~ m@^drivers/base/core@) {
|
|
ERROR("LOCKDEP",
|
|
"lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
|
|
}
|
|
}
|
|
|
|
if ($line =~ /debugfs_create_\w+.*\b$mode_perms_world_writable\b/ ||
|
|
$line =~ /DEVICE_ATTR.*\b$mode_perms_world_writable\b/) {
|
|
WARN("EXPORTED_WORLD_WRITABLE",
|
|
"Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
|
|
}
|
|
|
|
# Mode permission misuses where it seems decimal should be octal
|
|
# This uses a shortcut match to avoid unnecessary uses of a slow foreach loop
|
|
if ($^V && $^V ge 5.10.0 &&
|
|
$line =~ /$mode_perms_search/) {
|
|
foreach my $entry (@mode_permission_funcs) {
|
|
my $func = $entry->[0];
|
|
my $arg_pos = $entry->[1];
|
|
|
|
my $skip_args = "";
|
|
if ($arg_pos > 1) {
|
|
$arg_pos--;
|
|
$skip_args = "(?:\\s*$FuncArg\\s*,\\s*){$arg_pos,$arg_pos}";
|
|
}
|
|
my $test = "\\b$func\\s*\\(${skip_args}([\\d]+)\\s*[,\\)]";
|
|
if ($line =~ /$test/) {
|
|
my $val = $1;
|
|
$val = $6 if ($skip_args ne "");
|
|
|
|
if ($val !~ /^0$/ &&
|
|
(($val =~ /^$Int$/ && $val !~ /^$Octal$/) ||
|
|
length($val) ne 4)) {
|
|
ERROR("NON_OCTAL_PERMISSIONS",
|
|
"Use 4 digit octal (0777) not decimal permissions\n" . $herecurr);
|
|
} elsif ($val =~ /^$Octal$/ && (oct($val) & 02)) {
|
|
ERROR("EXPORTED_WORLD_WRITABLE",
|
|
"Exporting writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
# validate content of MODULE_LICENSE against list from include/linux/module.h
|
|
if ($line =~ /\bMODULE_LICENSE\s*\(\s*($String)\s*\)/) {
|
|
my $extracted_string = get_quoted_string($line, $rawline);
|
|
my $valid_licenses = qr{
|
|
GPL|
|
|
GPL\ v2|
|
|
GPL\ and\ additional\ rights|
|
|
Dual\ BSD/GPL|
|
|
Dual\ MIT/GPL|
|
|
Dual\ MPL/GPL|
|
|
Proprietary
|
|
}x;
|
|
if ($extracted_string !~ /^"(?:$valid_licenses)"$/x) {
|
|
WARN("MODULE_LICENSE",
|
|
"unknown module license " . $extracted_string . "\n" . $herecurr);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($chk_author && $qca_sign_off && !$codeaurora_sign_off) {
|
|
WARN("BAD_SIGN_OFF",
|
|
"QCA Signed-off-by requires CODEAURORA Signed-off-by\n" . $line );
|
|
}
|
|
|
|
# If we have no input at all, then there is nothing to report on
|
|
# so just keep quiet.
|
|
if ($#rawlines == -1) {
|
|
exit(0);
|
|
}
|
|
|
|
# In mailback mode only produce a report in the negative, for
|
|
# things that appear to be patches.
|
|
if ($mailback && ($clean == 1 || !$is_patch)) {
|
|
exit(0);
|
|
}
|
|
|
|
# This is not a patch, and we are are in 'no-patch' mode so
|
|
# just keep quiet.
|
|
if (!$chk_patch && !$is_patch) {
|
|
exit(0);
|
|
}
|
|
|
|
if (!$is_patch && $file !~ /cover-letter\.patch$/) {
|
|
ERROR("NOT_UNIFIED_DIFF",
|
|
"Does not appear to be a unified-diff format patch\n");
|
|
}
|
|
if ($is_patch && $filename ne '-' && $chk_signoff && $signoff == 0) {
|
|
ERROR("MISSING_SIGN_OFF",
|
|
"Missing Signed-off-by: line(s)\n");
|
|
}
|
|
|
|
print report_dump();
|
|
if ($summary && !($clean == 1 && $quiet == 1)) {
|
|
print "$filename " if ($summary_file);
|
|
print "total: $cnt_error errors, $cnt_warn warnings, " .
|
|
(($check)? "$cnt_chk checks, " : "") .
|
|
"$cnt_lines lines checked\n";
|
|
}
|
|
|
|
if ($quiet == 0) {
|
|
# If there were whitespace errors which cleanpatch can fix
|
|
# then suggest that.
|
|
if ($rpt_cleaners) {
|
|
$rpt_cleaners = 0;
|
|
print << "EOM"
|
|
|
|
NOTE: Whitespace errors detected.
|
|
You may wish to use scripts/cleanpatch or scripts/cleanfile
|
|
EOM
|
|
}
|
|
}
|
|
|
|
if ($clean == 0 && $fix &&
|
|
("@rawlines" ne "@fixed" ||
|
|
$#fixed_inserted >= 0 || $#fixed_deleted >= 0)) {
|
|
my $newfile = $filename;
|
|
$newfile .= ".EXPERIMENTAL-checkpatch-fixes" if (!$fix_inplace);
|
|
my $linecount = 0;
|
|
my $f;
|
|
|
|
@fixed = fix_inserted_deleted_lines(\@fixed, \@fixed_inserted, \@fixed_deleted);
|
|
|
|
open($f, '>', $newfile)
|
|
or die "$P: Can't open $newfile for write\n";
|
|
foreach my $fixed_line (@fixed) {
|
|
$linecount++;
|
|
if ($file) {
|
|
if ($linecount > 3) {
|
|
$fixed_line =~ s/^\+//;
|
|
print $f $fixed_line . "\n";
|
|
}
|
|
} else {
|
|
print $f $fixed_line . "\n";
|
|
}
|
|
}
|
|
close($f);
|
|
|
|
if (!$quiet) {
|
|
print << "EOM";
|
|
|
|
Wrote EXPERIMENTAL --fix correction(s) to '$newfile'
|
|
|
|
Do _NOT_ trust the results written to this file.
|
|
Do _NOT_ submit these changes without inspecting them for correctness.
|
|
|
|
This EXPERIMENTAL file is simply a convenience to help rewrite patches.
|
|
No warranties, expressed or implied...
|
|
EOM
|
|
}
|
|
}
|
|
|
|
if ($quiet == 0) {
|
|
print "\n";
|
|
if ($clean == 1) {
|
|
print "$vname has no obvious style problems and is ready for submission.\n";
|
|
} else {
|
|
print "$vname has style problems, please review.\n";
|
|
}
|
|
}
|
|
return $clean;
|
|
}
|