Inter-revision diff: patch 6

Comparing v3 (message) to v8 (message)

--- v3
+++ v8
@@ -1,55 +1,51 @@
 Define helpers to allocate/free VAS window objects. These will
 be used in follow-on patches when opening/closing windows.
 
+Changelog[v8]:
+	- [Michael Ellerman] Make some functions static; retry if
+	  ida_get_new() fails with EAGAIN; fix a couple of leak in ids
+
 Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
 ---
- drivers/misc/vas/vas-window.c | 74 +++++++++++++++++++++++++++++++++++++++++--
- 1 file changed, 72 insertions(+), 2 deletions(-)
+ arch/powerpc/platforms/powernv/vas-window.c | 73 +++++++++++++++++++++++++++++
+ 1 file changed, 73 insertions(+)
 
-diff --git a/drivers/misc/vas/vas-window.c b/drivers/misc/vas/vas-window.c
-index edf5c9f..9233bf5 100644
---- a/drivers/misc/vas/vas-window.c
-+++ b/drivers/misc/vas/vas-window.c
-@@ -119,7 +119,7 @@ static void unmap_wc_mmio_bars(struct vas_window *window)
-  * OS/User Window Context (UWC) MMIO Base Address Region for the given window.
-  * Map these bus addresses and save the mapped kernel addresses in @window.
-  */
--int map_wc_mmio_bars(struct vas_window *window)
-+static int map_wc_mmio_bars(struct vas_window *window)
- {
- 	int len;
- 	uint64_t start;
-@@ -472,8 +472,78 @@ int init_winctx_regs(struct vas_window *window, struct vas_winctx *winctx)
+diff --git a/arch/powerpc/platforms/powernv/vas-window.c b/arch/powerpc/platforms/powernv/vas-window.c
+index 68dfe53..bfc9dba 100644
+--- a/arch/powerpc/platforms/powernv/vas-window.c
++++ b/arch/powerpc/platforms/powernv/vas-window.c
+@@ -485,6 +485,79 @@ int init_winctx_regs(struct vas_window *window, struct vas_winctx *winctx)
  	return 0;
  }
  
--/* stub for now */
-+DEFINE_SPINLOCK(vas_ida_lock);
++static DEFINE_SPINLOCK(vas_ida_lock);
 +
-+void vas_release_window_id(struct ida *ida, int winid)
++static void vas_release_window_id(struct ida *ida, int winid)
 +{
 +	spin_lock(&vas_ida_lock);
 +	ida_remove(ida, winid);
 +	spin_unlock(&vas_ida_lock);
 +}
 +
-+int vas_assign_window_id(struct ida *ida)
++static int vas_assign_window_id(struct ida *ida)
 +{
 +	int rc, winid;
 +
-+	rc = ida_pre_get(ida, GFP_KERNEL);
-+	if (!rc)
-+		return -EAGAIN;
++	do {
++		rc = ida_pre_get(ida, GFP_KERNEL);
++		if (!rc)
++			return -EAGAIN;
 +
-+	spin_lock(&vas_ida_lock);
-+	rc = ida_get_new_above(ida, 0, &winid);
-+	spin_unlock(&vas_ida_lock);
++		spin_lock(&vas_ida_lock);
++		rc = ida_get_new(ida, &winid);
++		spin_unlock(&vas_ida_lock);
++	} while (rc == -EAGAIN);
 +
 +	if (rc)
 +		return rc;
 +
-+	if (winid > VAS_MAX_WINDOWS_PER_CHIP) {
-+		pr_err("VAS: Too many (%d) open windows\n", winid);
++	if (winid > VAS_WINDOWS_PER_CHIP) {
++		pr_err("Too many (%d) open windows\n", winid);
 +		vas_release_window_id(ida, winid);
 +		return -EAGAIN;
 +	}
@@ -57,47 +53,46 @@
 +	return winid;
 +}
 +
-+static void vas_window_free(struct vas_window *window)
++void vas_window_free(struct vas_window *window)
 +{
-+	unmap_wc_mmio_bars(window);
-+	kfree(window->paste_addr_name);
++	int winid = window->winid;
++	struct vas_instance *vinst = window->vinst;
++
++	unmap_winctx_mmio_bars(window);
 +	kfree(window);
++
++	vas_release_window_id(&vinst->ida, winid);
 +}
 +
-+static struct vas_window *vas_window_alloc(struct vas_instance *vinst, int id)
++struct vas_window *vas_window_alloc(struct vas_instance *vinst)
 +{
++	int winid;
 +	struct vas_window *window;
++
++	winid = vas_assign_window_id(&vinst->ida);
++	if (winid < 0)
++		return ERR_PTR(winid);
 +
 +	window = kzalloc(sizeof(*window), GFP_KERNEL);
 +	if (!window)
-+		return NULL;
++		goto out_free;
 +
 +	window->vinst = vinst;
-+	window->winid = id;
++	window->winid = winid;
 +
-+	if (map_wc_mmio_bars(window))
++	if (map_winctx_mmio_bars(window))
 +		goto out_free;
 +
 +	return window;
 +
 +out_free:
 +	kfree(window);
-+	return NULL;
++	vas_release_window_id(&vinst->ida, winid);
++	return ERR_PTR(-ENOMEM);
 +}
 +
- int vas_window_reset(struct vas_instance *vinst, int winid)
+ /* stub for now */
+ int vas_win_close(struct vas_window *window)
  {
-+	struct vas_window *window;
-+
-+	window = vas_window_alloc(vinst, winid);
-+	if (!window)
-+		return -ENOMEM;
-+
-+	reset_window_regs(window);
-+
-+	vas_window_free(window);
-+
- 	return 0;
- }
 -- 
 2.7.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help