All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block/sed-opal: Introduce free_opal_dev to free the structure and clean up state
@ 2017-02-17 17:25 Scott Bauer
  2017-02-18 16:14 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Scott Bauer @ 2017-02-17 17:25 UTC (permalink / raw)
  To: linux-block; +Cc: axboe, keith.busch, jonathan.derrick, hch, Scott Bauer

Before we free the opal structure we need to clean up any saved
locking ranges that the user had told us to unlock from a suspend.
Also fixup a list_for_each to list_for_each_safe in the save path.

Signed-off-by: Scott Bauer <scott.bauer@intel.com>
---
 block/sed-opal.c         | 33 +++++++++++++++++++++++++++++++--
 include/linux/sed-opal.h |  5 +++++
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/block/sed-opal.c b/block/sed-opal.c
index d1c52ba..1be5c72 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -988,9 +988,9 @@ static int start_opal_session_cont(struct opal_dev *dev)
 static void add_suspend_info(struct opal_dev *dev,
 			     struct opal_suspend_data *sus)
 {
-	struct opal_suspend_data *iter;
+	struct opal_suspend_data *iter, *next;
 
-	list_for_each_entry(iter, &dev->unlk_lst, node) {
+	list_for_each_entry_safe(iter, next, &dev->unlk_lst, node) {
 		if (iter->lr == sus->lr) {
 			list_del(&iter->node);
 			kfree(iter);
@@ -2014,6 +2014,28 @@ static int check_opal_support(struct opal_dev *dev)
 	return ret;
 }
 
+static void clean_opal_dev(struct opal_dev *dev)
+{
+
+	struct opal_suspend_data *suspend, *next;
+
+	mutex_lock(&dev->dev_lock);
+	list_for_each_entry_safe(suspend, next, &dev->unlk_lst, node) {
+		list_del(&suspend->node);
+		kfree(suspend);
+	}
+	mutex_unlock(&dev->dev_lock);
+}
+
+void free_opal_dev(struct opal_dev *dev)
+{
+	if (!dev)
+		return;
+	clean_opal_dev(dev);
+	kfree(dev);
+}
+EXPORT_SYMBOL(free_opal_dev);
+
 struct opal_dev *init_opal_dev(void *data, sec_send_recv *send_recv)
 {
 	struct opal_dev *dev;
@@ -2193,6 +2215,13 @@ static int opal_reverttper(struct opal_dev *dev, struct opal_key *opal)
 	dev->func_data[1] = opal;
 	ret = next(dev);
 	mutex_unlock(&dev->dev_lock);
+
+	/* If we succesfully reverted lets clean
+	 * any saved locking ranges.
+	 */
+	if (!ret)
+		clean_opal_dev(dev);
+
 	return ret;
 }
 
diff --git a/include/linux/sed-opal.h b/include/linux/sed-opal.h
index deee23d..04b124f 100644
--- a/include/linux/sed-opal.h
+++ b/include/linux/sed-opal.h
@@ -27,6 +27,7 @@ typedef int (sec_send_recv)(void *data, u16 spsp, u8 secp, void *buffer,
 		size_t len, bool send);
 
 #ifdef CONFIG_BLK_SED_OPAL
+void free_opal_dev(struct opal_dev *dev);
 bool opal_unlock_from_suspend(struct opal_dev *dev);
 struct opal_dev *init_opal_dev(void *data, sec_send_recv *send_recv);
 int sed_ioctl(struct opal_dev *dev, unsigned int cmd, void __user *ioctl_ptr);
@@ -51,6 +52,10 @@ static inline bool is_sed_ioctl(unsigned int cmd)
 	return false;
 }
 #else
+static inline void free_opal_dev(struct opal_dev *dev)
+{
+}
+
 static inline bool is_sed_ioctl(unsigned int cmd)
 {
 	return false;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] block/sed-opal: Introduce free_opal_dev to free the structure and clean up state
  2017-02-17 17:25 [PATCH] block/sed-opal: Introduce free_opal_dev to free the structure and clean up state Scott Bauer
@ 2017-02-18 16:14 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2017-02-18 16:14 UTC (permalink / raw)
  To: Scott Bauer; +Cc: linux-block, axboe, keith.busch, jonathan.derrick, hch

On Fri, Feb 17, 2017 at 10:25:13AM -0700, Scott Bauer wrote:
> Before we free the opal structure we need to clean up any saved
> locking ranges that the user had told us to unlock from a suspend.
> Also fixup a list_for_each to list_for_each_safe in the save path.
> 
> Signed-off-by: Scott Bauer <scott.bauer@intel.com>

This looks fine to me, but I think the fix to add_suspend_info
should be a separate patch:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-02-18 16:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-17 17:25 [PATCH] block/sed-opal: Introduce free_opal_dev to free the structure and clean up state Scott Bauer
2017-02-18 16:14 ` Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.