Skip to contentSkip to conversation

resource: Simplify region_intersects() by reducing conditionals

PATCH Superseded Andy Shevchenko 2 participants 23 messages Aug 13, 2020 – Aug 14, 2020

Subsystems (2)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 resource: Simplify region_intersects() by reducing conditionals

Now we have for 'other' and 'type' variables

other type return

  0	  0	REGION_DISJOINT
  0	  x	REGION_INTERSECTS
  x	  0	REGION_DISJOINT
  x	  x	REGION_MIXED

Obviously it's easier to check 'type' for 0 first instead of currently checked 'other'.

---
 kernel/resource.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
kernel/resource.c +3 -6
index 841737bbda9e..70575a61bf20 100644
@@ -554,13 +554,10 @@ int region_intersects(resource_size_t start, size_t size, unsigned long flags,
 	}
 	read_unlock(&resource_lock);
 
-	if (other == 0)
-		return type ? REGION_INTERSECTS : REGION_DISJOINT;
+	if (type == 0)
+		return REGION_DISJOINT;
 
-	if (type)
-		return REGION_MIXED;
-
-	return REGION_DISJOINT;
+	return (other == 0) ? REGION_INTERSECTS : REGION_MIXED;
 }
 EXPORT_SYMBOL_GPL(region_intersects);
 
Signature · 1 line
2.28.0
#1 lore raw

PATCH 2/7 resource: Group resource_overlaps() with other inline helpers

For better maintenance group resource_overlaps() with other inline helpers.

---
 include/linux/ioport.h | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
include/linux/ioport.h +5 -6
index 6c2b06fe8beb..0193987b9968 100644
@@ -226,6 +226,11 @@ static inline bool resource_contains(struct resource *r1, struct resource *r2)
 	return r1->start <= r2->start && r1->end >= r2->end;
 }
 
+/* True if any part of r1 overlaps r2 */
+static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
+{
+       return (r1->start <= r2->end && r1->end >= r2->start);
+}
 
 /* Convenience shorthand with allocation */
 #define request_region(start,n,name)		__request_region(&ioport_resource, (start), (n), (name), 0)
@@ -291,12 +296,6 @@ extern int
 walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start, u64 end,
 		    void *arg, int (*func)(struct resource *, void *));
 
-/* True if any part of r1 overlaps r2 */
-static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
-{
-       return (r1->start <= r2->end && r1->end >= r2->start);
-}
-
 struct resource *devm_request_free_mem_region(struct device *dev,
 		struct resource *base, unsigned long size);
 struct resource *request_free_mem_region(struct resource *base,
Signature · 1 line
2.28.0
#2 lore raw

Re: [PATCH v1 2/7] resource: Group resource_overlaps() with other inline helpers

Quoted 13 lines · Andy Shevchenko

For better maintenance group resource_overlaps() with other inline helpers.

---
 include/linux/ioport.h | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
include/linux/ioport.h +0 -0
index 6c2b06fe8beb..0193987b9968 100644

include/linux/ioport.h static inline bool resource_contains(struct resource *r1, struct resource *r2) · line 232

Quoted 7 lines
include/linux/ioport.h +4 -0
@@ -226,6 +226,11 @@ static inline bool resource_contains(struct resource *r1, struct resource *r2)
        return r1->start <= r2->start && r1->end >= r2->end;
 }
 
+/* True if any part of r1 overlaps r2 */
+static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
+{
+       return (r1->start <= r2->end && r1->end >= r2->start);

The redundant parens can be dropped while at it.

Quoted 20 lines
include/linux/ioport.h +1 -7
+}
 
 /* Convenience shorthand with allocation */
 #define request_region(start,n,name)           __request_region(&ioport_resource, (start), (n), (name), 0)
@@ -291,12 +296,6 @@ extern int
 walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start, u64 end,
                    void *arg, int (*func)(struct resource *, void *));
 
