Update core.c
Subsystems (3)
PATCH 1/1 Update core.c
From: Okan Tümüklü <[email protected]>
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(-)
net/nfc/core.c +10 -18
@@ -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; - } - - dev->fw_download_in_progress = true; - rc = dev->ops->fw_download (dev, firmware_name); -if (rc) - dev->fw_download_in_progress = false; + }else { + 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; }/**
Signature · 1 line
2.39.5
Quoted 7 lines · Okan Tumuklu
From: Okan Tümüklü <[email protected]>
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_unlockcall at the end of the function is guaranteed in all cases.
Write a paragraph - don't use bullet lists.
Please refer to submitting patches for details on how to write shortlogs and change logs.
"Update core.c" with what? Write a better short log.
Why do you this [email protected] in the list? It will complain every time someone responds to this thread. This is not how patches are sent. Refer to documents in the kernel repo on how to send patches.
You are missing net maintainers and mailing lists.
Include all reviewers - run get_maintainers.pl
Quoted 10 lines
--- net/nfc/core.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-)net/nfc/core.c +0
-0@@ -40,27 +40,19 @@ int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name)
net/nfc/core.c int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name) · line 49
Quoted 10 lines
net/nfc/core.c +1
-6if (dev->shutting_down) { rc = -ENODEV ; - goto error; - } - -if (dev->dev_up) { + }else if (dev->dev_up) { rc = -EBUSY ; - goto error; - }
Did you run checkpack script on this patch? There are a few coding style errors.
Quoted 16 lines
net/nfc/core.c +6
-9- -if (!dev->ops->fw_download) { + }else if (!dev->ops->fw_download) { rc = -EOPNOTSUPP ; - goto error; - } - - dev->fw_download_in_progress = true; - rc = dev->ops->fw_download (dev, firmware_name); -if (rc) - dev->fw_download_in_progress = false; + }else { + dev->fw_download_in_progress = true; + rc = dev->ops->fw_download (dev, firmware_name); +if (rc) + dev->fw_download_in_progress = false;
net/nfc/core.c int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name) · line 58
Quoted 10 lines
net/nfc/core.c +3
-3+ } -error: -device_unlock (&dev->dev); -return rc; +device_unlock (&dev->dev); +return rc; }/**
thanks,
-- Shuah
Quoted 16 lines · Shuah Khan
Quoted 7 lines · Okan Tumuklu
From: Okan Tümüklü <[email protected]>
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_unlockcall at the end of the function is guaranteed in all cases.Write a paragraph - don't use bullet lists.
Please refer to submitting patches for details on how to write shortlogs and change logs.
"Update
core.c" with what? Write a better short log.
Quoted 8 lines
Why do you this [email protected] in the list? It will complain every time someone responds to this thread. This is not how patches are sent. Refer to documents in the kernel repo on how to send patches.
You are missing net maintainers and mailing lists.
Include all reviewers - run get_maintainers.pl
And consider whether the patch is a trip up the garden path, or actually worthwhile.
Why would if/else be better than a goto?
What's unclear about the current error handling?
In what case is the device_unlock() call missed?
Maybe there's some value in using the scoped cleanup here (do netdev folks even want scoped cleanup?), but this patch may not be worth the time spent improving it. +CC Krzk and netdev, before more time is potentially wasted here.
Cheers,
Conor.
Quoted 51 lines
Quoted 10 lines
--- net/nfc/core.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-)net/nfc/core.c +0
-0net/nfc/core.c int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name) · line 48
Quoted 10 lines
net/nfc/core.c +1
-6@@ -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; - }Did you run checkpack script on this patch? There are a few coding style errors.
Quoted 14 lines
net/nfc/core.c +4
-9- -if (!dev->ops->fw_download) { + }else if (!dev->ops->fw_download) { rc = -EOPNOTSUPP ; - goto error; - } - - dev->fw_download_in_progress = true; - rc = dev->ops->fw_download (dev, firmware_name); -if (rc) - dev->fw_download_in_progress = false; + }else { + dev->fw_download_in_progress = true; + rc = dev->ops->fw_download (dev, firmware_name);net/nfc/core.c int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name) · line 58
Quoted 10 lines
net/nfc/core.c +5
-3+if (rc) + dev->fw_download_in_progress = false; + } -error: -device_unlock (&dev->dev); -return rc; +device_unlock (&dev->dev); +return rc; }/** thanks,
-- Shuah
Jakub Kicinski
maintainerQuoted 1 line · On Mon, 30 Sep 2024 23:20:45 +0100 Conor Dooley wrote:
(do netdev folks even want scoped cleanup?),
Since I have it handy... :)
Quoting documentation:
Using device-managed and cleanup.h constructs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Netdev remains skeptical about promises of all "auto-cleanup" APIs, including even ``devm_`` helpers, historically. They are not the preferred style of implementation, merely an acceptable one.
Use of ``guard()`` is discouraged within any function longer than 20 lines, ``scoped_guard()`` is considered more readable. Using normal lock/unlock is still (weakly) preferred.
Low level cleanup constructs (such as ``__free()``) can be used when building APIs and helpers, especially scoped iterators. However, direct use of ``__free()`` within networking core and drivers is discouraged. Similar guidance applies to declaring variables mid-function.
Quoted 18 lines · Jakub Kicinski
Quoted 1 line · On Mon, 30 Sep 2024 23:20:45 +0100 Conor Dooley wrote:
(do netdev folks even want scoped cleanup?),
Since I have it handy... :)
Quoting documentation:
Using device-managed and
cleanup.hconstructs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Netdev remains skeptical about promises of all "auto-cleanup" APIs, including even ``devm_`` helpers, historically. They are not the preferred style of implementation, merely an acceptable one.
Use of ``guard()`` is discouraged within any function longer than 20 lines, ``scoped_guard()`` is considered more readable. Using normal lock/unlock is still (weakly) preferred.
Quoted 6 lines
Low level cleanup constructs (such as ``__free()``) can be used when building APIs and helpers, especially scoped iterators. However, direct use of ``__free()`` within networking core and drivers is discouraged. Similar guidance applies to declaring variables mid-function.
Thank you. This will be helpful for new developers such as this patch submitter to understand the scope of cleanup patches.
thanks,
-- Shuah
Quoted 18 lines · Jakub Kicinski
Quoted 1 line · On Mon, 30 Sep 2024 23:20:45 +0100 Conor Dooley wrote:
(do netdev folks even want scoped cleanup?),
Since I have it handy... :)
Quoting documentation:
Using device-managed and
cleanup.hconstructs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Netdev remains skeptical about promises of all "auto-cleanup" APIs, including even ``devm_`` helpers, historically. They are not the preferred style of implementation, merely an acceptable one.
Use of ``guard()`` is discouraged within any function longer than 20 lines, ``scoped_guard()`` is considered more readable. Using normal lock/unlock is still (weakly) preferred.
Quoted 6 lines
Low level cleanup constructs (such as ``__free()``) can be used when building APIs and helpers, especially scoped iterators. However, direct use of ``__free()`` within networking core and drivers is discouraged. Similar guidance applies to declaring variables mid-function.
Bravo. Mind if that gets stolen for VFS as well?
Jakub Kicinski
maintainerQuoted 13 lines · On Wed, 2 Oct 2024 23:21:45 +0100 Al Viro wrote:
Quoted 13 lines
Quoting documentation:
Using device-managed and
cleanup.hconstructs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Netdev remains skeptical about promises of all "auto-cleanup" APIs, including even ``devm_`` helpers, historically. They are not the preferred style of implementation, merely an acceptable one.
Use of ``guard()`` is discouraged within any function longer than 20 lines, ``scoped_guard()`` is considered more readable. Using normal lock/unlock is still (weakly) preferred.
Quoted 8 lines
Quoted 6 lines
Low level cleanup constructs (such as ``__free()``) can be used when building APIs and helpers, especially scoped iterators. However, direct use of ``__free()`` within networking core and drivers is discouraged. Similar guidance applies to declaring variables mid-function.
Bravo. Mind if that gets stolen for VFS as well?
Not at all. Slight preference towards not mentioning that you got it from us, tho, lest we attract unwanted attention :)
Quoted 1 line · Okan Tumuklu
From: Okan Tümüklü <[email protected]>
Please use your real email address and don't forget to add Signed-off-by:
trailer (git commit -s does it for you).
Quoted 6 lines
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_unlockcall at the end of the function is guaranteed in all cases.
Split logical changes into separate patches - in a patch set.
Thanks.
Signature · 1 line
An old man doll... just what I always wanted! - Clara