diff --git a/.github/workflows/driver-cross-build.yml b/.github/workflows/driver-cross-build.yml index 9792e2a..0d1d949 100644 --- a/.github/workflows/driver-cross-build.yml +++ b/.github/workflows/driver-cross-build.yml @@ -5,16 +5,33 @@ on: branches: - master paths: + - '.github/workflows/driver-cross-build.yml' + - '.test/bin/**' + - '.test/lint.sh' - 'src/drivers/**' - - '.github/workflows/**' pull_request: types: [opened, synchronize] paths: + - '.github/workflows/driver-cross-build.yml' + - '.test/bin/**' + - '.test/lint.sh' - 'src/drivers/**' - - '.github/workflows/**' jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Lint + run: | + ./.test/lint.sh build: + needs: lint strategy: fail-fast: false matrix: diff --git a/.test/bin/run-clang-format.py b/.test/bin/run-clang-format.py new file mode 100644 index 0000000..5c76b36 --- /dev/null +++ b/.test/bin/run-clang-format.py @@ -0,0 +1,432 @@ +#!/usr/bin/env python + +"""A wrapper script around clang-format, suitable for linting multiple files +and to use for continuous integration. + +This is an alternative API for the clang-format command line. +It runs over multiple files and directories in parallel. +A diff output is produced and a sensible exit code is returned. + +# https://github.com/Sarcasm/run-clang-format/blob/39081c9c42768ab5e8321127a7494ad1647c6a2f/run-clang-format.py + +MIT License + +Copyright (c) 2017 Guillaume Papin + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +""" + +from __future__ import print_function, unicode_literals + +import argparse +import codecs +import difflib +import fnmatch +import io +import errno +import multiprocessing +import os +import signal +import subprocess +import sys +import traceback + +from functools import partial + +try: + from subprocess import DEVNULL # py3k +except ImportError: + DEVNULL = open(os.devnull, "wb") + + +DEFAULT_EXTENSIONS = 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx' +DEFAULT_CLANG_FORMAT_IGNORE = '.clang-format-ignore' + + +class ExitStatus: + SUCCESS = 0 + DIFF = 1 + TROUBLE = 2 + +def excludes_from_file(ignore_file): + excludes = [] + try: + with io.open(ignore_file, 'r', encoding='utf-8') as f: + for line in f: + if line.startswith('#'): + # ignore comments + continue + pattern = line.rstrip() + if not pattern: + # allow empty lines + continue + excludes.append(pattern) + except EnvironmentError as e: + if e.errno != errno.ENOENT: + raise + return excludes; + +def list_files(files, recursive=False, extensions=None, exclude=None): + if extensions is None: + extensions = [] + if exclude is None: + exclude = [] + + out = [] + for file in files: + if recursive and os.path.isdir(file): + for dirpath, dnames, fnames in os.walk(file): + fpaths = [os.path.join(dirpath, fname) for fname in fnames] + for pattern in exclude: + # os.walk() supports trimming down the dnames list + # by modifying it in-place, + # to avoid unnecessary directory listings. + dnames[:] = [ + x for x in dnames + if + not fnmatch.fnmatch(os.path.join(dirpath, x), pattern) + ] + fpaths = [ + x for x in fpaths if not fnmatch.fnmatch(x, pattern) + ] + for f in fpaths: + ext = os.path.splitext(f)[1][1:] + if ext in extensions: + out.append(f) + else: + out.append(file) + return out + + +def make_diff(file, original, reformatted): + return list( + difflib.unified_diff( + original, + reformatted, + fromfile='{}\t(original)'.format(file), + tofile='{}\t(reformatted)'.format(file), + n=3)) + + +class DiffError(Exception): + def __init__(self, message, errs=None): + super(DiffError, self).__init__(message) + self.errs = errs or [] + + +class UnexpectedError(Exception): + def __init__(self, message, exc=None): + super(UnexpectedError, self).__init__(message) + self.formatted_traceback = traceback.format_exc() + self.exc = exc + + +def run_clang_format_diff_wrapper(args, file): + try: + ret = run_clang_format_diff(args, file) + return ret + except DiffError: + raise + except Exception as e: + raise UnexpectedError('{}: {}: {}'.format(file, e.__class__.__name__, + e), e) + + +def run_clang_format_diff(args, file): + try: + with io.open(file, 'r', encoding='utf-8') as f: + original = f.readlines() + except IOError as exc: + raise DiffError(str(exc)) + + if args.in_place: + invocation = [args.clang_format_executable, '-i', file] + else: + invocation = [args.clang_format_executable, file] + + if args.style: + invocation.extend(['--style', args.style]) + + if args.dry_run: + print(" ".join(invocation)) + return [], [] + + # Use of utf-8 to decode the process output. + # + # Hopefully, this is the correct thing to do. + # + # It's done due to the following assumptions (which may be incorrect): + # - clang-format will returns the bytes read from the files as-is, + # without conversion, and it is already assumed that the files use utf-8. + # - if the diagnostics were internationalized, they would use utf-8: + # > Adding Translations to Clang + # > + # > Not possible yet! + # > Diagnostic strings should be written in UTF-8, + # > the client can translate to the relevant code page if needed. + # > Each translation completely replaces the format string + # > for the diagnostic. + # > -- http://clang.llvm.org/docs/InternalsManual.html#internals-diag-translation + # + # It's not pretty, due to Python 2 & 3 compatibility. + encoding_py3 = {} + if sys.version_info[0] >= 3: + encoding_py3['encoding'] = 'utf-8' + + try: + proc = subprocess.Popen( + invocation, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + **encoding_py3) + except OSError as exc: + raise DiffError( + "Command '{}' failed to start: {}".format( + subprocess.list2cmdline(invocation), exc + ) + ) + proc_stdout = proc.stdout + proc_stderr = proc.stderr + if sys.version_info[0] < 3: + # make the pipes compatible with Python 3, + # reading lines should output unicode + encoding = 'utf-8' + proc_stdout = codecs.getreader(encoding)(proc_stdout) + proc_stderr = codecs.getreader(encoding)(proc_stderr) + # hopefully the stderr pipe won't get full and block the process + outs = list(proc_stdout.readlines()) + errs = list(proc_stderr.readlines()) + proc.wait() + if proc.returncode: + raise DiffError( + "Command '{}' returned non-zero exit status {}".format( + subprocess.list2cmdline(invocation), proc.returncode + ), + errs, + ) + if args.in_place: + return [], errs + return make_diff(file, original, outs), errs + + +def bold_red(s): + return '\x1b[1m\x1b[31m' + s + '\x1b[0m' + + +def colorize(diff_lines): + def bold(s): + return '\x1b[1m' + s + '\x1b[0m' + + def cyan(s): + return '\x1b[36m' + s + '\x1b[0m' + + def green(s): + return '\x1b[32m' + s + '\x1b[0m' + + def red(s): + return '\x1b[31m' + s + '\x1b[0m' + + for line in diff_lines: + if line[:4] in ['--- ', '+++ ']: + yield bold(line) + elif line.startswith('@@ '): + yield cyan(line) + elif line.startswith('+'): + yield green(line) + elif line.startswith('-'): + yield red(line) + else: + yield line + + +def print_diff(diff_lines, use_color): + if use_color: + diff_lines = colorize(diff_lines) + if sys.version_info[0] < 3: + sys.stdout.writelines((l.encode('utf-8') for l in diff_lines)) + else: + sys.stdout.writelines(diff_lines) + + +def print_trouble(prog, message, use_colors): + error_text = 'error:' + if use_colors: + error_text = bold_red(error_text) + print("{}: {} {}".format(prog, error_text, message), file=sys.stderr) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + '--clang-format-executable', + metavar='EXECUTABLE', + help='path to the clang-format executable', + default='clang-format') + parser.add_argument( + '--extensions', + help='comma separated list of file extensions (default: {})'.format( + DEFAULT_EXTENSIONS), + default=DEFAULT_EXTENSIONS) + parser.add_argument( + '-r', + '--recursive', + action='store_true', + help='run recursively over directories') + parser.add_argument( + '-d', + '--dry-run', + action='store_true', + help='just print the list of files') + parser.add_argument( + '-i', + '--in-place', + action='store_true', + help='format file instead of printing differences') + parser.add_argument('files', metavar='file', nargs='+') + parser.add_argument( + '-q', + '--quiet', + action='store_true', + help="disable output, useful for the exit code") + parser.add_argument( + '-j', + metavar='N', + type=int, + default=0, + help='run N clang-format jobs in parallel' + ' (default number of cpus + 1)') + parser.add_argument( + '--color', + default='auto', + choices=['auto', 'always', 'never'], + help='show colored diff (default: auto)') + parser.add_argument( + '-e', + '--exclude', + metavar='PATTERN', + action='append', + default=[], + help='exclude paths matching the given glob-like pattern(s)' + ' from recursive search') + parser.add_argument( + '--style', + help='formatting style to apply (LLVM, Google, Chromium, Mozilla, WebKit)') + + args = parser.parse_args() + + # use default signal handling, like diff return SIGINT value on ^C + # https://bugs.python.org/issue14229#msg156446 + signal.signal(signal.SIGINT, signal.SIG_DFL) + try: + signal.SIGPIPE + except AttributeError: + # compatibility, SIGPIPE does not exist on Windows + pass + else: + signal.signal(signal.SIGPIPE, signal.SIG_DFL) + + colored_stdout = False + colored_stderr = False + if args.color == 'always': + colored_stdout = True + colored_stderr = True + elif args.color == 'auto': + colored_stdout = sys.stdout.isatty() + colored_stderr = sys.stderr.isatty() + + version_invocation = [args.clang_format_executable, str("--version")] + try: + subprocess.check_call(version_invocation, stdout=DEVNULL) + except subprocess.CalledProcessError as e: + print_trouble(parser.prog, str(e), use_colors=colored_stderr) + return ExitStatus.TROUBLE + except OSError as e: + print_trouble( + parser.prog, + "Command '{}' failed to start: {}".format( + subprocess.list2cmdline(version_invocation), e + ), + use_colors=colored_stderr, + ) + return ExitStatus.TROUBLE + + retcode = ExitStatus.SUCCESS + + excludes = excludes_from_file(DEFAULT_CLANG_FORMAT_IGNORE) + excludes.extend(args.exclude) + + files = list_files( + args.files, + recursive=args.recursive, + exclude=excludes, + extensions=args.extensions.split(',')) + + if not files: + return + + njobs = args.j + if njobs == 0: + njobs = multiprocessing.cpu_count() + 1 + njobs = min(len(files), njobs) + + if njobs == 1: + # execute directly instead of in a pool, + # less overhead, simpler stacktraces + it = (run_clang_format_diff_wrapper(args, file) for file in files) + pool = None + else: + pool = multiprocessing.Pool(njobs) + it = pool.imap_unordered( + partial(run_clang_format_diff_wrapper, args), files) + pool.close() + while True: + try: + outs, errs = next(it) + except StopIteration: + break + except DiffError as e: + print_trouble(parser.prog, str(e), use_colors=colored_stderr) + retcode = ExitStatus.TROUBLE + sys.stderr.writelines(e.errs) + except UnexpectedError as e: + print_trouble(parser.prog, str(e), use_colors=colored_stderr) + sys.stderr.write(e.formatted_traceback) + retcode = ExitStatus.TROUBLE + # stop at the first unexpected error, + # something could be very wrong, + # don't process all files unnecessarily + if pool: + pool.terminate() + break + else: + sys.stderr.writelines(errs) + if outs == []: + continue + if not args.quiet: + print_diff(outs, use_color=colored_stdout) + if retcode == ExitStatus.SUCCESS: + retcode = ExitStatus.DIFF + if pool: + pool.join() + return retcode + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/.test/lint.sh b/.test/lint.sh new file mode 100755 index 0000000..5ae2bd1 --- /dev/null +++ b/.test/lint.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -eu + +SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0}); cd ../; pwd) + + +lint_driver () { + pushd $SRC_DIR/src/drivers + python3 $SRC_DIR/.test/bin/run-clang-format.py rtmouse.c + popd +} + +check_driver_version () { + MOD_VER=$(grep MODULE_VERSION $SRC_DIR/src/drivers/rtmouse.c | sed -E 's/MODULE_VERSION\("([0-9.]*)"\);/\1/g') + COMMENT_VER=$(grep '* Version' $SRC_DIR/src/drivers/rtmouse.c | sed -E 's/.*Version: ([0-9.]*)/\1/g') + if [[ "$MOD_VER" != "$COMMENT_VER" ]]; then + echo "The versions do not match." + echo "Module Version: "$MOD_VER + echo "Comment Version: "$COMMENT_VER + exit 1 + else + echo "Module Version and Comment Version matched." + fi +} + + +lint_driver +check_driver_version \ No newline at end of file diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index 4463461..db5867e 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -10,12 +10,12 @@ * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, @@ -253,7 +253,6 @@ static struct mutex lock; #define RPI_PWM_RNG2 0x20 #define RPI_PWM_DAT2 0x24 - #if RASPBERRYPI == 4 #define PWM_BASECLK 27000000 #else @@ -299,7 +298,8 @@ struct mcp3204_drvdata { /* --- Static variables --- */ /* SPI device ID */ static struct spi_device_id mcp3204_id[] = { - {"mcp3204", 0}, {}, + {"mcp3204", 0}, + {}, }; /* SPI Info */ @@ -315,7 +315,8 @@ static struct spi_board_info mcp3204_info = { static struct spi_driver mcp3204_driver = { .driver = { - .name = DEVNAME_SENSOR, .owner = THIS_MODULE, + .name = DEVNAME_SENSOR, + .owner = THIS_MODULE, }, .id_table = mcp3204_id, .probe = mcp3204_probe, @@ -343,19 +344,21 @@ static unsigned int motor_r_freq_is_positive = 1; /* I2C Device ID */ static struct i2c_device_id i2c_counter_id[] = { - {DEVNAME_CNTL, 0}, {DEVNAME_CNTR, 1}, {}, + {DEVNAME_CNTL, 0}, + {DEVNAME_CNTR, 1}, + {}, }; /* I2C Dirver Info */ static struct i2c_driver i2c_counter_driver = { - .driver = + .driver = { - .name = "rtcounter", - .owner = THIS_MODULE, + .name = "rtcounter", + .owner = THIS_MODULE, }, - .id_table = i2c_counter_id, - .probe = rtcnt_i2c_probe, - .remove = rtcnt_i2c_remove, + .id_table = i2c_counter_id, + .probe = rtcnt_i2c_probe, + .remove = rtcnt_i2c_remove, }; /* -- Device Addition -- */ @@ -747,7 +750,8 @@ static int buzzer_init(void) udelay(1000); rpi_pwm_write32(RPI_PWM_CTRL, 0x00008181); // PWM1,2 enable - // printk(KERN_DEBUG "%s: rpi_pwm_ctrl:%08X\n", DRIVER_NAME, ioread32(pwm_base + RPI_PWM_CTRL)); + // printk(KERN_DEBUG "%s: rpi_pwm_ctrl:%08X\n", DRIVER_NAME, + // ioread32(pwm_base + RPI_PWM_CTRL)); return 0; } @@ -851,7 +855,7 @@ static int i2c_dev_open(struct inode *inode, struct file *filep) if (dev_info == NULL || dev_info->client == NULL) { printk(KERN_ERR "%s: i2c dev_open failed.\n", DRIVER_NAME); } - dev_info->device_minor = MINOR(inode->i_rdev); + dev_info->device_minor = MINOR(inode->i_rdev); filep->private_data = dev_info; return 0; } @@ -891,7 +895,6 @@ static int parseMotorCmd(const char __user *buf, size_t count, int *ret) return count; } - /* * led_write - Trun ON/OFF LEDs * Write function of /dev/rtled @@ -1114,8 +1117,7 @@ static int i2c_counter_read(struct rtcnt_device_info *dev_info, int *ret) * update_signed_count - update signed pulse count of dev_info * called by rtcnt_read() */ -void update_signed_count(struct rtcnt_device_info *dev_info, - int rtcnt_count) +void update_signed_count(struct rtcnt_device_info *dev_info, int rtcnt_count) { int diff_count = rtcnt_count - dev_info->raw_pulse_count; @@ -1123,26 +1125,26 @@ void update_signed_count(struct rtcnt_device_info *dev_info, // ただし、それ以外でもdiffが負の値になることがある // そのため、diffが十分に大きな負の値の場合に処理する // if(diff_count < 0) では正常に動作しない - if(diff_count < -SIGNED_COUNT_SIZE){ + if (diff_count < -SIGNED_COUNT_SIZE) { diff_count += MAX_PULSE_COUNT; } - if(dev_info->client->addr == DEV_ADDR_CNTL){ - if(motor_l_freq_is_positive){ + if (dev_info->client->addr == DEV_ADDR_CNTL) { + if (motor_l_freq_is_positive) { dev_info->signed_pulse_count += diff_count; - }else{ + } else { dev_info->signed_pulse_count -= diff_count; } - }else{ - if(motor_r_freq_is_positive){ + } else { + if (motor_r_freq_is_positive) { dev_info->signed_pulse_count += diff_count; - }else{ + } else { dev_info->signed_pulse_count -= diff_count; } } - if(dev_info->signed_pulse_count > SIGNED_COUNT_SIZE || - dev_info->signed_pulse_count < -SIGNED_COUNT_SIZE){ + if (dev_info->signed_pulse_count > SIGNED_COUNT_SIZE || + dev_info->signed_pulse_count < -SIGNED_COUNT_SIZE) { dev_info->signed_pulse_count = 0; } } @@ -1151,14 +1153,13 @@ void update_signed_count(struct rtcnt_device_info *dev_info, * reset_signed_count - reset signed pulse count of dev_info * called by rtcnt_write() */ -void reset_signed_count(struct rtcnt_device_info *dev_info, - int rtcnt_count) +void reset_signed_count(struct rtcnt_device_info *dev_info, int rtcnt_count) { int raw_count; - if(rtcnt_count > SIGNED_COUNT_SIZE){ + if (rtcnt_count > SIGNED_COUNT_SIZE) { rtcnt_count = SIGNED_COUNT_SIZE; - }else if(rtcnt_count < - SIGNED_COUNT_SIZE){ + } else if (rtcnt_count < -SIGNED_COUNT_SIZE) { rtcnt_count = -SIGNED_COUNT_SIZE; } dev_info->signed_pulse_count = rtcnt_count; @@ -1183,11 +1184,11 @@ static ssize_t rtcnt_read(struct file *filep, char __user *buf, size_t count, return 0; /* close device */ i2c_counter_read(dev_info, &rtcnt_count); - if(dev_info->device_minor == 1){ + if (dev_info->device_minor == 1) { update_signed_count(dev_info, rtcnt_count); dev_info->raw_pulse_count = rtcnt_count; rtcnt_count = dev_info->signed_pulse_count; - }else{ + } else { dev_info->raw_pulse_count = rtcnt_count; } @@ -1228,7 +1229,7 @@ static ssize_t rtcnt_write(struct file *filep, const char __user *buf, i2c_counter_set(dev_info, rtcnt_count); - if(dev_info->device_minor == 1){ + if (dev_info->device_minor == 1) { reset_signed_count(dev_info, rtcnt_count); } @@ -1240,35 +1241,51 @@ static ssize_t rtcnt_write(struct file *filep, const char __user *buf, /* --- Device File Operations --- */ /* /dev/rtled */ static struct file_operations led_fops = { - .open = dev_open, .release = dev_release, .write = led_write, + .open = dev_open, + .release = dev_release, + .write = led_write, }; /* /dev/rtbuzzer */ static struct file_operations buzzer_fops = { - .open = dev_open, .release = dev_release, .write = buzzer_write, + .open = dev_open, + .release = dev_release, + .write = buzzer_write, }; /* /dev/rtswitch */ static struct file_operations sw_fops = { - .open = dev_open, .read = sw_read, .release = dev_release, + .open = dev_open, + .read = sw_read, + .release = dev_release, }; /* /dev/rtlightsensor */ static struct file_operations sensor_fops = { - .open = dev_open, .read = sensor_read, .release = dev_release, + .open = dev_open, + .read = sensor_read, + .release = dev_release, }; /* /dev/rtmotor_raw_r */ static struct file_operations motorrawr_fops = { - .open = dev_open, .write = rawmotor_r_write, .release = dev_release, + .open = dev_open, + .write = rawmotor_r_write, + .release = dev_release, }; /* /dev/rtmotor_raw_l */ static struct file_operations motorrawl_fops = { - .open = dev_open, .write = rawmotor_l_write, .release = dev_release, + .open = dev_open, + .write = rawmotor_l_write, + .release = dev_release, }; /* /dev/rtmotoren */ static struct file_operations motoren_fops = { - .open = dev_open, .write = motoren_write, .release = dev_release, + .open = dev_open, + .write = motoren_write, + .release = dev_release, }; /* /dev/rtmotor */ static struct file_operations motor_fops = { - .open = dev_open, .write = motor_write, .release = dev_release, + .open = dev_open, + .write = motor_write, + .release = dev_release, }; /* /dev/rtcounter_* */ static struct file_operations rtcnt_fops = { @@ -1293,7 +1310,7 @@ static int led_register_dev(void) DEV_MINOR, /* ベースマイナー番号 */ NUM_DEV_LED, /* デバイスの数 */ DEVNAME_LED /* デバイスドライバの名前 */ - ); + ); if (retval < 0) { printk(KERN_ERR "alloc_chrdev_region failed.\n"); @@ -1342,7 +1359,7 @@ static int buzzer_register_dev(void) DEV_MINOR, /* ベースマイナー番号 */ NUM_DEV_BUZZER, /* デバイスの数 */ DEVNAME_BUZZER /* デバイスドライバの名前 */ - ); + ); if (retval < 0) { printk(KERN_ERR "alloc_chrdev_region failed.\n"); @@ -1388,7 +1405,7 @@ static int motorrawr_register_dev(void) DEV_MINOR, /* ベースマイナー番号 */ NUM_DEV_MOTORRAWR, /* デバイスの数 */ DEVNAME_MOTORRAWR /* デバイスドライバの名前 */ - ); + ); if (retval < 0) { printk(KERN_ERR "alloc_chrdev_region failed.\n"); @@ -1436,7 +1453,7 @@ static int motorrawl_register_dev(void) DEV_MINOR, /* ベースマイナー番号 */ NUM_DEV_MOTORRAWL, /* デバイスの数 */ DEVNAME_MOTORRAWL /* デバイスドライバの名前 */ - ); + ); if (retval < 0) { printk(KERN_ERR "alloc_chrdev_region failed.\n"); @@ -1483,7 +1500,7 @@ static int switch_register_dev(void) DEV_MINOR, /* ベースマイナー番号 */ NUM_DEV_SWITCH, /* デバイスの数 */ DEVNAME_SWITCH /* デバイスドライバの名前 */ - ); + ); if (retval < 0) { printk(KERN_ERR "alloc_chrdev_region failed.\n"); @@ -1532,7 +1549,7 @@ static int sensor_register_dev(void) DEV_MINOR, /* ベースマイナー番号 */ NUM_DEV_SENSOR, /* デバイスの数 */ DEVNAME_SENSOR /* デバイスドライバの名前 */ - ); + ); if (retval < 0) { printk(KERN_ERR "alloc_chrdev_region failed.\n"); @@ -1578,7 +1595,7 @@ static int motoren_register_dev(void) DEV_MINOR, /* ベースマイナー番号 */ NUM_DEV_MOTOREN, /* デバイスの数 */ DEVNAME_MOTOREN /* デバイスドライバの名前 */ - ); + ); if (retval < 0) { printk(KERN_ERR "alloc_chrdev_region failed.\n"); @@ -1623,7 +1640,7 @@ static int motor_register_dev(void) DEV_MINOR, /* ベースマイナー番号 */ NUM_DEV_MOTOR, /* デバイスの数 */ DEVNAME_MOTOR /* デバイスドライバの名前 */ - ); + ); if (retval < 0) { printk(KERN_ERR "alloc_chrdev_region failed.\n"); @@ -1846,7 +1863,7 @@ static int rtcntr_i2c_create_cdev(struct rtcnt_device_info *dev_info) } /* 取得したdev( = メジャー番号 + マイナー番号) - * からメジャー番号を取得して保持しておく */ + * からメジャー番号を取得して保持しておく */ dev_info->device_major = MAJOR(dev); dev = MKDEV(dev_info->device_major, DEV_MINOR); @@ -1896,7 +1913,7 @@ static int rtcntl_i2c_create_cdev(struct rtcnt_device_info *dev_info) } /* 取得したdev( = メジャー番号 + マイナー番号) - * からメジャー番号を取得して保持しておく */ + * からメジャー番号を取得して保持しておく */ dev_info->device_major = MAJOR(dev); dev = MKDEV(dev_info->device_major, DEV_MINOR); @@ -1944,8 +1961,8 @@ static int rtcnt_i2c_probe(struct i2c_client *client, lsb = i2c_smbus_read_byte_data(client, CNT_ADDR_LSB); if ((msb < 0) || (lsb < 0)) { printk(KERN_INFO - "%s: rtcounter not found, or wrong i2c device probed", - DRIVER_NAME); + "%s: rtcounter not found, or wrong i2c device probed", + DRIVER_NAME); // printk(KERN_DEBUG "%s: addr 0x%x, msb %d, lsb %d", __func__, // client->addr, msb, lsb); return -ENODEV; @@ -1972,7 +1989,6 @@ static int rtcnt_i2c_probe(struct i2c_client *client, return 0; } - /* * i2c_counter_init - initialize I2C counter * called by dev_init_module() @@ -2066,7 +2082,8 @@ static void rtcnt_i2c_delete_cdev(struct rtcnt_device_info *dev_info) static int rtcnt_i2c_remove(struct i2c_client *client) { struct rtcnt_device_info *dev_info; - // printk(KERN_DEBUG "%s: removing i2c device 0x%x\n", __func__, client->addr); + // printk(KERN_DEBUG "%s: removing i2c device 0x%x\n", __func__, + // client->addr); dev_info = i2c_get_clientdata(client); rtcnt_i2c_delete_cdev(dev_info); printk(KERN_INFO "%s: i2c device 0x%x removed\n", DRIVER_NAME, @@ -2093,8 +2110,7 @@ int dev_init_module(void) retval = i2c_counter_init(); if (retval == 0) { registered_devices += 2 * NUM_DEV_CNT; - } - else{ + } else { printk(KERN_ALERT "%s: i2c counter device driver register failed.\n", DRIVER_NAME); @@ -2226,7 +2242,7 @@ int dev_init_module(void) } printk(KERN_INFO "%s: %d devices loaded.\n", DRIVER_NAME, - registered_devices+NUM_DEV_TOTAL); + registered_devices + NUM_DEV_TOTAL); printk(KERN_INFO "%s: module installed at %lu\n", DRIVER_NAME, jiffies); return 0;