linux kernel - not understand the mechanism of free_netdev -
i study network-device-driver recently. somehow not understand free_netdev function.
i have read following link: possible de-reference of private data using net_device
the answer says when free network device, private data free.
after checking function, found call following function:
void netdev_freemem(struct net_device *dev) { char *addr = (char *)dev - dev->padded; kvfree(addr); }
but cannot understand why call function free net_device memory, , private data?
or understanding wrong...
just wondering if can guide me understand mechanism of free_netdev.
thanks in advance.
check out alloc_netdev() function definition in net/core/dev.c
alloc_size = sizeof(struct net_device); if (sizeof_priv) { /* ensure 32-byte alignment of private area */ alloc_size = align(alloc_size, netdev_align); alloc_size += sizeof_priv; } /* ensure 32-byte alignment of whole construct */ alloc_size += netdev_align - 1; p = kzalloc(alloc_size, gfp_kernel | __gfp_nowarn | __gfp_repeat); if (!p) p = vzalloc(alloc_size); if (!p) return null; dev = ptr_align(p, netdev_align); dev->padded = (char *)dev - (char *)p;
it kzalloc of sizeof(struct net_device) + sizeof_priv + padding_bytes.
so net_device private memory following struct net_device , hence kfree() of netdev frees net_device_private memory.
Comments
Post a Comment