Linux 树驱动程序编译内核失败 BUILD_BUG_ON_ZERO

Linux Kernel out of tree Driver Compilation failed with BUILD_BUG_ON_ZERO

在 Raspberry Pi 3 上,我正在编译自定义 Linux 内核并希望包含开源软件 PWM 内核驱动程序。

我为 Linux 源克隆了以下存储库:

https://github.com/raspberrypi/linux.git

我为软件 PWM 克隆了以下存储库:

https://github.com/dagon666/rpi_SoftPwm

成功构建内核后,我按照 README 编译软件 PWM 驱动程序,如下所示:

pi@raspberrypi:~/Desktop/rpi_SoftPwm $ make M=/home/pi/Desktop/rpi_SoftPwm -C /home/pi/linux/ modules

编译失败,出现以下错误:

make: Entering directory '/home/pi/linux'
  CC [M]  /home/pi/Desktop/rpi_SoftPwm/pwm.o
In file included from ./include/linux/thread_info.h:11:0,
                 from ./include/asm-generic/preempt.h:4,
                 from ./arch/arm/include/generated/asm/preempt.h:1,
                 from ./include/linux/preempt.h:59,
                 from ./include/linux/spinlock.h:50,
                 from ./include/linux/seqlock.h:35,
                 from ./include/linux/time.h:5,
                 from ./include/linux/stat.h:18,
                 from ./include/linux/module.h:10,
                 from /home/pi/Desktop/rpi_SoftPwm/pwm.c:2:
./include/linux/bug.h:37:45: error: negative width in bit-field ‘<anonymous>’
 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
                                             ^
./include/linux/kernel.h:854:3: note: in expansion of macro ‘BUILD_BUG_ON_ZERO’
   BUILD_BUG_ON_ZERO((perms) & 2) +     \
   ^
./include/linux/sysfs.h:102:12: note: in expansion of macro ‘VERIFY_OCTAL_PERMISSIONS’
    .mode = VERIFY_OCTAL_PERMISSIONS(_mode) },  \
            ^
/home/pi/Desktop/rpi_SoftPwm/pwm.c:155:2: note: in expansion of macro ‘__ATTR’
  __ATTR(export, 0222, NULL, export_store),
  ^
./include/linux/bug.h:37:45: error: negative width in bit-field ‘<anonymous>’
 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
                                             ^
./include/linux/kernel.h:854:3: note: in expansion of macro ‘BUILD_BUG_ON_ZERO’
   BUILD_BUG_ON_ZERO((perms) & 2) +     \
   ^
./include/linux/sysfs.h:102:12: note: in expansion of macro ‘VERIFY_OCTAL_PERMISSIONS’
    .mode = VERIFY_OCTAL_PERMISSIONS(_mode) },  \
            ^
/home/pi/Desktop/rpi_SoftPwm/pwm.c:156:2: note: in expansion of macro ‘__ATTR’
  __ATTR(unexport, 0222, NULL, unexport_store),
  ^
scripts/Makefile.build:299: recipe for target '/home/pi/Desktop/rpi_SoftPwm/pwm.o' failed
make[1]: *** [/home/pi/Desktop/rpi_SoftPwm/pwm.o] Error 1
Makefile:1490: recipe for target '_module_/home/pi/Desktop/rpi_SoftPwm' failed
make: *** [_module_/home/pi/Desktop/rpi_SoftPwm] Error 2
make: Leaving directory '/home/pi/linux'

我试图在 Google 上研究这个问题,但没有找到解决方案。失败与 __ATTR 宏有关。这曾经与较旧的 Linux 内核 3.19 一起编译,但是现在 Raspbian 最高可达 Linux 4+。

我怎样才能编译它?谢谢。

Linux 内核开发人员倾向于创建 属性/sys 下的文件)非根用户不可写。这是宏 VERIFY_OCTAL_PERMISSIONS 检查的内容:权限不应设置标志 S_IWOTH(第二位)。

将权限0222替换为0220,编译成功