Saturday 1 February 2014

Static functions in Linux device driver

Because these static function are not supposed to be used directly outside of the module. They are called by other functions in the module, among which can be the interface to an ioctl or whatever callbacks. This is why they can be called from user-space, they are just in the call path.
Take a look at the network dummy module:
dummy_dev_init() is obviously static:
static int dummy_dev_init(struct net_device *dev)
{
dev
->dstats = alloc_percpu(struct pcpu_dstats);
if (!dev->dstats)
return -ENOMEM;

return 0;
}
but it is a callback of ->ndo_init() which is called when registering this network device.
static const struct net_device_ops dummy_netdev_ops = {
.ndo_init = dummy_dev_init,
.ndo_uninit = dummy_dev_uninit,
.ndo_start_xmit = dummy_xmit,
.ndo_validate_addr = eth_validate_addr,
.ndo_set_rx_mode = set_multicast_list,
.ndo_set_mac_address = eth_mac_addr,
.ndo_get_stats64 = dummy_get_stats64,
.ndo_change_carrier = dummy_change_carrier,
};
And obvious no one should call dummy_dev_init() directly.

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More