2013-09-23 09:56:38

by Wei Yongjun

[permalink] [raw]
Subject: [PATCH] NFC: nfcsim: fix the error handle in nfcsim_init()

From: Wei Yongjun <[email protected]>

Add the missing unregister/free NFC device and destroy_workqueue()
before return in the error handling case.

Signed-off-by: Wei Yongjun <[email protected]>
---
drivers/nfc/nfcsim.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/nfc/nfcsim.c b/drivers/nfc/nfcsim.c
index 9a53f13..a4a2286 100644
--- a/drivers/nfc/nfcsim.c
+++ b/drivers/nfc/nfcsim.c
@@ -497,15 +497,13 @@ static int __init nfcsim_init(void)
dev0 = nfcsim_init_dev();
if (IS_ERR(dev0)) {
rc = PTR_ERR(dev0);
- goto exit;
+ goto exit_init_dev0;
}

dev1 = nfcsim_init_dev();
if (IS_ERR(dev1)) {
- kfree(dev0);
-
rc = PTR_ERR(dev1);
- goto exit;
+ goto exit_init_dev1;
}

dev0->peer_dev = dev1;
@@ -513,11 +511,14 @@ static int __init nfcsim_init(void)

pr_debug("NFCsim " NFCSIM_VERSION " initialized\n");

- rc = 0;
+ return 0;
+
+exit_init_dev1:
+ nfcsim_free_device(dev0);
+exit_init_dev0:
+ destroy_workqueue(wq);
exit:
- if (rc)
- pr_err("Failed to initialize nfcsim driver (%d)\n",
- rc);
+ pr_err("Failed to initialize nfcsim driver (%d)\n", rc);

return rc;
}