I am following LDD3 for learning network device driver. I just compiled the source code of snull driver and I got this compilation error:
error: ‘struct net_device’ has no member named ‘open’
I also got similar error when I try to initialize other members of struct net_device. Please help to resolve this error.
Below is the code:
struct net_device *snull_devs[2];
snull_devs[0] = alloc_netdev(sizeof(struct snull_priv), "sn%d",
snull_init);
void snull_init(struct net_device *dev)
{
ether_setup(dev); /* assign some of the fields */
dev->open = snull_open;
dev->stop = snull_release;
That book is pretty old, and this has apparently changed in more recent kernels. struct net_device now has the following member:
const struct net_device_ops *netdev_ops;
This has members like:
int (*ndo_open)(struct net_device *dev);
int (*ndo_stop)(struct net_device *dev);
So the equivalent code would be:
dev->netdev_ops->ndo_open = snull_open;
dev->netdev_ops->ndo_stop = snull_release;
But there could be other changes to the device driver environment that affect how this should be coded. I suggest you read the chapter API changes in the 2.6 kernel series.
Related
I'm trying to compile a kernel module on kernel 3.13 and I get this error:
error: implicit declaration of function 'create_proc_read_entry' [-Werror=implicit-function-declaration]
I google it and did not found any response. Here is the part of the code which refers to this error:
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
proc = proc_net_create(KAODV_QUEUE_PROC_FS_NAME, 0, kaodv_queue_get_info);
#else
proc = create_proc_read_entry(KAODV_QUEUE_PROC_FS_NAME, 0, init_net.proc_net, kaodv_queue_get_info, NULL);
#endif
if (!proc) {
printk(KERN_ERR "kaodv_queue: failed to create proc entry\n");
return -1;
}
Can I get help ? I really don't know what is wrong. It might be the kernel 3.13 which needs a patch. I read somewhere (on KERNEL 3.10) that the kernel needs patch. Can anyone show me where can I get the 3.13 kernel patch to eventually fix the problem. Thanks
The error is because you are not including explicitly the header that declares the function and the compiler is 'including' implicitily for you and this throws a warning. The flag '-Werror' is making the compiler treats the warning as an error. Try adding: #include <linux/proc_fs.h>
Also: create_proc_read_entry is a deprecated function.
Take a look at: https://lkml.org/lkml/2013/4/11/215
in Linux 3.9
static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
umode_t mode,
struct proc_dir_entry *base,
read_proc_t *read_proc,
void * data
) { return NULL; }
http://lxr.free-electrons.com/source/include/linux/proc_fs.h?v=3.9
in Linux 3.10
static inline struct proc_dir_entry *proc_create(const char *name,
umode_t mode,
struct proc_dir_entry *parent,
const struct file_operations *proc_fops
)
http://lxr.free-electrons.com/source/include/linux/proc_fs.h?v=3.10
So change create_proc_read_entry() to proc_create(), and change the 5 parameters to 4 parameters. It then works.
In your linux version 3.13 create_proc_read_entry this method has been deleted,instead using proc_create or proc_create_data.You can use this API
struct proc_dir_entry *proc_create_data(const char *, umode_t,
struct proc_dir_entry *,
const struct file_operations *,
void *);
static inline struct proc_dir_entry *proc_create(
const char *name, umode_t mode, struct proc_dir_entry *parent,
const struct file_operations *proc_fops);
I'm working in C and getting the following error:
*** ERROR C074 IN LINE 78 OF ..\..\..\libraries\mchpstack_base\arp.c : Invalid declaration syntax
The relevant portion of code is:
typedef struct _ARP_PACKET
{
WORD HardwareType;
WORD Protocol;
BYTE MACAddrLen;
BYTE ProtocolLen;
WORD Operation;
MAC_ADDR2 SenderMACAddr;
IP_ADDR SenderIPAddr;
MAC_ADDR2 TargetMACAddr; // This is line 78
IP_ADDR TargetIPAddr;
} ARP_PACKET;
Now MAC_ADDR2 is define elsewhere in a header file which I am sure is included in arp.c:
typedef struct _MAC_ADDR2
{
BYTE v[6];
} MAC_ADDR2;
I'm new to C; but read over guides on creating structs, the typedef usage, and the namespace issue within C. I'm quite stuck. What is that error telling me?
I'm using libwebsockets and I can't compile a demo code implemented by myself.
I created the context:
struct libwebsocket_context *context;
...
context = libwebsocket_create_context(&info);
and when I try to access the members of the struct libwebsocket_context, defined in private-libwebsockets.h:
struct libwebsocket_context {
struct pollfd *fds;
struct libwebsocket **lws_lookup; /* fd to wsi */
int fds_count;
int max_fds;
int listen_port;
...
};
For example,
printf("%d\n", context->listen_port);
The compiler returns,
error: dereferencing pointer to incomplete type
Thanks!
It seems that "struct libwebsocket_context" is not known for gcc - that's why this error occures. Are you sure that definition of this structure is included from .h file? I'd suggest you to insert for example #warning or #error with some message near definition of this struct (in .h file) and try to recompile your program. Your #error or #warning message should appear while compilation. If not - it means that gcc will not also see this struct.
The fact that the struct definition is in private-libwebsockets.h suggests that you are not supposed to use the struct members directly. You can #include that header to get access to the private implementation details of the library but you probably should not do it.
int (*foo)(epoll_event e, void *data);
If I name the file with cc extension, this gets accepted. With .c extension this
error: expected ‘)’ before ‘e’
I have googled and declaration seems to be valid for C. Can anyone please provide input on how to fix this?
Thanks
I'm guessing epoll_event is not a type name, it's a structure tag name.
In this case you need to add struct:
int (*foo)(struct epoll_event e, void *data);
This page suggests so:
struct epoll_event {
uint32_t events; /* Epoll events */
epoll_data_t data; /* User data variable */
};
So, I am trying to modify evdev.c, which is an event handler driver for input devices like mouse on linux.
The problem I am having is that when I try to compile the module, I get a ton of errors saying the members of evdev cannot be found.
/home/mousedev_dbl.c:215: error: ‘struct evdev’ has no member named ‘client_lock’
/home/mousedev_dbl.c:216: error: ‘struct evdev’ has no member named ‘client_list’
/hom/mousedev_dbl.c:217: error: ‘struct evdev’ has no member named ‘client_lock’
/home/mousedev_dbl.c: In function ‘evdev_detach_client’:
/home/mousedev_dbl.c:224: error: ‘struct evdev’ has no member named ‘client_lock’
/home/mousedev_dbl.c:226: error: ‘struct evdev’ has no member named ‘client_lock’
/home/mousedev_dbl.c: In function ‘evdev_open_device’:
/home/mousedev_dbl.c:234: error: ‘struct evdev’ has no member named ‘mutex’
/home/mousedev_dbl.c:238: error: ‘struct evdev’ has no member named ‘exist’
This is only a small portion of the errors.
The struct for evdev is clearly present in the mousedev_dbl.c files I am compiling.
struct evdev {
int open;
int minor;
struct input_handle handle;
wait_queue_head_t wait;
struct evdev_client __rcu *grab;
struct list_head client_list;
spinlock_t client_lock; /* protects client_list */
struct mutex mutex;
struct device dev;
bool exist;
};
As an example, here is how it is used on line 215.
spin_lock(&evdev->client_lock);
list_add_tail_rcu(&client->node, &evdev->client_list);
spin_unlock(&evdev->client_lock);
synchronize_rcu();
What would cause these errors?? The entire file can be found here:
http://lxr.free-electrons.com/source/drivers/input/evdev.c
struct evdev_client __rcu *grab;
Is this declaration valid? (Doesn't look like to me, unless __rcu is for the preprocessor).
Seems this declaration is rendering the rest of your struct evdev garbled. Which could explain the compiler not identifying the client_list, client_lock etc.
The problem was that I was using the kernel source from the wrong version. 2.6.38 rather than 2.6.35 so the headers and the source were not mixing well.
__rcu is defined in include/linux/compiler.h as
# define __rcu __attribute__((noderef, address_space(4)))