#! /usr/bin/env bash
# Copyright (c) 2016 - 2019 DisplayLink (UK) Ltd.

set -e
set -u

files=(
  checkpatch.pl
  const_structs.checkpatch
  spelling.txt
)

KVER=master

for file in "${files[@]}"; do
  wget -N -q "https://raw.githubusercontent.com/torvalds/linux/${KVER}/scripts/${file}"
done

chmod +x checkpatch.pl

set +e

result=0
./checkpatch.pl --terse --no-tree --ignore NEW_TYPEDEFS -f ./library/*
result=$((result || $?))

find ./module -type f -exec ./checkpatch.pl --terse --no-tree --ignore LINUX_VERSION_CODE,PREFER_PR_LEVEL -f {} \;
result=$((result || $?))

rm "${files[@]}"

exit ${result}