-/* True if any part of r1 overlaps r2 */
-static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
-{
-       return (r1->start <= r2->end && r1->end >= r2->start);
-}
-
 struct resource *devm_request_free_mem_region(struct device *dev,
                struct resource *base, unsigned long size);
 struct resource *request_free_mem_region(struct resource *base,
--

2.28.0

#3 lore raw

Re: [PATCH v1 2/7] resource: Group resource_overlaps() with other inline helpers

Quoted 4 lines · Rafael J. Wysocki
Quoted 2 lines · Andy Shevchenko

For better maintenance group resource_overlaps() with other inline helpers.

...

Quoted 6 lines

include/linux/ioport.h static inline bool resource_contains(struct resource *r1, struct resource *r2) · line 232

Quoted 4 lines
include/linux/ioport.h +4 -0
+/* True if any part of r1 overlaps r2 */
+static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
+{
+       return (r1->start <= r2->end && r1->end >= r2->start);

The redundant parens can be dropped while at it.

Okay, will do!

Quoted 1 line
Quoted 1 line

+}

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

PATCH 3/7 resource: Introduce resource_union() for overlapping resources

In reply to Andy Shevchenko

Some already present users may utilize resource_union() helper. Provide it for them and for wider use in the future.

Deliberately avoid min()/max() macro as they are still parts of kernel.h which is quite a burden to be included here in order to avoid circular dependencies.

Cc Mika Westerberg <[email protected]>
Cc Kuppuswamy Sathyanarayanan <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 include/linux/ioport.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/ioport.h +10 -0
index 0193987b9968..c98df0ec7422 100644
@@ -232,6 +232,16 @@ static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
        return (r1->start <= r2->end && r1->end >= r2->start);
 }
 
+static inline bool
+resource_union(struct resource *r1, struct resource *r2, struct resource *r)
+{
+	if (!resource_overlaps(r1, r2))
+		return false;
+	r->start = r2->start < r1->start ? r2->start : r1->start;
+	r->end = r2->end > r1->end ? r2->end : r1->end;
+	return true;
+}
+
 /* Convenience shorthand with allocation */
 #define request_region(start,n,name)		__request_region(&ioport_resource, (start), (n), (name), 0)
 #define request_muxed_region(start,n,name)	__request_region(&ioport_resource, (start), (n), (name), IORESOURCE_MUXED)
Signature · 1 line
2.28.0
#5 lore raw

Re: [PATCH v1 3/7] resource: Introduce resource_union() for overlapping resources

Quoted 22 lines · Andy Shevchenko

Some already present users may utilize resource_union() helper. Provide it for them and for wider use in the future.

Deliberately avoid min()/max() macro as they are still parts of kernel.h which is quite a burden to be included here in order to avoid circular dependencies.

Cc Mika Westerberg <[email protected]>
Cc Kuppuswamy Sathyanarayanan <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 include/linux/ioport.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/ioport.h +0 -0
index 0193987b9968..c98df0ec7422 100644

include/linux/ioport.h static inline bool resource_overlaps(struct resource *r1, struct resource *r2) · line 239

Quoted 8 lines
include/linux/ioport.h +5 -0
@@ -232,6 +232,16 @@ static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
        return (r1->start <= r2->end && r1->end >= r2->start);
 }
 
+static inline bool
+resource_union(struct resource *r1, struct resource *r2, struct resource *r)
+{
+       if (!resource_overlaps(r1, r2))
+               return false;

I tend to add empty lines after return statements like this to make them more clearly visible.

include/linux/ioport.h static inline bool resource_overlaps(struct resource *r1, struct resource *r2) · line 241

Quoted 2 lines
include/linux/ioport.h +2 -0
+       r->start = r2->start < r1->start ? r2->start : r1->start;
+       r->end = r2->end > r1->end ? r2->end : r1->end;

Well, what about using min() and max() here?

Quoted 9 lines
include/linux/ioport.h +3 -1
+       return true;
+}
+
 /* Convenience shorthand with allocation */
 #define request_region(start,n,name)           __request_region(&ioport_resource, (start), (n), (name), 0)
 #define request_muxed_region(start,n,name)     __request_region(&ioport_resource, (start), (n), (name), IORESOURCE_MUXED)
--

2.28.0

#6 lore raw

Re: [PATCH v1 3/7] resource: Introduce resource_union() for overlapping resources

Quoted 9 lines · Rafael J. Wysocki
Quoted 7 lines · Andy Shevchenko

Some already present users may utilize resource_union() helper. Provide it for them and for wider use in the future.

Deliberately avoid min()/max() macro as they are still parts of kernel.h which is quite a burden to be included here in order to avoid circular dependencies.

...

Quoted 5 lines

include/linux/ioport.h static inline bool resource_overlaps(struct resource *r1, struct resource *r2) · line 239

Quoted 2 lines
include/linux/ioport.h +2 -0
+       if (!resource_overlaps(r1, r2))
+               return false;

I tend to add empty lines after return statements like this to make them more clearly visible.

Okay!

