0

Sorry that the title is a bit vague. Here is what I want to do.

First lets say there is the following struct.

struct info {
  struct device *dev
  int a;
  int b;
}

I allocate memory for this struct and assign values as the following.

struct info *i0;
i0 = kzalloc(sizeof(*i), GFP_KERNEL);
i0->dev = dev0; //dev is pre-initialized
i0->a = 0;
i0->b = 1;

I am unsure if I can use container_of with pre-initialized dev0 that I used to assign to i0->dev. Something like below.

struct info * i1 = container_of(dev0, struct info, dev);
do_something(i1->a, i1->b);

Doing so gives the following error in the line of container_of.

error: undefined symbol: __compiletime_assert_###

Can someone help me understand the error and guide me on correct use of container_of? What would be a good workaround? Thank you very much.

wWw
  • 147
  • 9
  • What does it mean "predefined" `dev0` ? How is it "predefined"? – Eugene Sh. Mar 09 '22 at 20:49
  • @EugeneSh. Sorry for confusion. I meant pre-initialized. So, not doing something like `device_initialize(i0->dev)`, but just assigning `i0->dev = dev0` where `dev0` is already initialized and used in somewhere. – wWw Mar 09 '22 at 21:08
  • 1
    No. dev0 has no way of knowing there is a pointer in a different struct. That's not how container of works. – stark Mar 09 '22 at 21:16
  • 1
    You can do `container_of(dev0, struct info, dev);` only if `dev0 == &(i0->dev)`. – Marco Bonelli Mar 09 '22 at 21:37

0 Answers0