diff mbox series

[v10,09/17] rangeset: add rangeset_empty() function

Message ID 20231012220854.2736994-10-volodymyr_babchuk@epam.com (mailing list archive)
State Superseded
Headers show
Series PCI devices passthrough on Arm, part 3 | expand

Commit Message

Volodymyr Babchuk Oct. 12, 2023, 10:09 p.m. UTC
This function can be used when user wants to remove all rangeset
entries but do not want to destroy rangeset itself.

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>

---

Changes in v10:

 - New in v10. The function is used in "vpci/header: handle p2m range sets per BAR"
---
 xen/common/rangeset.c      | 9 +++++++--
 xen/include/xen/rangeset.h | 3 ++-
 2 files changed, 9 insertions(+), 3 deletions(-)

Comments

Stewart Hildebrand Oct. 13, 2023, 5:54 p.m. UTC | #1
On 10/12/23 18:09, Volodymyr Babchuk wrote:
> This function can be used when user wants to remove all rangeset
> entries but do not want to destroy rangeset itself.
> 
> Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
> 
> ---
> 
> Changes in v10:
> 
>  - New in v10. The function is used in "vpci/header: handle p2m range sets per BAR"
> ---
>  xen/common/rangeset.c      | 9 +++++++--
>  xen/include/xen/rangeset.h | 3 ++-
>  2 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/xen/common/rangeset.c b/xen/common/rangeset.c
> index 35c3420885..420275669e 100644
> --- a/xen/common/rangeset.c
> +++ b/xen/common/rangeset.c
> @@ -448,8 +448,7 @@ struct rangeset *rangeset_new(
>      return r;
>  }
> 
> -void rangeset_destroy(
> -    struct rangeset *r)
> +void rangeset_empty(struct rangeset *r)
>  {
>      struct range *x;
> 
> @@ -465,6 +464,12 @@ void rangeset_destroy(
> 
>      while ( (x = first_range(r)) != NULL )
>          destroy_range(r, x);
> +}
> +
> +void rangeset_destroy(
> +    struct rangeset *r)
> +{
> +    rangeset_empty(r);
> 
>      xfree(r);
>  }

I think the list_del(&r->rangeset_list) operation (and associated locking and NULL check) shouldn't be moved to the new rangeset_empty() function, it should stay in rangeset_destroy().
Volodymyr Babchuk Oct. 13, 2023, 6:08 p.m. UTC | #2
Hi Stewart,

Stewart Hildebrand <stewart.hildebrand@amd.com> writes:

> On 10/12/23 18:09, Volodymyr Babchuk wrote:
>> This function can be used when user wants to remove all rangeset
>> entries but do not want to destroy rangeset itself.
>> 
>> Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
>> 
>> ---
>> 
>> Changes in v10:
>> 
>>  - New in v10. The function is used in "vpci/header: handle p2m range sets per BAR"
>> ---
>>  xen/common/rangeset.c      | 9 +++++++--
>>  xen/include/xen/rangeset.h | 3 ++-
>>  2 files changed, 9 insertions(+), 3 deletions(-)
>> 
>> diff --git a/xen/common/rangeset.c b/xen/common/rangeset.c
>> index 35c3420885..420275669e 100644
>> --- a/xen/common/rangeset.c
>> +++ b/xen/common/rangeset.c
>> @@ -448,8 +448,7 @@ struct rangeset *rangeset_new(
>>      return r;
>>  }
>> 
>> -void rangeset_destroy(
>> -    struct rangeset *r)
>> +void rangeset_empty(struct rangeset *r)
>>  {
>>      struct range *x;
>> 
>> @@ -465,6 +464,12 @@ void rangeset_destroy(
>> 
>>      while ( (x = first_range(r)) != NULL )
>>          destroy_range(r, x);
>> +}
>> +
>> +void rangeset_destroy(
>> +    struct rangeset *r)
>> +{
>> +    rangeset_empty(r);
>> 
>>      xfree(r);
>>  }
>
> I think the list_del(&r->rangeset_list) operation (and associated
> locking and NULL check) shouldn't be moved to the new rangeset_empty()
> function, it should stay in rangeset_destroy().

Ahh, yes. It was a really stupid idea to move list_del(&r->rangeset_list); to
rangeset_empty().
diff mbox series

Patch

diff --git a/xen/common/rangeset.c b/xen/common/rangeset.c
index 35c3420885..420275669e 100644
--- a/xen/common/rangeset.c
+++ b/xen/common/rangeset.c
@@ -448,8 +448,7 @@  struct rangeset *rangeset_new(
     return r;
 }
 
-void rangeset_destroy(
-    struct rangeset *r)
+void rangeset_empty(struct rangeset *r)
 {
     struct range *x;
 
@@ -465,6 +464,12 @@  void rangeset_destroy(
 
     while ( (x = first_range(r)) != NULL )
         destroy_range(r, x);
+}
+
+void rangeset_destroy(
+    struct rangeset *r)
+{
+    rangeset_empty(r);
 
     xfree(r);
 }
diff --git a/xen/include/xen/rangeset.h b/xen/include/xen/rangeset.h
index f7c69394d6..5eded7ffc5 100644
--- a/xen/include/xen/rangeset.h
+++ b/xen/include/xen/rangeset.h
@@ -56,7 +56,7 @@  void rangeset_limit(
 bool_t __must_check rangeset_is_empty(
     const struct rangeset *r);
 
-/* Add/claim/remove/query a numeric range. */
+/* Add/claim/remove/query/empty a numeric range. */
 int __must_check rangeset_add_range(
     struct rangeset *r, unsigned long s, unsigned long e);
 int __must_check rangeset_claim_range(struct rangeset *r, unsigned long size,
@@ -70,6 +70,7 @@  bool_t __must_check rangeset_overlaps_range(
 int rangeset_report_ranges(
     struct rangeset *r, unsigned long s, unsigned long e,
     int (*cb)(unsigned long s, unsigned long e, void *), void *ctxt);
+void rangeset_empty(struct rangeset *r);
 
 /*
  * Note that the consume function can return an error value apart from