Quoted 4 lines

include/linux/ioport.h static inline bool resource_overlaps(struct resource *r1, struct resource *r2) · line 241

Quoted 2 lines
include/linux/ioport.h +2 -0
+       r->start = r2->start < r1->start ? r2->start : r1->start;
+       r->end = r2->end > r1->end ? r2->end : r1->end;

Well, what about using min() and max() here?

I devoted one paragraph in the commit message to answer this. The kernel.h (which I'm planning to split at some point) is a monster which brings more pain than solves here. Note, this is a header file and it's quite clean from dependencies perspective.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw

Re: [PATCH v1 3/7] resource: Introduce resource_union() for overlapping resources

Quoted 25 lines · Andy Shevchenko
Quoted 9 lines · Rafael J. Wysocki
Quoted 7 lines · Andy Shevchenko

Some already present users may utilize resource_union() helper. Provide it for them and for wider use in the future.

Deliberately avoid min()/max() macro as they are still parts of kernel.h which is quite a burden to be included here in order to avoid circular dependencies.

...

Quoted 5 lines

include/linux/ioport.h static inline bool resource_overlaps(struct resource *r1, struct resource *r2) · line 239

Quoted 2 lines
include/linux/ioport.h +2 -0
+       if (!resource_overlaps(r1, r2))
+               return false;

I tend to add empty lines after return statements like this to make them more clearly visible.

Okay!

Quoted 3 lines
Quoted 2 lines
include/linux/ioport.h +2 -0
+       r->start = r2->start < r1->start ? r2->start : r1->start;
+       r->end = r2->end > r1->end ? r2->end : r1->end;
Quoted 6 lines
Quoted 1 line

Well, what about using min() and max() here?

I devoted one paragraph in the commit message to answer this. The kernel.h (which I'm planning to split at some point) is a monster which brings more pain than solves here. Note, this is a header file and it's quite clean from dependencies perspective.

But this is code duplication (even if really small) and it is not entirely clean too.

Maybe move the definitions of min() and max() to a separate header file?

#8 lore raw

Re: [PATCH v1 3/7] resource: Introduce resource_union() for overlapping resources

Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Rafael J. Wysocki

On Thu, Aug 13, 2020 at 7:57 PM Andy Shevchenko
<[email protected]> wrote:

...

Quoted 11 lines
Quoted 6 lines
Quoted 1 line

Well, what about using min() and max() here?

I devoted one paragraph in the commit message to answer this. The kernel.h (which I'm planning to split at some point) is a monster which brings more pain than solves here. Note, this is a header file and it's quite clean from dependencies perspective.

But this is code duplication (even if really small) and it is not entirely clean too.

Maybe move the definitions of min() and max() to a separate header file?

That is the plan in the kernel.h splitting project. But do you want me to do it here? I can try to bring that patch into this series.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#9 lore raw

Re: [PATCH v1 3/7] resource: Introduce resource_union() for overlapping resources

Quoted 17 lines · Andy Shevchenko
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Rafael J. Wysocki

On Thu, Aug 13, 2020 at 7:57 PM Andy Shevchenko
<[email protected]> wrote:

...

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Well, what about using min() and max() here?

I devoted one paragraph in the commit message to answer this. The kernel.h (which I'm planning to split at some point) is a monster which brings more pain than solves here. Note, this is a header file and it's quite clean from dependencies perspective.

Quoted 7 lines
Quoted 4 lines

But this is code duplication (even if really small) and it is not entirely clean too.

Maybe move the definitions of min() and max() to a separate header file?

That is the plan in the kernel.h splitting project. But do you want me to do it here? I can try to bring that patch into this series.

Well, ostensibly the purpose of this series is to reduce code duplication, but if it adds code duplication, that kind of defeats the purpose IMO.

#10 lore raw

Re: [PATCH v1 3/7] resource: Introduce resource_union() for overlapping resources

Quoted 21 lines · Rafael J. Wysocki
Quoted 19 lines · Andy Shevchenko
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Rafael J. Wysocki

On Thu, Aug 13, 2020 at 7:57 PM Andy Shevchenko
<[email protected]> wrote:

...

Quoted 10 lines
Quoted 6 lines
Quoted 1 line

Well, what about using min() and max() here?

I devoted one paragraph in the commit message to answer this. The kernel.h (which I'm planning to split at some point) is a monster which brings more pain than solves here. Note, this is a header file and it's quite clean from dependencies perspective.

But this is code duplication (even if really small) and it is not entirely clean too.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Maybe move the definitions of min() and max() to a separate header file?

That is the plan in the kernel.h splitting project. But do you want me to do it here? I can try to bring that patch into this series.

Well, ostensibly the purpose of this series is to reduce code duplication, but if it adds code duplication, that kind of defeats the purpose IMO.

Okay, I will append minmax.h split in v2.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#11 lore raw

PATCH 4/7 resource: Introduce resource_intersection() for overlapping resources

In reply to Andy Shevchenko

There will be at least one user that can utilize new helper. Provide the helper for future user and for wider use.

Deliberately avoid min()/max() macro as they are still parts of kernel.h which is quite a burden to be included here in order to avoid circular dependencies.

---
 include/linux/ioport.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/ioport.h +10 -0
index c98df0ec7422..1d5ab2e7f9eb 100644
@@ -232,6 +232,16 @@ static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
        return (r1->start <= r2->end && r1->end >= r2->start);
 }
 
+static inline bool
+resource_intersection(struct resource *r1, struct resource *r2, struct resource *r)
+{
+	if (!resource_overlaps(r1, r2))
+		return false;
+	r->start = r1->start > r2->start ? r1->start : r2->start;
+	r->end = r1->end < r2->end ? r1->end : r2->end;
+	return true;
+}
+
 static inline bool
 resource_union(struct resource *r1, struct resource *r2, struct resource *r)
 {
Signature · 1 line
2.28.0
#12 lore raw

Re: [PATCH v1 4/7] resource: Introduce resource_intersection() for overlapping resources

Quoted 20 lines · Andy Shevchenko

There will be at least one user that can utilize new helper. Provide the helper for future user and for wider use.

Deliberately avoid min()/max() macro as they are still parts of kernel.h which is quite a burden to be included here in order to avoid circular dependencies.

---
 include/linux/ioport.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/ioport.h +0 -0
index c98df0ec7422..1d5ab2e7f9eb 100644
@@ -232,6 +232,16 @@ static inline bool resource_overlaps(struct resource *r1, struct resource *r2)
        return (r1->start <= r2->end && r1->end >= r2->start);
 }

include/linux/ioport.h static inline bool resource_overlaps(struct resource *r1, struct resource *r2) · line 243

Quoted 10 lines
include/linux/ioport.h +9 -0
 
+static inline bool
+resource_intersection(struct resource *r1, struct resource *r2, struct resource *r)
+{
+       if (!resource_overlaps(r1, r2))
+               return false;
+       r->start = r1->start > r2->start ? r1->start : r2->start;
+       r->end = r1->end < r2->end ? r1->end : r2->end;
+       return true;
+}

I have the same comments as for patch [3/7].

Quoted 7 lines
include/linux/ioport.h +1 -1
+
 static inline bool
 resource_union(struct resource *r1, struct resource *r2, struct resource *r)
 {
--

2.28.0

#13 lore raw

Re: [PATCH v1 4/7] resource: Introduce resource_intersection() for overlapping resources

Quoted 9 lines · Rafael J. Wysocki
Quoted 7 lines · Andy Shevchenko

There will be at least one user that can utilize new helper. Provide the helper for future user and for wider use.

Deliberately avoid min()/max() macro as they are still parts of kernel.h which is quite a burden to be included here in order to avoid circular dependencies.

...

Quoted 1 line

I have the same comments as for patch [3/7].

Same answers as there :-)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#14 lore raw

PATCH 5/7 PCI/ACPI: Replace open coded variant of resource_union()

In reply to Andy Shevchenko

Since we have resource_union() helper, let's utilize it here.

Cc Kuppuswamy Sathyanarayanan <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/acpi/pci_root.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/acpi/pci_root.c +1 -3
index f90e841c59f5..2a6a741896de 100644
@@ -724,9 +724,7 @@ static void acpi_pci_root_validate_resources(struct device *dev,
 			 * our resources no longer match the ACPI _CRS, but
 			 * the kernel resource tree doesn't allow overlaps.
 			 */
-			if (resource_overlaps(res1, res2)) {
-				res2->start = min(res1->start, res2->start);
-				res2->end = max(res1->end, res2->end);
+			if (resource_union(res1, res2, res2)) {
 				dev_info(dev, "host bridge window expanded to %pR; %pR ignored\n",
 					 res2, res1);
 				free = true;
Signature · 1 line
2.28.0
maintainer Reviewed-by on v1 5/7
#15 lore raw

Re: [PATCH v1 5/7] PCI/ACPI: Replace open coded variant of resource_union()

Quoted 7 lines · Andy Shevchenko

Since we have resource_union() helper, let's utilize it here.

Cc Kuppuswamy Sathyanarayanan <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Quoted 22 lines
---
 drivers/acpi/pci_root.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/acpi/pci_root.c +1 -4
index f90e841c59f5..2a6a741896de 100644
@@ -724,9 +724,7 @@ static void acpi_pci_root_validate_resources(struct device *dev,
                         * our resources no longer match the ACPI _CRS, but
                         * the kernel resource tree doesn't allow overlaps.
                         */
-                       if (resource_overlaps(res1, res2)) {
-                               res2->start = min(res1->start, res2->start);
-                               res2->end = max(res1->end, res2->end);
+                       if (resource_union(res1, res2, res2)) {
                                dev_info(dev, "host bridge window expanded to %pR; %pR ignored\n",
                                         res2, res1);
                                free = true;
--

2.28.0

#16 lore raw

PATCH 6/7 PCI/ACPI: Fix description of @handle for acpi_is_root_bridge()

In reply to Andy Shevchenko

Fix description of handle parameter in documentation of acpi_is_root_bridge(). Otherwise we get the following warning:

CHECK drivers/acpi/pci_root.c
drivers/acpi/pci_root.c:71: warning: Function parameter or member 'handle' not described in 'acpi_is_root_bridge'

Cc Kuppuswamy Sathyanarayanan <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/acpi/pci_root.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/pci_root.c +1 -1
index 2a6a741896de..f723679954d7 100644
@@ -62,7 +62,7 @@ static DEFINE_MUTEX(osc_lock);
 
 /**
  * acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge
- * @handle - the ACPI CA node in question.
+ * @handle: the ACPI CA node in question.
  *
  * Note: we could make this API take a struct acpi_device * instead, but
  * for now, it's more convenient to operate on an acpi_handle.
Signature · 1 line
2.28.0
#17 lore raw

Re: [PATCH v1 6/7] PCI/ACPI: Fix description of @handle for acpi_is_root_bridge()

Quoted 6 lines · Andy Shevchenko

Fix description of handle parameter in documentation of acpi_is_root_bridge(). Otherwise we get the following warning:

CHECK drivers/acpi/pci_root.c
drivers/acpi/pci_root.c:71: warning: Function parameter or member 'handle' not described in 'acpi_is_root_bridge'

I'm not sure why this patch doesn't go by itself. It appears to be immediately applicable.

I'll apply it next week if Bjorn doesn't object.

Quoted 24 lines
Cc Kuppuswamy Sathyanarayanan <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/acpi/pci_root.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/pci_root.c +1 -2
index 2a6a741896de..f723679954d7 100644
@@ -62,7 +62,7 @@ static DEFINE_MUTEX(osc_lock);
 
 /**
  * acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge
- * @handle - the ACPI CA node in question.
+ * @handle: the ACPI CA node in question.
  *
  * Note: we could make this API take a struct acpi_device * instead, but
  * for now, it's more convenient to operate on an acpi_handle.
--

2.28.0

#18 lore raw

Re: [PATCH v1 6/7] PCI/ACPI: Fix description of @handle for acpi_is_root_bridge()

Quoted 11 lines · Rafael J. Wysocki
Quoted 6 lines · Andy Shevchenko

Fix description of handle parameter in documentation of acpi_is_root_bridge(). Otherwise we get the following warning:

CHECK drivers/acpi/pci_root.c
drivers/acpi/pci_root.c:71: warning: Function parameter or member 'handle' not described in 'acpi_is_root_bridge'

I'm not sure why this patch doesn't go by itself. It appears to be immediately applicable.

Just appears when I working on the rest of the series. Can be standalone if it makes more sense.

Quoted 1 line

I'll apply it next week if Bjorn doesn't object.

At least fine with me, thanks!

Quoted 24 lines
Quoted 24 lines
Cc Kuppuswamy Sathyanarayanan <[email protected]>
Cc Bjorn Helgaas <[email protected]>
---
 drivers/acpi/pci_root.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/pci_root.c +1 -2
index 2a6a741896de..f723679954d7 100644
@@ -62,7 +62,7 @@ static DEFINE_MUTEX(osc_lock);
 
 /**
  * acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge
- * @handle - the ACPI CA node in question.
+ * @handle: the ACPI CA node in question.
  *
  * Note: we could make this API take a struct acpi_device * instead, but
  * for now, it's more convenient to operate on an acpi_handle.
--

2.28.0

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#19 lore raw

PATCH 7/7 ACPI: watchdog: Replace open coded variant of resource_union()

In reply to Andy Shevchenko

Since we have resource_union() helper, let's utilize it here.

---
 drivers/acpi/acpi_watchdog.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/acpi/acpi_watchdog.c +1 -5
index 5c1e9ea43123..ca28183f4d13 100644
@@ -151,11 +151,7 @@ void __init acpi_watchdog_init(void)
 		found = false;
 		resource_list_for_each_entry(rentry, &resource_list) {
 			if (rentry->res->flags == res.flags &&
-			    resource_overlaps(rentry->res, &res)) {
-				if (res.start < rentry->res->start)
-					rentry->res->start = res.start;
-				if (res.end > rentry->res->end)
-					rentry->res->end = res.end;
+			    resource_union(rentry->res, &res, rentry->res)) {
 				found = true;
 				break;
 			}
Signature · 1 line
2.28.0
maintainer Reviewed-by on v1 7/7
#20 lore raw

Re: [PATCH v1 7/7] ACPI: watchdog: Replace open coded variant of resource_union()

Quoted 5 lines · Andy Shevchenko

Since we have resource_union() helper, let's utilize it here.

Quoted 24 lines
---
 drivers/acpi/acpi_watchdog.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/acpi/acpi_watchdog.c +1 -6
index 5c1e9ea43123..ca28183f4d13 100644
@@ -151,11 +151,7 @@ void __init acpi_watchdog_init(void)
                found = false;
                resource_list_for_each_entry(rentry, &resource_list) {
                        if (rentry->res->flags == res.flags &&
-                           resource_overlaps(rentry->res, &res)) {
-                               if (res.start < rentry->res->start)
-                                       rentry->res->start = res.start;
-                               if (res.end > rentry->res->end)
-                                       rentry->res->end = res.end;
+                           resource_union(rentry->res, &res, rentry->res)) {
                                found = true;
                                break;
                        }
--

2.28.0

#21 lore raw
In reply to Andy Shevchenko
Quoted 25 lines · Andy Shevchenko

Now we have for 'other' and 'type' variables

other   type    return
  0       0     REGION_DISJOINT
  0       x     REGION_INTERSECTS
  x       0     REGION_DISJOINT
  x       x     REGION_MIXED

Obviously it's easier to check 'type' for 0 first instead of currently checked 'other'.

---
 kernel/resource.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
kernel/resource.c +0 -0
index 841737bbda9e..70575a61bf20 100644
@@ -554,13 +554,10 @@ int region_intersects(resource_size_t start, size_t size, unsigned long flags,
        }
        read_unlock(&resource_lock);
 

kernel/resource.c int region_intersects(resource_size_t start, size_t size, unsigned long flags, · line 560

Quoted 10 lines
kernel/resource.c +3 -6
-       if (other == 0)
-               return type ? REGION_INTERSECTS : REGION_DISJOINT;
+       if (type == 0)
+               return REGION_DISJOINT;
 
-       if (type)
-               return REGION_MIXED;
-
-       return REGION_DISJOINT;
+       return (other == 0) ? REGION_INTERSECTS : REGION_MIXED;

The parens are not needed here.

Also I would do

if (other == 0)

       REGION_INTERSECTS;

return REGION_MIXED;

Quoted 6 lines
kernel/resource.c +0 -1
 }
 EXPORT_SYMBOL_GPL(region_intersects);
 
--

2.28.0

#22 lore raw
Quoted 13 lines · Rafael J. Wysocki
Quoted 11 lines · Andy Shevchenko

Now we have for 'other' and 'type' variables

other   type    return
  0       0     REGION_DISJOINT
  0       x     REGION_INTERSECTS
  x       0     REGION_DISJOINT
  x       x     REGION_MIXED

Obviously it's easier to check 'type' for 0 first instead of currently checked 'other'.

...

Quoted 3 lines
Quoted 1 line

+ return (other == 0) ? REGION_INTERSECTS : REGION_MIXED;

The parens are not needed here.

Right.

Quoted 6 lines

Also I would do

if (other == 0)

       REGION_INTERSECTS;

return REGION_MIXED;

Works for me, I'll update in v2.

Signature · 2 lines
With Best Regards,
Andy Shevchenko