From 5b036330b2fdde9ce677ae2164dbbc56a61cb4f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Okan=20T=C3=BCm=C3=BCkl=C3=BC?= <117488504+Okan-tumuklu@users.noreply.github.com> Date: Mon, 30 Sep 2024 01:23:29 +0300 Subject: [PATCH] Update core.c 1:The control flow was simplified by using else if statements instead of goto structure. 2:Error conditions are handled more clearly. 3:The device_unlock call at the end of the function is guaranteed in all cases. --- net/nfc/core.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/net/nfc/core.c b/net/nfc/core.c index e58dc6405054..4e8f01145c37 100644 --- a/net/nfc/core.c +++ b/net/nfc/core.c @@ -40,27 +40,19 @@ int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name) if (dev->shutting_down) { rc = -ENODEV; - goto error; - } - - if (dev->dev_up) { + }else if (dev->dev_up) { rc = -EBUSY; - goto error; - } - - if (!dev->ops->fw_download) { + }else if (!dev->ops->fw_download) { rc = -EOPNOTSUPP; - goto error; - } + }else{ + dev->fw_download_in_progress = true; + rc = dev->ops->fw_download(dev, firmware_name); + if (rc) + dev->fw_download_in_progress = false; + } - dev->fw_download_in_progress = true; - rc = dev->ops->fw_download(dev, firmware_name); - if (rc) - dev->fw_download_in_progress = false; - -error: - device_unlock(&dev->dev); - return rc; + device_unlock(&dev->dev); + return rc; } /**