NFC: digital: Call pending command callbacks at device unregister
authorThierry Escande <thierry.escande@collabora.com>
Thu, 16 Jun 2016 18:24:43 +0000 (20:24 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Wed, 6 Jul 2016 08:09:47 +0000 (10:09 +0200)
With this patch, when freeing the command queue in the module unregister
function, the callbacks of the commands still queued are called with a
ENODEV error. This gives a chance to the command issuer to free any
memory it could have allocate.

Signed-off-by: Thierry Escande <thierry.escande@collabora.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
net/nfc/digital_core.c

index 27769ac89d274928a5db673c54c060e23819395b..6e0b255aec6606ef9741b0ebddfe6f35be45ab2c 100644 (file)
@@ -842,6 +842,14 @@ void nfc_digital_unregister_device(struct nfc_digital_dev *ddev)
 
        list_for_each_entry_safe(cmd, n, &ddev->cmd_queue, queue) {
                list_del(&cmd->queue);
+
+               /* Call the command callback if any and pass it a ENODEV error.
+                * This gives a chance to the command issuer to free any
+                * allocated buffer.
+                */
+               if (cmd->cmd_cb)
+                       cmd->cmd_cb(ddev, cmd->cb_context, ERR_PTR(-ENODEV));
+
                kfree(cmd->mdaa_params);
                kfree(cmd);
        }