1. 定义全局模板函数集
//thermal_of.c static struct thermal_zone_device_ops of_thermal_ops = { .get_trip_type = of_thermal_get_trip_type, .get_trip_temp = of_thermal_get_trip_temp, .set_trip_temp = of_thermal_set_trip_temp, .get_trip_hyst = of_thermal_get_trip_hyst, .set_trip_hyst = of_thermal_set_trip_hyst, .get_crit_temp = of_thermal_get_crit_temp, .bind = of_thermal_bind, .unbind = of_thermal_unbind, };
3. 使用时继承全局模板函数集
//thermal_of.c int __init of_parse_thermal_zones(void) { ... struct thermal_zone_device_ops *ops = kmemdup(&of_thermal_ops, sizeof(*ops), GFP_KERNEL); ... }
kmemdup 就是直接拷贝一份,拷贝的都是指针,这样就可以修改自己的,实现多态。