如何修复一个指针错误在C代码嵌入式设备驱动程序为Android三星Note 3手机



我试图将第二段中的代码编译为设备驱动程序,我得到以下错误。任何想法为什么我得到这个错误以及如何修复它?

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: successfuln");
return 0;
}
static int hello_release(struct inode *inode, struct file *file)
{
printk("hello_release: successfuln");
return 0;
}
static ssize_t hello_read(struct file *file, char *buf, size_t count,
loff_t *ptr)
{
printk("hello_read: returning zero bytesn");
return 0;
}
static ssize_t hello_write(struct file *file, const char *buf,
size_t count, loff_t * ppos)
{
printk("hello_read: accepting zero bytesn");
return 0;
}
static long hello_ioctl(struct file *filep,
  unsigned  int cmd, unsigned long arg)
{
  printk("hello_ioctl: cmd=%ld, arg=%ldn", cmd, arg);
  return 0;
}
static int __init hello_init(void)
{
  int ret;
  printk("Hello Example Init - debug mode is %sn",
  debug_enable ? "enabled" : "disabled");
  ret = register_chrdev(HELLO_MAJOR, "hello1", &hello_fops);
  if (ret < 0) {
  printk("Error registering hello devicen");
  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 Exitn");
}
struct file_operations hello_fops = {
owner: THIS_MODULE,
read: hello_read,
write: hello_write,
unloced_ioctl: hello_ioctl,
open: hello_open,
release: hello_release,
};
...

这是一个可加载模块的示例代码。我已经加载了一个较小的版本。这个应该有更多的功能。它附带了另一个文件,该文件应该从用户空间运行。任何提示在哪里我可以把项目内的代码是非常感谢。

我找到了另一个关于这个问题的链接。这里描述了问题和解决方案,我在上面的文件中做了他们建议的修改,但是现在我得到了关于更新行不同的错误,如下所示:

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=%ldn", cmd, arg);
      return 0;
    }

@ nsilent -我睡了很长时间,脑子不太清楚。现在我明白了,只有将打印类型更改为与要打印的变量相同才有意义。也谢谢你指出拼写错误。

相关内容

最新更新