NFC: cooperation with runtime PM
Subsystems (3)
PATCH 1/1 NFC: cooperation with runtime PM
We cannot rely on the underlying hardware to do correct runtime PM. NFC core needs to get PM reference while a device is operational, lest it be suspended when it is supposed to be waiting for a target to come into range.
--- net/nfc/core.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
net/nfc/core.c +18 -1
@@ -15,6 +15,7 @@#include <linux/slab.h> #include <linux/rfkill.h> #include <linux/nfc.h> +#include <linux/pm_runtime.h> #include <net/genetlink.h>
@@ -37,6 +38,7 @@ int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name)pr_debug ("%s do firmware %s\n" ,dev_name (&dev->dev), firmware_name);device_lock (&dev->dev); +pm_runtime_get_sync (&dev->dev);if (!device_is_registered (&dev->dev)) { rc = -ENODEV ;
@@ -58,7 +60,10 @@ int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name)if (rc) dev->fw_download_in_progress = false; +device_unlock (&dev->dev); +return rc; error: +pm_runtime_put (&dev->dev);device_unlock (&dev->dev);return rc; }
@@ -73,9 +78,13 @@ int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name)int nfc_fw_download_done (struct nfc_dev *dev,const char *firmware_name,u32 result) { +int rv; + dev->fw_download_in_progress = false; -return nfc_genl_fw_download_done (dev, firmware_name, result); + rv =nfc_genl_fw_download_done (dev, firmware_name, result); +pm_runtime_put (&dev->dev); +return rv; }EXPORT_SYMBOL (nfc_fw_download_done);
@@ -93,6 +102,7 @@ int nfc_dev_up(struct nfc_dev *dev)pr_debug ("dev_name=%s\n" ,dev_name (&dev->dev));device_lock (&dev->dev); +pm_runtime_get_sync (&dev->dev);if (dev->rfkill &&rfkill_blocked (dev->rfkill)) { rc = -ERFKILL ;
@@ -124,7 +134,11 @@ int nfc_dev_up(struct nfc_dev *dev)if (dev->ops->discover_se && dev->ops->discover_se (dev))pr_err ("SE discovery failed\n" ); +device_unlock (&dev->dev); +return rc; + error: +pm_runtime_put (&dev->dev);device_unlock (&dev->dev);return rc; }
@@ -161,6 +175,9 @@ int nfc_dev_down(struct nfc_dev *dev) dev->ops->dev_down (dev); dev->dev_up = false; +pm_runtime_put (&dev->dev); +device_unlock (&dev->dev); +return rc; error:device_unlock (&dev->dev);
Signature · 1 line
2.26.2
Hi,
Thanks for the patch. Few notes:
Quoted 5 lines · Oliver Neukum
We cannot rely on the underlying hardware to do correct runtime PM. NFC core needs to get PM reference while a device is operational, lest it be suspended when it is supposed to be waiting for a target to come into range.
Your word wrapping is unusually early - please wrap the commit msg as in coding style (so around 75-character).
https://elixir.bootlin.com/linux/latest/source/Documentation/process/submitting-patches.rst#L578
Quoted 19 lines
Signed-off-by Oliver Neukum <[email protected]>--- net/nfc/core.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)net/nfc/core.c +1
-0@@ -15,6 +15,7 @@#include <linux/slab.h> #include <linux/rfkill.h> #include <linux/nfc.h> +#include <linux/pm_runtime.h> #include <net/genetlink.h>
net/nfc/core.c int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name) · line 41
Quoted 4 lines
net/nfc/core.c +1
-0@@ -37,6 +38,7 @@ int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name)pr_debug ("%s do firmware %s\n" ,dev_name (&dev->dev), firmware_name);device_lock (&dev->dev); +pm_runtime_get_sync (&dev->dev);
This can fail. Probably you wanted pm_runtime_resume_and_get() here.
net/nfc/core.c int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name) · line 61
Quoted 6 lines
net/nfc/core.c +0
-0if (!device_is_registered (&dev->dev)) { rc = -ENODEV ;@@ -58,7 +60,10 @@ int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name)if (rc) dev->fw_download_in_progress = false;
goto error
net/nfc/core.c int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name) · line 63
Quoted 3 lines
net/nfc/core.c +2
-0+device_unlock (&dev->dev); +return rc;
Since last rc cannot be != 0, return 0
Blank line
net/nfc/core.c int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name) · line 81
Quoted 10 lines
net/nfc/core.c +2
-0error: +pm_runtime_put (&dev->dev);device_unlock (&dev->dev);return rc; }@@ -73,9 +78,13 @@ int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name)int nfc_fw_download_done (struct nfc_dev *dev,const char *firmware_name,u32 result) { +int rv;
"int rc"
Quoted 11 lines
net/nfc/core.c +4
-1+ dev->fw_download_in_progress = false; -return nfc_genl_fw_download_done (dev, firmware_name, result); + rv =nfc_genl_fw_download_done (dev, firmware_name, result); +pm_runtime_put (&dev->dev); +return rv; }EXPORT_SYMBOL (nfc_fw_download_done);
net/nfc/core.c int nfc_dev_up(struct nfc_dev *dev) · line 105
Quoted 4 lines
net/nfc/core.c +1
-0@@ -93,6 +102,7 @@ int nfc_dev_up(struct nfc_dev *dev)pr_debug ("dev_name=%s\n" ,dev_name (&dev->dev));device_lock (&dev->dev); +pm_runtime_get_sync (&dev->dev);
Same comments as before.
net/nfc/core.c int nfc_dev_up(struct nfc_dev *dev) · line 138
Quoted 9 lines
net/nfc/core.c +2
-0if (dev->rfkill &&rfkill_blocked (dev->rfkill)) { rc = -ERFKILL ;@@ -124,7 +134,11 @@ int nfc_dev_up(struct nfc_dev *dev)if (dev->ops->discover_se && dev->ops->discover_se (dev))pr_err ("SE discovery failed\n" ); +device_unlock (&dev->dev); +return rc;
Probably same comments as before apply.
net/nfc/core.c int nfc_dev_down(struct nfc_dev *dev) · line 180
Quoted 13 lines
net/nfc/core.c +5
-0+ error: +pm_runtime_put (&dev->dev);device_unlock (&dev->dev);return rc; }@@ -161,6 +175,9 @@ int nfc_dev_down(struct nfc_dev *dev) dev->ops->dev_down (dev); dev->dev_up = false; +pm_runtime_put (&dev->dev); +device_unlock (&dev->dev); +return rc;
return 0
net/nfc/core.c int nfc_fw_download(struct nfc_dev *dev, const char *firmware_name)
Quoted 4 lines
net/nfc/core.c +0
-0error:device_unlock (&dev->dev);
Best regards,
Krzysztof
Am Mittwoch, den 12.05.2021, 09:54 -0400 schrieb Krzysztof Kozlowski:
Quoted 4 lines
Hi,
Thanks for the patch. Few notes:
Hi,
thank you excellent suggestion. V2 is compiling and will be tested incorporating your suggestions.
Regards
Oliver
Am Mittwoch, den 12.05.2021, 15:44 +0200 schrieb Oliver Neukum:
Quoted 6 lines
We cannot rely on the underlying hardware to do correct runtime PM. NFC core needs to get PM reference while a device is operational, lest it be suspended when it is supposed to be waiting for a target to come into range.
Sorry for sending this out with an uncompleted change log. It went out unintentionally early.
Regards
Oliver