lib: logic_pio: Add logic_pio_unregister_range() [Linux 4.19.70]

This Linux kernel change "lib: logic_pio: Add logic_pio_unregister_range()" is included in the Linux 4.19.70 release. This change is authored by John Garry <john.garry [at] huawei.com> on Tue Jul 30 21:29:54 2019 +0800. The commit for this change in Linux stable tree is c4616a9 (patch) which is from upstream commit b884e2d. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream b884e2d.

lib: logic_pio: Add logic_pio_unregister_range()

commit b884e2de2afc68ce30f7093747378ef972dde253 upstream.

Add a function to unregister a logical PIO range.

Logical PIO space can still be leaked when unregistering certain
LOGIC_PIO_CPU_MMIO regions, but this acceptable for now since there are no
callers to unregister LOGIC_PIO_CPU_MMIO regions, and the logical PIO
region allocation scheme would need significant work to improve this.

Cc: stable@vger.kernel.org
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Wei Xu <xuwei5@hisilicon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

There are 15 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 include/linux/logic_pio.h |  1 +
 lib/logic_pio.c           | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/include/linux/logic_pio.h b/include/linux/logic_pio.h
index cbd9d84..88e1e63 100644
--- a/include/linux/logic_pio.h
+++ b/include/linux/logic_pio.h
@@ -117,6 +117,7 @@ struct logic_pio_host_ops {
 unsigned long logic_pio_trans_hwaddr(struct fwnode_handle *fwnode,
            resource_size_t hw_addr, resource_size_t size);
 int logic_pio_register_range(struct logic_pio_hwaddr *newrange);
+void logic_pio_unregister_range(struct logic_pio_hwaddr *range);
 resource_size_t logic_pio_to_hwaddr(unsigned long pio);
 unsigned long logic_pio_trans_cpuaddr(resource_size_t hw_addr);

diff --git a/lib/logic_pio.c b/lib/logic_pio.c
index d0165c8..9050275 100644
--- a/lib/logic_pio.c
+++ b/lib/logic_pio.c
@@ -99,6 +99,20 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range)
 }

 /**
+ * logic_pio_unregister_range - unregister a logical PIO range for a host
+ * @range: pointer to the IO range which has been already registered.
+ *
+ * Unregister a previously-registered IO range node.
+ */
+void logic_pio_unregister_range(struct logic_pio_hwaddr *range)
+{
+   mutex_lock(&io_range_mutex);
+   list_del_rcu(&range->list);
+   mutex_unlock(&io_range_mutex);
+   synchronize_rcu();
+}
+
+/**
  * find_io_range_by_fwnode - find logical PIO range for given FW node
  * @fwnode: FW node handle associated with logical PIO range
  *

Leave a Reply

Your email address will not be published. Required fields are marked *