--- zzzz-none-000/linux-2.6.28.10/include/linux/inetdevice.h 2009-05-02 18:54:43.000000000 +0000 +++ puma5-6360-529/linux-2.6.28.10/include/linux/inetdevice.h 2009-12-11 11:48:18.000000000 +0000 @@ -173,6 +173,84 @@ return in_dev; } +#ifdef CONFIG_DEV_REFCNT_DEBUG + +#include "linux/kallsyms.h" + +static inline void in_show_here(char *func, struct net_device *dev, + int refcnt, char *fn, int ln, + unsigned long ip) +{ + printk(KERN_DEBUG "%s: in %d dev %d %s() %s:%d", + dev->name, refcnt, atomic_read(&dev->refcnt), + func, fn, ln); + print_ip_sym(ip); +} + +#define in_dev_get(dev) ____in_dev_get(dev, __FILE__, __LINE__) + +static inline struct in_device * +____in_dev_get(struct net_device *dev, char *fn, int ln) +{ + struct in_device *idev = NULL; + rcu_read_lock(); + idev = __in_dev_get_rcu(dev); + if (idev) { + atomic_inc(&idev->refcnt); + in_show_here("in_dev_get", idev->dev, atomic_read(&idev->refcnt), + fn, ln, + (unsigned long)__builtin_return_address(0)); + } + rcu_read_unlock(); + return idev; +} + +static __inline__ struct in_device * +__in_dev_get_rtnl(const struct net_device *dev) +{ + return (struct in_device*)dev->ip_ptr; +} + +extern void in_dev_finish_destroy(struct in_device *idev); + +#define in_dev_put(idev) ____in_dev_put(idev, __FILE__, __LINE__) + +static inline void +____in_dev_put(struct in_device *idev, char *fn, int ln) +{ + int tmp = atomic_dec_and_test(&idev->refcnt); + + in_show_here("in_dev_put", idev->dev, atomic_read(&idev->refcnt), + fn, ln, + (unsigned long)__builtin_return_address(0)); + if (tmp) + in_dev_finish_destroy(idev); +} + +#define __in_dev_put(idev) ______in_dev_put(idev, __FILE__, __LINE__) + +static inline void +______in_dev_put(struct in_device *idev, char *fn, int ln) +{ + atomic_dec(&(idev)->refcnt); + in_show_here("__in_dev_put", idev->dev, atomic_read(&idev->refcnt), + fn, ln, + (unsigned long)__builtin_return_address(0)); +} + +#define in_dev_hold(idev) ____in_dev_hold(idev, __FILE__, __LINE__) + +static inline void +____in_dev_hold(struct in_device *idev, char *fn, int ln) +{ + atomic_inc(&(idev)->refcnt); + in_show_here("__in_dev_put", idev->dev, atomic_read(&idev->refcnt), + fn, ln, + (unsigned long)__builtin_return_address(0)); +} + +#else + static __inline__ struct in_device * in_dev_get(const struct net_device *dev) { @@ -202,6 +280,7 @@ #define __in_dev_put(idev) atomic_dec(&(idev)->refcnt) #define in_dev_hold(idev) atomic_inc(&(idev)->refcnt) +#endif #endif /* __KERNEL__ */