1

The syntax for netif_napi_add is:

netif_napi_add(struct net_device *dev, struct napi_struct *napi,int (*poll)(struct napi_struct *, int), int weight)

It is used for initializing the napi structure. The problem is, when I use the function as:

netif_napi_add(wdev,rnapi,rrpoll(rnapi,20),16);

It's giving me a compilation warning:

warning: passing argument 3 of ‘netif_napi_add’ makes pointer from integer without a cast
/usr/src/linux-2.6.34.10-0.6/include/linux/netdevice.h:1089:6: note: expected ‘int (*)(struct napi_struct *, int)’ but argument is of type ‘int’

How do I fix it?

karan421
  • 863
  • 17
  • 43

2 Answers2

4

The third argument to netif_napi_add, int (*poll)(struct napi_struct *, int), is a function pointer named poll that points to a function that takes a struct napi_struct * and an int and returns an int. You're calling rrpoll directly and passing its return value (an int) to netif_napi_add, instead of a function pointer. You probably want to just pass rrpoll to the function directly:

netif_napi_add(wdev, rnapi, &rrpoll, 16);
Community
  • 1
  • 1
Michael Mrozek
  • 169,610
  • 28
  • 168
  • 175
  • Note that the `&` is optional, since the name of a function usually "decays" to a pointer to the function: `netif_napi_add(wdev, rnapi, rrpoll, 16);` – Keith Thompson Feb 16 '12 at 09:41
  • @KeithThompson It's the "usually" that bothers me; it's never wrong, so I just include it always – Michael Mrozek Feb 16 '12 at 14:48
  • The only exceptions are when the function name is the operand of `sizeof` or `_Alignof` (new in C11) (both of which are illegal), and when it's the operand of unary `&`. It's safe to omit the `&`. (But as you say, it's also save to include it.) – Keith Thompson Feb 16 '12 at 17:11
2

The third argument should be a pointer to the function, not the return value, you should call it like that:

netif_napi_add(wdev,rnapi,&rrpoll,16);

(unless rrpoll returns a pointer to the function of the given type, but I don't think this is the case :) )

MByD
  • 135,866
  • 28
  • 264
  • 277