By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,436 Members | 1,901 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,436 IT Pros & Developers. It's quick & easy.

Dereferencing pointer to incomplete type error.

P: n/a
Hi all,

While compiling a driver, I am getting this error:

error: dereferencing pointer to incomplete type

int __kc_adapter_clean(struct net_device *netdev, int *budget)
{
/*some initialization stuff */
struct adapter_struct *adapter = netdev_priv(netdev);

struct napi_struct *napi = &adapter->rx_ring[0].napi; /*
<<<<<<<<<<<the error is on this line */
/* some other function stuff */
}

struct adapter_struct is defined as:
#define adapter_struct e1000_adapter

which is defined as:
struct e1000_adapter {
/* other members */
struct e1000_rx_ring *rx_ring;
/* other members */
};

struct e1000_rx_ring {
struct e1000_adapter *adapter;
#ifdef CONFIG_E1000_NAPI
struct napi_struct napi;
#endif
/* other members */
};

For netdev_priv() either the macro or the inline function is used:

#define netdev_priv(x) x->priv

OR

static inline void *netdev_priv(struct net_device *dev)
{
return (char *)dev + ((sizeof(struct net_device)
+ NETDEV_ALIGN_CONST)
& ~NETDEV_ALIGN_CONST);
}

struct net_device
{
void *priv;
/* other data */
}

In the particular line "&adapter->rx_ring[0].napi", after macro
substitution, dereferencing is not done in correct way, but I am not
able to figure out exactly where and how. I have tried casting the
void * part to particular struct type but, even that doesn't eliminate
the problem.
I think I have already provided all info related, if anything is
missing please point out.

I have looked for the problem around on net, couldn't find same thing,
so if this question is asked elsewhere please point to the same and I
apologize for adding the noise.
I think that problem is more of typical C compilation problem, so I
have assumed that this community is most relevant for asking this
question.
I apologize if I have unknowingly violated any community rule.

Thanks

Regards
Anuz
Nov 17 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Nov 17, 10:19 am, Richard Heathfield <r...@see.sig.invalidwrote:
Anuz said:
Hi all,
While compiling a driver, I am getting this error:
error: dereferencing pointer to incomplete type

This normally means that you've got some kind of structure type for which a
declaration is visible (e.g. struct foo;) but not a definition. Perhaps
you've omitted a header or something like that.
int __kc_adapter_clean(struct net_device *netdev, int *budget)
{
/*some initialization stuff */
struct adapter_struct *adapter = netdev_priv(netdev);
struct napi_struct *napi = &adapter->rx_ring[0].napi; /*
<<<<<<<<<<<the error is on this line */

The adapter object is of type struct adapter_struct. Make sure you have a
definition of this struct type in scope. If it is your own type, this
shouldn't be hard. If it's a platform-specific structure, check your
documentation to discover which header you need.

Assuming that's all fine, look up the type of its rx_ring member, and go
through the same deal again.
/* some other function stuff */
}
All these structures are locally defined in a single header, which is
included in very first line, so that should not be the problem.

struct adapter_struct is defined as:
#define adapter_struct e1000_adapter

You'd be better off with:

typedef e1000_adapter adapter_struct;

but I'm puzzled as to what you think the synonym offers you.


Sorry, I have skipped the following:

#ifdef DRIVER_E1000
#define adapter_struct e1000_adapter
#endif

so this is used only if particular macro is defined.

Thanks
Anuz

Nov 17 '08 #2

P: n/a
Anuz wrote:
Sorry, I have skipped the following:

#ifdef DRIVER_E1000
#define adapter_struct e1000_adapter
#endif

so this is used only if particular macro is defined.
The obvious guess would be that 'DRIVER_E1000' macro is not defined,
which in turn disables the definition of 'adapter_struct' macro. The
rest follows.

--
Best regards,
Andrey Tarasevich
Nov 17 '08 #3

P: n/a
Anuz wrote:
>
The header is included in the very first line, which contains all the
definitions of the relevant structures. And all macros like
DRIVER_E1000 are all defined my Makefile itself.
Well, I'd re-verify that. Add an obvious error next to the definition of
'adapter_struct' macro and see whether the compiler catches it

#ifdef DRIVER_E1000
#define adapter_struct e1000_adapter
jasbdxjkasbcfjda /* just to make the compiler complain */
#endif

If it doesn't, then 'DRIVER_E1000' is _not_ defined.
I suspect that when at this line:
struct adapter_struct *adapter = netdev_priv(netdev);

it becomes:
adapter = netdev->priv;/* this is a (void *) data type */
What "is a (void *) data type"? netdev->priv? If so, it doesn't really
matter, since 'adapter' is not a 'void*'.
now when
struct napi_struct *napi = &adapter->rx_ring[0].napi;
this becomes
napi = &netdev->priv->rx_ring[0].napi; /* priv is (void *) data type
*/
No, things don't "become" like that in C. 'adapter' is not a macro, so
it doesn't just get substituted they way you seem to suggest.

--
Best regards,
Andrey Tarasevich
Nov 17 '08 #4

P: n/a
Andrey Tarasevich said:
Anuz wrote:
>>
The header is included in the very first line, which contains all the
definitions of the relevant structures. And all macros like
DRIVER_E1000 are all defined my Makefile itself.

Well, I'd re-verify that. Add an obvious error next to the definition of
'adapter_struct' macro and see whether the compiler catches it

#ifdef DRIVER_E1000
#define adapter_struct e1000_adapter
jasbdxjkasbcfjda /* just to make the compiler complain */
#endif

If it doesn't, then 'DRIVER_E1000' is _not_ defined.
Slightly more elegantly:

#ifdef DRIVER_E1000
#define adapter_struct e1000_adapter
#error DRIVER_E1000 is defined - now remove this error message
#endif

Note, too, that the OP should be using typedef, not #define, for type
synonyms.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 17 '08 #5

P: n/a

On Nov 17, 12:23 pm, Andrey Tarasevich <andreytarasev...@hotmail.com>
wrote:
Anuz wrote:
The header is included in the very first line, which contains all the
definitions of the relevant structures. And all macros like
DRIVER_E1000 are all defined my Makefile itself.

Well, I'd re-verify that. Add an obvious error next to the definition of
'adapter_struct' macro and see whether the compiler catches it

#ifdef DRIVER_E1000
#define adapter_struct e1000_adapter
jasbdxjkasbcfjda /* just to make the compiler complain */
#endif

If it doesn't, then 'DRIVER_E1000' is _not_ defined.
I suspect that when at this line:
struct adapter_struct *adapter = netdev_priv(netdev);
it becomes:
adapter = netdev->priv;/* this is a (void *) data type */

What "is a (void *) data type"? netdev->priv? If so, it doesn't really
matter, since 'adapter' is not a 'void*'.
now when
struct napi_struct *napi = &adapter->rx_ring[0].napi;
this becomes
napi = &netdev->priv->rx_ring[0].napi; /* priv is (void *) data type
*/

No, things don't "become" like that in C. 'adapter' is not a macro, so
it doesn't just get substituted they way you seem to suggest.
"become" is the wrong word, my mistake.
Yes, right, E1000_DRIVER is not defined, I have tried using #error.

Thanks a loads.

Regards
Anuz
Nov 17 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.