summaryrefslogtreecommitdiffstats
path: root/block/sed-opal.c
diff options
context:
space:
mode:
authorScott Bauer <scott.bauer@intel.com>2017-02-22 12:15:06 -0500
committerJens Axboe <axboe@fb.com>2017-02-23 13:55:41 -0500
commit7d6d15789d69856f1c5405e106a773c87277eb8c (patch)
tree7ae43ae226e85c4db783756a3c07f14ed1dbd0cf /block/sed-opal.c
parent124298bd03acebd9c9da29a794718aca31bec1f7 (diff)
block/sed-opal: Introduce free_opal_dev to free the structure and clean up state
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. Signed-off-by: Scott Bauer <scott.bauer@intel.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block/sed-opal.c')
-rw-r--r--block/sed-opal.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/block/sed-opal.c b/block/sed-opal.c
index 893557554cc5..020bf3e28e38 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -1987,6 +1987,28 @@ static int check_opal_support(struct opal_dev *dev)
1987 return ret; 1987 return ret;
1988} 1988}
1989 1989
1990static void clean_opal_dev(struct opal_dev *dev)
1991{
1992
1993 struct opal_suspend_data *suspend, *next;
1994
1995 mutex_lock(&dev->dev_lock);
1996 list_for_each_entry_safe(suspend, next, &dev->unlk_lst, node) {
1997 list_del(&suspend->node);
1998 kfree(suspend);
1999 }
2000 mutex_unlock(&dev->dev_lock);
2001}
2002
2003void free_opal_dev(struct opal_dev *dev)
2004{
2005 if (!dev)
2006 return;
2007 clean_opal_dev(dev);
2008 kfree(dev);
2009}
2010EXPORT_SYMBOL(free_opal_dev);
2011
1990struct opal_dev *init_opal_dev(void *data, sec_send_recv *send_recv) 2012struct opal_dev *init_opal_dev(void *data, sec_send_recv *send_recv)
1991{ 2013{
1992 struct opal_dev *dev; 2014 struct opal_dev *dev;
@@ -2141,6 +2163,14 @@ static int opal_reverttper(struct opal_dev *dev, struct opal_key *opal)
2141 setup_opal_dev(dev, revert_steps); 2163 setup_opal_dev(dev, revert_steps);
2142 ret = next(dev); 2164 ret = next(dev);
2143 mutex_unlock(&dev->dev_lock); 2165 mutex_unlock(&dev->dev_lock);
2166
2167 /*
2168 * If we successfully reverted lets clean
2169 * any saved locking ranges.
2170 */
2171 if (!ret)
2172 clean_opal_dev(dev);
2173
2144 return ret; 2174 return ret;
2145} 2175}
2146 2176