Commit 1f14b57f authored by John Allen's avatar John Allen Committed by Herbert Xu

crypto: ccp - Cleanup misc_dev on sev_exit()

Explicitly free and clear misc_dev in sev_exit(). Since devm_kzalloc()
associates misc_dev with the first device that gets probed, change from
devm_kzalloc() to kzalloc() and explicitly free memory in sev_exit() as
the first device probed is not guaranteed to be the last device released.
To ensure that the variable gets properly set to NULL, remove the local
definition of misc_dev.

Fixes: 200664d5 ("crypto: ccp: Add Secure Encrypted Virtualization (SEV) command support")
Signed-off-by: default avatarJohn Allen <john.allen@amd.com>
Acked-by: default avatarTom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 7548bf8c
...@@ -896,9 +896,9 @@ EXPORT_SYMBOL_GPL(sev_guest_df_flush); ...@@ -896,9 +896,9 @@ EXPORT_SYMBOL_GPL(sev_guest_df_flush);
static void sev_exit(struct kref *ref) static void sev_exit(struct kref *ref)
{ {
struct sev_misc_dev *misc_dev = container_of(ref, struct sev_misc_dev, refcount);
misc_deregister(&misc_dev->misc); misc_deregister(&misc_dev->misc);
kfree(misc_dev);
misc_dev = NULL;
} }
static int sev_misc_init(struct sev_device *sev) static int sev_misc_init(struct sev_device *sev)
...@@ -916,7 +916,7 @@ static int sev_misc_init(struct sev_device *sev) ...@@ -916,7 +916,7 @@ static int sev_misc_init(struct sev_device *sev)
if (!misc_dev) { if (!misc_dev) {
struct miscdevice *misc; struct miscdevice *misc;
misc_dev = devm_kzalloc(dev, sizeof(*misc_dev), GFP_KERNEL); misc_dev = kzalloc(sizeof(*misc_dev), GFP_KERNEL);
if (!misc_dev) if (!misc_dev)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment