如何修复 Android Samsung Note 3 手机的嵌入式设备驱动程序 C 代码中的指针错误?

How to fix a pointer error in C code for embedded device driver for Android Samsung Note 3 handset?

我试图将第 2 段中的代码编译为设备驱动程序,但出现以下错误。请问为什么我会收到此错误以及如何解决?

drivers/char/tbt/tbt.c:61:1: error: unknown field 'ioctl' specified in initializer
drivers/char/tbt/tbt.c:61:1: warning: initialization from incompatible pointer type [enabled by default]

#include <linux/module.h>
#include <linux/fs.h>
#define HELLO_MAJOR 234
static int debug_enable = 0;
module_param(debug_enable, int, 0);
MODULE_PARM_DESC(debug_enable, "Enable module debug mode.");
struct file_operations hello_fops;
static int hello_open(struct inode *inode, struct file *file)
{
printk("hello_open: successful\n");
return 0;
}
static int hello_release(struct inode *inode, struct file *file)
{
printk("hello_release: successful\n");
return 0;
}
static ssize_t hello_read(struct file *file, char *buf, size_t count,
loff_t *ptr)
{
printk("hello_read: returning zero bytes\n");
return 0;
}
static ssize_t hello_write(struct file *file, const char *buf,
size_t count, loff_t * ppos)
{
printk("hello_read: accepting zero bytes\n");
return 0;
}
static long hello_ioctl(struct file *filep,
  unsigned  int cmd, unsigned long arg)

{
  printk("hello_ioctl: cmd=%ld, arg=%ld\n", cmd, arg);
  return 0;
}
static int __init hello_init(void)
{
  int ret;
  printk("Hello Example Init - debug mode is %s\n",
  debug_enable ? "enabled" : "disabled");
  ret = register_chrdev(HELLO_MAJOR, "hello1", &hello_fops);
  if (ret < 0) {
  printk("Error registering hello device\n");
  goto hello_fail1;
}
printk("Hello: registered module successfully!\n");
/* Init processing here... */
return 0;
hello_fail1:
return ret;
}
  static void __exit hello_exit(void)
{
printk("Hello Example Exit\n");
}
struct file_operations hello_fops = {
owner: THIS_MODULE,
read: hello_read,
write: hello_write,
unloced_ioctl: hello_ioctl,
open: hello_open,
release: hello_release,
};
...

这是可加载模块的示例代码。我已经加载了它的较小版本。这个应该有更多的功能。它带有另一个文件,该文件应该来自用户 space 运行。非常感谢有关我可以将该代码放在项目中何处的任何提示。

我发现另一个 link 关于这个问题。描述了问题和解决方案 here 我在上面的文件中进行了他们建议的修改,但现在我收到关于更新行的不同错误,如下所示:

drivers/char/tos/tos.c:34:1: warning: format '%ld' expects argument of type 'long int', but argument 2 has type 'unsigned int' [-Wformat]
error, forbidden warning: tbt.c:34
make[3]: *** [drivers/char/tbt/tbt.o] Error 1
make[2]: *** [drivers/char/tbt] Error 2
make[1]: *** [drivers/char] Error 2
make: *** [drivers] Error 2

所以我改变了以下程序如下:

 static long hello_ioctl(struct file *filep,
      unsigned  long cmd, unsigned long arg)

    {
      printk("hello_ioctl: cmd=%ld, arg=%ld\n", cmd, arg);
      return 0;
    }

@ nsilent - 我醒了很长时间,没有想清楚。我现在明白了,只有将打印类型更改为与您正在打印的变量相同才有意义。也感谢您发现拼写错误。