Skip to content

Commit 7d6d157

Browse files
Scott Baueraxboe
authored andcommitted
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>
1 parent 124298b commit 7d6d157

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

block/sed-opal.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,6 +1987,28 @@ static int check_opal_support(struct opal_dev *dev)
19871987
return ret;
19881988
}
19891989

1990+
static 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+
2003+
void free_opal_dev(struct opal_dev *dev)
2004+
{
2005+
if (!dev)
2006+
return;
2007+
clean_opal_dev(dev);
2008+
kfree(dev);
2009+
}
2010+
EXPORT_SYMBOL(free_opal_dev);
2011+
19902012
struct opal_dev *init_opal_dev(void *data, sec_send_recv *send_recv)
19912013
{
19922014
struct opal_dev *dev;
@@ -2141,6 +2163,14 @@ static int opal_reverttper(struct opal_dev *dev, struct opal_key *opal)
21412163
setup_opal_dev(dev, revert_steps);
21422164
ret = next(dev);
21432165
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+
21442174
return ret;
21452175
}
21462176

include/linux/sed-opal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ typedef int (sec_send_recv)(void *data, u16 spsp, u8 secp, void *buffer,
2727
size_t len, bool send);
2828

2929
#ifdef CONFIG_BLK_SED_OPAL
30+
void free_opal_dev(struct opal_dev *dev);
3031
bool opal_unlock_from_suspend(struct opal_dev *dev);
3132
struct opal_dev *init_opal_dev(void *data, sec_send_recv *send_recv);
3233
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)
5152
return false;
5253
}
5354
#else
55+
static inline void free_opal_dev(struct opal_dev *dev)
56+
{
57+
}
58+
5459
static inline bool is_sed_ioctl(unsigned int cmd)
5560
{
5661
return false;

0 commit comments

Comments
 (0)