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);
}
- pdev is pointer to a platform device. The content of the structure to which pdev is pointing to is already created when platform device is initialized and driver core will pass that information to this probe function. ?? This is the same with pci dev structure where driver core is passing pci_dev it identified during probe for driver to use? Is my understanding right?
- I am not clear on the parameters of devm_kzalloc. what does "Device to allocate memory for" mean at line 763 http://lxr.free-electrons.com/source/drivers/base/devres.c?v=3.19#L774 ? At the end of the day we just need to allocate memory in kernel of size struct ocores_i2c. Is the first parameter used as a tracking mechanism to free it later automatically (based on reading devres kernel documentation)?
- return value of devm_kzalloc is pointer to newly allocated memory of size ocores_i2c in kernel. If this is the case shouldnt the second parameter of devm_kzalloc be sizeof(struct ocores_i2c) instead of sizeof(*i2c )?