diff options
author | Kristofer Jonsson <kristofer.jonsson@arm.com> | 2023-01-20 13:38:13 +0100 |
---|---|---|
committer | Kristofer Jonsson <kristofer.jonsson@arm.com> | 2023-02-02 16:30:39 +0100 |
commit | ec47704ab3fd50a9ef8339f33139ddae4caa00b6 (patch) | |
tree | 87698ce04f75b460580dfbc637d453dbfc141c37 /kernel/ethosu_cancel_inference.c | |
parent | d779a08a0f7ca3cdde16941720ddc7af96e74520 (diff) | |
download | ethos-u-linux-driver-stack-ec47704ab3fd50a9ef8339f33139ddae4caa00b6.tar.gz |
Break circulare dependency on struct ethosu_device
The 'struct ethosu_device' has been passed as argument to classes.
This creates a circular dependency dependency and it gives all
classes full visibility to all resources in the device struct. This
patch removes the circular dependency.
Using device_lock() and device_unlock() to for synchronization.
Change-Id: I8322e6530c72d7bd67f48f411b4f14b612be2706
Diffstat (limited to 'kernel/ethosu_cancel_inference.c')
-rw-r--r-- | kernel/ethosu_cancel_inference.c | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/kernel/ethosu_cancel_inference.c b/kernel/ethosu_cancel_inference.c index 61f7a9c..ee630f5 100644 --- a/kernel/ethosu_cancel_inference.c +++ b/kernel/ethosu_cancel_inference.c @@ -41,9 +41,10 @@ ****************************************************************************/ static int ethosu_cancel_inference_send( - struct ethosu_cancel_inference *cancellation) + struct ethosu_cancel_inference *cancellation, + struct ethosu_mailbox *mailbox) { - return ethosu_mailbox_cancel_inference(&cancellation->edev->mailbox, + return ethosu_mailbox_cancel_inference(mailbox, &cancellation->msg, cancellation->inf->msg.id); } @@ -61,7 +62,9 @@ static void ethosu_cancel_inference_fail(struct ethosu_mailbox_msg *msg) complete(&cancellation->done); } -int ethosu_cancel_inference_request(struct ethosu_inference *inf, +int ethosu_cancel_inference_request(struct device *dev, + struct ethosu_mailbox *mailbox, + struct ethosu_inference *inf, struct ethosu_uapi_cancel_inference_status *uapi) { struct ethosu_cancel_inference *cancellation; @@ -75,7 +78,7 @@ int ethosu_cancel_inference_request(struct ethosu_inference *inf, } cancellation = - devm_kzalloc(inf->edev->dev, + devm_kzalloc(dev, sizeof(struct ethosu_cancel_inference), GFP_KERNEL); if (!cancellation) @@ -86,39 +89,39 @@ int ethosu_cancel_inference_request(struct ethosu_inference *inf, /* mark inference ABORTING to avoid resending the inference message */ inf->status = ETHOSU_CORE_STATUS_ABORTING; - cancellation->edev = inf->edev; + cancellation->dev = dev; cancellation->inf = inf; cancellation->uapi = uapi; init_completion(&cancellation->done); cancellation->msg.fail = ethosu_cancel_inference_fail; - ret = ethosu_mailbox_register(&cancellation->edev->mailbox, + ret = ethosu_mailbox_register(mailbox, &cancellation->msg); if (ret < 0) goto kfree; - dev_info(cancellation->edev->dev, - "Inference cancellation create. cancel=0x%pK, msg.id=%d\n", + dev_info(dev, + "Inference cancellation create. cancel=0x%pK, msg.id=%ddev", cancellation, cancellation->msg.id); - ret = ethosu_cancel_inference_send(cancellation); + ret = ethosu_cancel_inference_send(cancellation, mailbox); if (0 != ret) goto deregister; /* Unlock the mutex before going to block on the condition */ - mutex_unlock(&cancellation->edev->mutex); + device_unlock(dev); /* wait for response to arrive back */ timeout = wait_for_completion_timeout(&cancellation->done, msecs_to_jiffies( CANCEL_INFERENCE_RESP_TIMEOUT_MS)); /* take back the mutex before resuming to do anything */ - ret = mutex_lock_interruptible(&cancellation->edev->mutex); + ret = device_lock_interruptible(dev); if (0 != ret) goto deregister; if (0 == timeout /* timed out*/) { - dev_warn(inf->edev->dev, - "Msg: Cancel Inference response lost - timeout\n"); + dev_warn(dev, + "Msg: Cancel Inference response lost - timeoutdev"); ret = -EIO; goto deregister; } @@ -129,30 +132,31 @@ int ethosu_cancel_inference_request(struct ethosu_inference *inf, } deregister: - ethosu_mailbox_deregister(&cancellation->edev->mailbox, + ethosu_mailbox_deregister(mailbox, &cancellation->msg); kfree: - dev_info(cancellation->edev->dev, - "Cancel inference destroy. cancel=0x%pK\n", cancellation); + dev_info(dev, + "Cancel inference destroy. cancel=0x%pK", cancellation); /* decrease the reference on the inference we are refering to */ ethosu_inference_put(cancellation->inf); - devm_kfree(cancellation->edev->dev, cancellation); + devm_kfree(dev, cancellation); return ret; } -void ethosu_cancel_inference_rsp(struct ethosu_device *edev, +void ethosu_cancel_inference_rsp(struct ethosu_mailbox *mailbox, int msg_id, struct ethosu_core_msg_cancel_inference_rsp *rsp) { + struct device *dev = mailbox->dev; struct ethosu_mailbox_msg *msg; struct ethosu_cancel_inference *cancellation; - msg = ethosu_mailbox_find(&edev->mailbox, msg_id); + msg = ethosu_mailbox_find(mailbox, msg_id); if (IS_ERR(msg)) { - dev_warn(edev->dev, - "Id for cancel inference msg not found. id=%d\n", + dev_warn(dev, + "Id for cancel inference msg not found. id=%ddev", msg_id); return; |