329-mac80211-Unify-mesh-and-mpp-path-removal-function.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. From: Henning Rogge <hrogge@gmail.com>
  2. Date: Wed, 3 Feb 2016 13:58:38 +0100
  3. Subject: [PATCH] mac80211: Unify mesh and mpp path removal function
  4. mpp_path_del() and mesh_path_del() are mostly the same function.
  5. Move common code into a new static function.
  6. Acked-by: Bob Copeland <me@bobcopeland.com>
  7. Signed-off-by: Henning Rogge <henning.rogge@fkie.fraunhofer.de>
  8. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  9. ---
  10. --- a/net/mac80211/mesh_pathtbl.c
  11. +++ b/net/mac80211/mesh_pathtbl.c
  12. @@ -55,16 +55,21 @@ int mpp_paths_generation;
  13. static DEFINE_RWLOCK(pathtbl_resize_lock);
  14. +static inline struct mesh_table *resize_dereference_paths(
  15. + struct mesh_table __rcu *table)
  16. +{
  17. + return rcu_dereference_protected(table,
  18. + lockdep_is_held(&pathtbl_resize_lock));
  19. +}
  20. +
  21. static inline struct mesh_table *resize_dereference_mesh_paths(void)
  22. {
  23. - return rcu_dereference_protected(mesh_paths,
  24. - lockdep_is_held(&pathtbl_resize_lock));
  25. + return resize_dereference_paths(mesh_paths);
  26. }
  27. static inline struct mesh_table *resize_dereference_mpp_paths(void)
  28. {
  29. - return rcu_dereference_protected(mpp_paths,
  30. - lockdep_is_held(&pathtbl_resize_lock));
  31. + return resize_dereference_paths(mpp_paths);
  32. }
  33. /*
  34. @@ -899,14 +904,17 @@ void mesh_path_flush_by_iface(struct iee
  35. }
  36. /**
  37. - * mesh_path_del - delete a mesh path from the table
  38. + * table_path_del - delete a path from the mesh or mpp table
  39. *
  40. - * @addr: dst address (ETH_ALEN length)
  41. + * @tbl: mesh or mpp path table
  42. * @sdata: local subif
  43. + * @addr: dst address (ETH_ALEN length)
  44. *
  45. * Returns: 0 if successful
  46. */
  47. -int mesh_path_del(struct ieee80211_sub_if_data *sdata, const u8 *addr)
  48. +static int table_path_del(struct mesh_table __rcu *rcu_tbl,
  49. + struct ieee80211_sub_if_data *sdata,
  50. + const u8 *addr)
  51. {
  52. struct mesh_table *tbl;
  53. struct mesh_path *mpath;
  54. @@ -915,11 +923,7 @@ int mesh_path_del(struct ieee80211_sub_i
  55. int hash_idx;
  56. int err = 0;
  57. - /* flush relevant mpp entries first */
  58. - mpp_flush_by_proxy(sdata, addr);
  59. -
  60. - read_lock_bh(&pathtbl_resize_lock);
  61. - tbl = resize_dereference_mesh_paths();
  62. + tbl = resize_dereference_paths(rcu_tbl);
  63. hash_idx = mesh_table_hash(addr, sdata, tbl);
  64. bucket = &tbl->hash_buckets[hash_idx];
  65. @@ -935,9 +939,30 @@ int mesh_path_del(struct ieee80211_sub_i
  66. err = -ENXIO;
  67. enddel:
  68. - mesh_paths_generation++;
  69. spin_unlock(&tbl->hashwlock[hash_idx]);
  70. + return err;
  71. +}
  72. +
  73. +/**
  74. + * mesh_path_del - delete a mesh path from the table
  75. + *
  76. + * @addr: dst address (ETH_ALEN length)
  77. + * @sdata: local subif
  78. + *
  79. + * Returns: 0 if successful
  80. + */
  81. +int mesh_path_del(struct ieee80211_sub_if_data *sdata, const u8 *addr)
  82. +{
  83. + int err = 0;
  84. +
  85. + /* flush relevant mpp entries first */
  86. + mpp_flush_by_proxy(sdata, addr);
  87. +
  88. + read_lock_bh(&pathtbl_resize_lock);
  89. + err = table_path_del(mesh_paths, sdata, addr);
  90. + mesh_paths_generation++;
  91. read_unlock_bh(&pathtbl_resize_lock);
  92. +
  93. return err;
  94. }
  95. @@ -951,33 +976,13 @@ enddel:
  96. */
  97. static int mpp_path_del(struct ieee80211_sub_if_data *sdata, const u8 *addr)
  98. {
  99. - struct mesh_table *tbl;
  100. - struct mesh_path *mpath;
  101. - struct mpath_node *node;
  102. - struct hlist_head *bucket;
  103. - int hash_idx;
  104. int err = 0;
  105. read_lock_bh(&pathtbl_resize_lock);
  106. - tbl = resize_dereference_mpp_paths();
  107. - hash_idx = mesh_table_hash(addr, sdata, tbl);
  108. - bucket = &tbl->hash_buckets[hash_idx];
  109. -
  110. - spin_lock(&tbl->hashwlock[hash_idx]);
  111. - hlist_for_each_entry(node, bucket, list) {
  112. - mpath = node->mpath;
  113. - if (mpath->sdata == sdata &&
  114. - ether_addr_equal(addr, mpath->dst)) {
  115. - __mesh_path_del(tbl, node);
  116. - goto enddel;
  117. - }
  118. - }
  119. -
  120. - err = -ENXIO;
  121. -enddel:
  122. - mesh_paths_generation++;
  123. - spin_unlock(&tbl->hashwlock[hash_idx]);
  124. + err = table_path_del(mpp_paths, sdata, addr);
  125. + mpp_paths_generation++;
  126. read_unlock_bh(&pathtbl_resize_lock);
  127. +
  128. return err;
  129. }