Dereferencing pointer to incomplete type error. 
November 17th, 2008, 05:05 AM
| | | |
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 | 
November 17th, 2008, 05:55 AM
| | | | re: Dereferencing pointer to incomplete type error.
On Nov 17, 10:19 am, Richard Heathfield <r...@see.sig.invalidwrote: Quote:
Anuz said:
>> Quote: |
While compiling a driver, I am getting this error:
| > Quote: |
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.
>
>
> Quote:
int __kc_adapter_clean(struct net_device *netdev, int *budget)
{
/*some initialization stuff */
struct adapter_struct *adapter = netdev_priv(netdev);
| > Quote:
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.
> Quote:
/* 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. Quote: Quote:
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 | 
November 17th, 2008, 06:15 AM
| | | | re: Dereferencing pointer to incomplete type error.
Anuz wrote: Quote:
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 | 
November 17th, 2008, 07:25 AM
| | | | re: Dereferencing pointer to incomplete type error.
Anuz wrote: Quote:
>
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. Quote:
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*'. Quote:
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 | 
November 17th, 2008, 07:35 AM
| | | | re: Dereferencing pointer to incomplete type error.
Andrey Tarasevich said: Quote:
Anuz wrote: Quote:
>>
>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 | 
November 17th, 2008, 08:45 AM
| | | | re: Dereferencing pointer to incomplete type error.
On Nov 17, 12:23 pm, Andrey Tarasevich <andreytarasev...@hotmail.com>
wrote: Quote:
Anuz wrote:
> Quote:
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.
> Quote:
I suspect that when at this line:
struct adapter_struct *adapter = netdev_priv(netdev);
| > Quote:
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*'.
> Quote:
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 |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|