Reputation: 95
I am new to kernel driver programming and would like to understand few aspects.
In the below code from http://lxr.free-electrons.com/source/drivers/i2c/busses/i2c-ocores.c?v=3.19
static int ocores_i2c_probe(struct platform_device *pdev)
{
struct ocores_i2c *i2c;
i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL);
}
Upvotes: 2
Views: 2623
Reputation: 9642
1) Yes, the kernel will fill out this structure for you and then pass it to your probe
function to perform initialisation.
2) In short, all of the devm_
suite of functions will tie the lifecycle of the returned resource to the lifecycle of the actual device. Any returned resources will therefore be automatically cleaned up when the specified device is un-probed.
3) Probably, yes, although the sizeof
operator will follow the definition of i2c
, so this is actually basically the same as sizeof(struct ocores_i2c)
.
Upvotes: 2