rtw_rhashtable.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. *****************************************************************************/
  15. #ifdef CONFIG_RTW_MESH /* for now, only promised for kernel versions we support mesh */
  16. #include <drv_types.h>
  17. int rtw_rhashtable_walk_enter(rtw_rhashtable *ht, rtw_rhashtable_iter *iter)
  18. {
  19. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
  20. return rhashtable_walk_init((ht), (iter), GFP_ATOMIC);
  21. #else
  22. /* kernel >= 4.4.0 rhashtable_walk_init use GFP_KERNEL to alloc, spin_lock for assignment */
  23. iter->ht = ht;
  24. iter->p = NULL;
  25. iter->slot = 0;
  26. iter->skip = 0;
  27. iter->walker = kmalloc(sizeof(*iter->walker), GFP_ATOMIC);
  28. if (!iter->walker)
  29. return -ENOMEM;
  30. spin_lock(&ht->lock);
  31. iter->walker->tbl =
  32. rcu_dereference_protected(ht->tbl, lockdep_is_held(&ht->lock));
  33. list_add(&iter->walker->list, &iter->walker->tbl->walkers);
  34. spin_unlock(&ht->lock);
  35. return 0;
  36. #endif
  37. }
  38. #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0))
  39. #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0))
  40. #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25))
  41. static inline int is_vmalloc_addr(const void *x)
  42. {
  43. #ifdef CONFIG_MMU
  44. unsigned long addr = (unsigned long)x;
  45. return addr >= VMALLOC_START && addr < VMALLOC_END;
  46. #else
  47. return 0;
  48. #endif
  49. }
  50. #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)) */
  51. void kvfree(const void *addr)
  52. {
  53. if (is_vmalloc_addr(addr))
  54. vfree(addr);
  55. else
  56. kfree(addr);
  57. }
  58. #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)) */
  59. #include "rhashtable.c"
  60. #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0)) */
  61. #endif /* CONFIG_RTW_MESH */