Dereferencing pointer to incomplete type error.

A

Anuz

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
 
B

Barry Schwarz

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 */

You really need to provide a compilable example which demonstrates the
problem.

There are two dereference operators on that line, -> and [0].

adapter is a pointer to struct adapter_struct, or if you
prefer, a pointer to struct e1000_adapter. Are you absolutely sure
the complete definition of this structure type is in scope at this
point in the program?

rx_ring is a pointer to struct e1000_rx_ring. Are you
absolutely sure the complete definition of this structure type is in
scope at this point in the program?
/* 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:

If you have identified the correct statement as the one in error, this
does not apear to be related to your compile time problem. However,
if the function is used I would expect run-time problems.
#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

What macro substitution do think occurs in this line?

Since the compiler is telling you that dereferencing cannot be
performed, what do you mean it is not being done the correct way? How
are you determining what should occur and what actually occurs? Why
are you even executing the code? This is not a trivial warning you
can ignore with impunity. The compiler is telling you the code
generated is practically guaranteed to be wrong.
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

Casting a void* is hardly ever necessary and definitely not for a
simple assignment statement.
the problem.


I think I have already provided all info related, if anything is
missing please point out.

We need the exact order in which the declarations are processed in
your source file. One of the structures has not been completed.
 
A

Anuz

Anuz said:
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.

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
 
A

Andrey Tarasevich

Anuz said:
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.
 
A

Anuz

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 */

You really need to provide a compilable example which demonstrates the
problem.

There are two dereference operators on that line, -> and [0].

adapter is a pointer to struct adapter_struct, or if you
prefer, a pointer to struct e1000_adapter. Are you absolutely sure
the complete definition of this structure type is in scope at this
point in the program?

rx_ring is a pointer to struct e1000_rx_ring. Are you
absolutely sure the complete definition of this structure type is in
scope at this point in the program?


/* 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:

If you have identified the correct statement as the one in error, this
does not apear to be related to your compile time problem. However,
if the function is used I would expect run-time problems.




#define netdev_priv(x) x->priv

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

What macro substitution do think occurs in this line?

Since the compiler is telling you that dereferencing cannot be
performed, what do you mean it is not being done the correct way? How
are you determining what should occur and what actually occurs? Why
are you even executing the code? This is not a trivial warning you
can ignore with impunity. The compiler is telling you the code
generated is practically guaranteed to be wrong.
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

Casting a void* is hardly ever necessary and definitely not for a
simple assignment statement.
the problem.
I think I have already provided all info related, if anything is
missing please point out.

We need the exact order in which the declarations are processed in
your source file. One of the structures has not been completed.

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.

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 */
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
*/

But I am not sure whether this is the place of problem.

Regards
Anuz
 
A

Andrey Tarasevich

Anuz said:
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.
 
A

Anuz

Anuz said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top