diff mbox series

[RFC,net-next,1/4] rhashtable: add length helper for rhashtable and rhltable

Message ID 20230609151332.263152-2-pctammela@mojatatu.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series rhashtable: length helper for rhashtable and rhltable | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 417 this patch: 417
netdev/cc_maintainers success CCed 3 of 3 maintainers
netdev/build_clang success Errors and warnings before: 131 this patch: 131
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 438 this patch: 438
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 20 lines checked
netdev/kdoc success Errors and warnings before: 1 this patch: 1
netdev/source_inline success Was 0 now: 0

Commit Message

Pedro Tammela June 9, 2023, 3:13 p.m. UTC
Instead of having users open code the rhashtable length like:
   atomic_read(&ht->nelems)

Provide a helper for both flavours of rhashtables.

Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
---
 include/linux/rhashtable.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Eric Dumazet June 9, 2023, 3:22 p.m. UTC | #1
On Fri, Jun 9, 2023 at 5:13 PM Pedro Tammela <pctammela@mojatatu.com> wrote:
>
> Instead of having users open code the rhashtable length like:
>    atomic_read(&ht->nelems)
>
> Provide a helper for both flavours of rhashtables.
>
> Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
> ---
>  include/linux/rhashtable.h | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>
> diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
> index 5b5357c0bd8c..aac803491916 100644
> --- a/include/linux/rhashtable.h
> +++ b/include/linux/rhashtable.h
> @@ -1283,4 +1283,20 @@ static inline void rhltable_destroy(struct rhltable *hlt)
>         return rhltable_free_and_destroy(hlt, NULL, NULL);
>  }
>
> +/**
> + * rhashtable_len - hash table length
> + * @ht: the hash table
> + *
> + * Returns the number of elements in the hash table
> + */
> +static inline int rhashtable_len(struct rhashtable *ht)
> +{
> +       return atomic_read(&ht->nelems);
> +}
> +
> +static inline int rhltable_len(struct rhltable *hlt)
> +{
> +       return rhashtable_len(&hlt->ht);
> +}
> +

If we want/need these, please add 'const' qualifiers to both

static inline int rhltable_len(const struct rhltable *hlt)
...
diff mbox series

Patch

diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index 5b5357c0bd8c..aac803491916 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -1283,4 +1283,20 @@  static inline void rhltable_destroy(struct rhltable *hlt)
 	return rhltable_free_and_destroy(hlt, NULL, NULL);
 }
 
+/**
+ * rhashtable_len - hash table length
+ * @ht: the hash table
+ *
+ * Returns the number of elements in the hash table
+ */
+static inline int rhashtable_len(struct rhashtable *ht)
+{
+	return atomic_read(&ht->nelems);
+}
+
+static inline int rhltable_len(struct rhltable *hlt)
+{
+	return rhashtable_len(&hlt->ht);
+}
+
 #endif /* _LINUX_RHASHTABLE_H */