diff --git a/net/core/dst.c b/net/core/dst.c index 00aa972ad1a1..b293aeae3018 100644 --- a/net/core/dst.c +++ b/net/core/dst.c @@ -241,8 +241,14 @@ void __dst_destroy_metrics_generic(struct dst_entry *dst, unsigned long old) new = ((unsigned long) &dst_default_metrics) | DST_METRICS_READ_ONLY; prev = cmpxchg(&dst->_metrics, old, new); - if (prev == old) - kfree(__DST_METRICS_PTR(old)); + if (prev == old) { + struct dst_metrics *old_p = (struct dst_metrics *)__DST_METRICS_PTR(old); + + if (prev & DST_METRICS_REFCOUNTED) { + if (atomic_dec_and_test(&old_p->refcnt)) + kfree(old_p); + } + } } EXPORT_SYMBOL(__dst_destroy_metrics_generic);