📄 check_driver
字号:
#!/bin/bash## This script shows some of the deficiencies in drivers. Some# of the things that are tested here are only suggestions, and# don't necessarily apply to every driver.#check_all=noif [ "$1" ];then driver=$1else echo 'check_driver <filename>' exit 1fiecho "I: ${driver}:"basedriver=$(basename ${driver} .c)# special casescase ${driver} in ni_pcimio.c) driver="${driver} ni_mio_common.c" ;; ni_atmio.c) driver="${driver} ni_mio_common.c" ;; ni_mio_cs.c) driver="${driver} ni_mio_common.c" ;;esac# check to see if it is a driverif grep '^\(static \)*comedi_driver' ${driver} &>/dev/null;then echo "appears to be a driver"else echo "not a driver file" exit 1fiif ! grep '[[:space:]]\+module:[[:space:]]*THIS_MODULE' ${driver} &>/dev/null;then echo "E: doesn't set driver->module to THIS_MODULE"fi# check the Makefile for the config optionconfig=$(grep "CONFIG.*${basedriver}.o" Makefile|sed 's/.*\(CONFIG_.*\)\{1\}).*/\1/')if [ "$config" = "" ];then echo "E: can't find config option!"else echo config option $configfi# check Makefile.in for the config optionif [ $(grep "CONFIG.*${basedriver}.o" Makefile &>/dev/null) ];then echo "E: driver missing from Makefile.in"fi# check to see if it uses name recognitionif grep 'board_name:' ${driver} &>/dev/null;then echo uses recognize to determine type probe=recognizeelse if grep 'dev..board_ptr' ${driver} &>/dev/null;then echo auto-probes type of board probe=auto else echo only supports one type of board probe=one fifi# auto checksif [ "$probe" = auto ];then if grep 'dev..board_ptr[[:space:]]*=' ${driver} &>/dev/null;then echo 'sets dev->board_ptr' else echo "E: doesn't set dev->board_ptr" fifi# recognize checksif [ "$probe" = recognize ];then if ! grep '[[:space:]]\+offset:[[:space:]]*sizeof' ${driver} &>/dev/null;then echo "E: doesn't set driver->offset" fi if ! grep '[[:space:]]\+num_names:[[:space:]]' ${driver} &>/dev/null;then echo "E: doesn't set driver->num_names" fifi# I would prefer that drivers have a consistent number of subdevices# independent of the particular board type. If a subdevice is not# relevant for a board type, the type should be set to COMEDI_SUBD_UNUSED.# However, for drivers that handle N identical subdevices, it's better# to have a variable number of subdevices.tmp=$(cat ${driver}|grep -c 'dev..n_subdevices[[:space:]]*=' 2>/dev/null)if [ "$tmp" = 1 ];then echo sets n_subdevices onceelse echo W: sets n_subdevices multiple times: "$tmp"fiif grep 'dev..n_subdevices[[:space:]]*=[[:space:]]*[^[:digit:][:space:]]' ${driver} &>/dev/null;then echo "W: sets n_subdevices by variable"fi# Check to see if board_name is setif grep 'dev..board_name[[:space:]]*=' ${driver} &>/dev/null;then echo "board_name is set"else echo "E: board_name not set"fi# Do we use trig? trig[0] has been eliminatedif [ "$check_all" = yes ]; thenif grep 'trig\[0\]' ${driver} &>/dev/null;then echo "E: uses trig[0]"else echo "doesn't use trig[0]"fifi# trig[1234] has been eliminatedif [ "$check_all" = yes ]; thenif grep 'trig\[[1234]\]' ${driver} &>/dev/null;then echo "E: uses trig[1234]" trig1234=yeselse echo "doesn't use trig[1234]" trig1234=nofifiif grep 'comedi_cmd' ${driver} &>/dev/null;then echo "uses cmd" cmd=yeselse if [ "$trig1234" == yes ];then echo "E: doesn't use cmd" else echo "doesn't use cmd" fi cmd=nofiif grep 'comedi_insn' ${driver} &>/dev/null;then echo "uses insn" insn=yeselse if grep 'subdev_8255_init' ${driver} &>/dev/null;then echo uses subdev_8255_init else echo "E: doesn't use insn" fi insn=nofi# rt_printk() only needs to be used in possible real-time code paths,# which is basically everything except *_attach() and *_detach().# However, since it works correctly in non-real-time code, just use# it everywhere.if [ "$check_all" = yes ]; thenif grep 'printk' ${driver} &>/dev/null;then if ! grep 'rt_printk' ${driver} &>/dev/null;then echo "W: doesn't use rt_printk" fififi# comedi_request_irq() handles real-time interrupts.if grep request_irq ${driver} &>/dev/null;then irq=yes if ! grep 'comedi_request_irq' ${driver} &>/dev/null;then echo "E: doesn't use comedi_request_irq" fi if ! grep 'comedi_free_irq' ${driver} &>/dev/null;then echo "E: doesn't use comedi_free_irq" fielse irq=nofiif grep SA_INTERRUPT ${driver} &>/dev/null;then echo "E: uses SA_INTERRUPT"fiif grep 'request_region' ${driver} &>/dev/null;then if ! grep 'release_region' ${driver} &>/dev/null;then echo "E: release_region() not called" fifiif grep 'pci_dev' ${driver} &>/dev/null;then pci=yes echo uses pci if ! grep 'pci_find_device' ${driver} &>/dev/null;then echo "W: doesn't use pci_find_device" fi if ! grep 'pci_enable_device' ${driver} &>/dev/null;then echo "W: doesn't use pci_enable_device" fi if ! grep 'MODULE_DEVICE_TABLE' ${driver} &>/dev/null;then echo "W: doesn't use MODULE_DEVICE_TABLE" fi if grep 'pcibios_' ${driver} &>/dev/null;then echo "W: has pcibios_*() calls" fielse pci=nofi# Who doesn't use comments like this to indicate something needs# to be fixed?if [ "$check_all" = yes ]; thenif grep '\(XXX\)\|\(FIX\)' ${driver} &>/dev/null;then echo "W: has FIXME-like comments"fifi# COMEDI_INITCLEANUP isn't strictly necessary, but it's a one-stop# cleanup to get Comedi to compile as part of the kernel. It is# recommended to use it unless something else is necessary in module# init.if [ "$check_all" = yes ]; thenif grep 'int init_module' ${driver} &>/dev/null;then echo "W: suggest using COMEDI_INITCLEANUP"fifi# range_unknown _should_ be used if the driver can't determine# the I/O range. However, it's commonly used as a marker where# the author has not added more accurate range information.if [ "$check_all" = yes ]; thenif grep 'range_unknown' ${driver} &>/dev/null;then echo "W: uses range_unknown"fifi# cur_trig was removed around 0.7.56if grep 'cur_trig' ${driver} &>/dev/null;then echo "E: uses cur_trig"fiif grep -E 'cmd..?data' ${driver} &>/dev/null;then echo "E: uses cmd->data or cmd->data_len"fi# buf_int_ptr is (void *), whereas the minimum sample size is# 2 bytes. Should be buf_int_ptr += sizeof(sampl_t)if grep 'buf_int_ptr++' ${driver} &>/dev/null;then echo "E: uses buf_int_ptr++"fi# sameif grep 'buf_int_count++' ${driver} &>/dev/null;then echo "E: uses buf_int_count++"fi# remnants of trig[0]if grep 'di_unpack' ${driver} &>/dev/null;then echo "E: di_unpack() is gone"fi# remnants of trig[0]if grep 'do_pack' ${driver} &>/dev/null;then echo "E: do_pack() is gone"fi# This is a bug that causes difficulty to unload a driver. Easy# to fix.if grep 'request_region.*dev.*iobase' ${driver} &>/dev/null;then echo "W: recommend assigning dev->iobase after successful request_region()"fi# ds got it wrong in the first driver, and it was subsequently# copied to others. Use ||.# Doesn't check everything. Use check_cmdtest.if grep 'if.*cmd.*&&.*err..;' ${driver} &>/dev/null;then echo "E: Probable logic error in cmdtest"fi# Change in 0.7.59. Drivers need to call subdev_8255_cleanup()# so the 8255 code knows when to free it's private structures.if grep 'subdev_8255_init' ${driver} &>/dev/null;then if ! grep 'subdev_8255_cleanup' ${driver} &>/dev/null;then echo "E: doesn't call subdev_8255_cleanup()" fifi# Policy change in 0.7.60. Drivers should use comedi_event(),# which has a slightly different behavior. Checks for use# of comedi_done(), comedi_error_done(), comedi_bufcheck(),# comedi_eos(), comedi_eobuf()if grep 'comedi_\(\(done\)\|\(error_done\)\|\(bufcheck\)\|\(eos\)\|\(eobuf\)\)[[:space:]]*(' \ ${driver} &>/dev/null;then echo "W: should be using comedi_event()"fi# Drivers should have documentation in Documentation/comedi/drivers.txtif false; thenif grep "^Driver: ${basedriver}.o$" ../../Documentation/comedi/drivers.txt \ &>/dev/null;then echo "entry in drivers.txt"else echo "E: not documented in drivers.txt"fifi# Drivers should have documentation in the sourceif grep "^Driver: ${basedriver}.o$" $driver &>/dev/null;then echo "documentation in source" if grep "^Devices:" $driver &>/dev/null;then echo "has devices documentation" else echo "E: documentation: no Devices:" fi if grep "^Author:" $driver &>/dev/null;then echo "has author documentation" else echo "E: documentation: no Author:" fi if grep "^Status:" $driver &>/dev/null;then echo "has status documentation" else echo "E: documentation: no Status:" fi if grep "^Updated:" $driver &>/dev/null;then echo "has updated documentation" else echo "W: documentation: no Updated:" fi if grep "^Description:" $driver &>/dev/null;then echo "has description documentation" else echo "E: documentation: no Description:" fielse echo "E: not documented in source"fi# Check that the config option is in Config.inif grep "dep_tristate.* ${config} \$CONFIG_COMEDI" ../Config.in &>/dev/null;then echo "config option in Config.in"else echo "E: config option not in Config.in (or broken)"fi# Check if the driver contains ^Mif grep '
' ${driver} &>/dev/null;then echo "E: driver has ^M characters"fiif [ -f "${basedriver}.o" ];then # .o checks n_syms=$(nm ${basedriver}.o |grep -c ' [TDC] ') echo "number of global symbols: $n_syms" n_xsyms=$(nm ${basedriver}.o |grep -c ' __ksymtab') echo "number of exported symbols: $n_xsyms" if [ $(($n_syms-$n_xsyms)) -gt 2 ];then echo "W: driver leaks symbols" fifi# Check if the driver contains SDF_RT, which isn't used by the coreif grep '
' ${driver} &>/dev/null;then echo "E: driver uses SDF_RT"fiif [ $irq = yes ];thenif [ $pci = yes ];then if ! grep SA_SHIRQ ${driver} &>/dev/null;then echo "E: PCI drivers need to use SA_SHIRQ" fielse if grep SA_SHIRQ ${driver} &>/dev/null;then echo "E: non PCI device using SA_SHIRQ" fififiif [ $pci = yes ];then if ! grep pci_device_id ${driver} &>/dev/null;then echo "E: PCI drivers should have pci_device_id tables" fifiif grep 'insn->data' ${driver} &>/dev/null;then echo "E: driver uses insn->data, which is a userspace pointer"fiif grep 'out[wlb] *([^(,]*iobase' ${driver} &>/dev/null; then echo "E: misordered outX(dev->iobase + offset,XXX)"fiif grep 'write[wlb] *([^(,]*iobase' ${driver} &>/dev/null; then echo "E: writeX(dev->iobase + offset,XXX)"fiif grep 'COMEDI_SUBD_AI' ${driver} &>/dev/null;then if ! grep 'SDF_\(GROUND\|COMMON\|DIFF\|OTHER\)' ${driver} &>/dev/null;then echo "E: Driver doesn't set SDF flags for aref's it supports" fifiif grep -e 'include..linux.version.h' \ -e 'include..linux.config.h' \ -e 'include..linux.kdev_t.h' \ -e 'include..linux.slab.h' \ -e 'include..linux.errno.h' \ -e 'include..linux.spinlock.h' \ -e 'include..linux.wait.h' \ -e 'include..linux.mm.h' \ -e 'include..linux.init.h' \ -e 'include..linux.vmalloc.h' \ -e 'include..asm.uaccess.h' \ ${driver} &>/dev/null;then echo "W: Driver #includes headers included by comedidev.h"fi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -