Repository navigation
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, this is wrong.
so if the probe fails in the workqueue, sdev would still be set. That's not a valid indicator of success.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is partially valid. We should also check is sdev->probe_complete additionally.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thinking a bit more about this, we should ask the question "would shutdown() ever get called if probe() is not successful?". If the answer is no, then sdev will never be NULL here, right? But sof_probe_continue() could still have failed and in that case the probe_complete is the right indicator for success.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@plbossart snd_sof_device_probe() is called by sof_pci_probe(). There are chances that sof_pci_probe() fails before snd_sof_device_probe() is called.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ranj063 My first version patch does check the sdev->probe_complete. After a second thought, the shutdown() will set sdev->system_suspend_target = SOF_SUSPEND_S3 and call snd_sof_suspend(sdev->dev) directly in the PR #2768. In snd_sof_suspend(), it will check sdev->fw_state != SOF_FW_BOOT_COMPLETE (something like checking the probe_complete). If the probe() fails, it will directly return in snd_sof_suspend().
Based on the issue reported by Pelton, Kyle D, the shutdown() callback will still be called even when the probe fails when loading the FW.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and oh btw I tested this on our TGL chromebook and confirmed that shutdown() is only called when probe() is successful.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@plbossart and @ranj063 some updates based on my investigations:
some background knowledge
When reboot, the kernel will check dev->driver and call dev->driver->shutdown() if there is no dev->bus->shutdown() defined. And if probe returns error, dev->driver will be set to NULL.
Will shutdown be called if probe fails in SOF driver?
In some cases, yes. In snd_sof_device_probe(), we may use schedule_work(&sdev->probe_work). In this case, snd_sof_device_probe() always return 0 even the probe_work fails. So the dev->drv won't be cleared.
Is the sdev check necessary?
No. If probe is successfully, sdev is always there. If probe failed in the probe_work, it means sdev has already been allocated successfully. In all other conditions, sof_pci_probe() will return failure and dev->drv is cleared and the shutdown won't be called.
Some further investigations and thoughts.
I checked another driver in kernel, wcnss_ctrl.c. It did the same operation as our SOF. It will use schedule_work for the probe and it return 0 directly. In the scheduled work, the probe may fail and it doesn't do any further clearance.
But as dd 's flow, if the driver fails in probe while it returns 0, like our case, dd will think the probe is OK and the driver will be bound to the device. We should take care of this situation.
I saw there is a function driver_detach() in dd.c. If we call this function in scheduled work when probe failed, it may clean up the things. But I didn't see any special driver call this function. It is only called by bus.c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a PCI bus, there is a .shutdown for that bus.
if the failure happens in the workqueue, then technically the probe didn't fail.
so we agree this test is useless then?
We need to do the same thing as for the remove case, we need to test if the workqueue succeeded (probe_completed or state > boot_not_started). The workqueue will cleanup all the resources if it fails.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I will close this PR later.
@plbossart Do you mean even the resources allocated by devm_xxx? It seems we should call devm_kfree() to free the memory as the driver is not bound to the pci->dev now while the memories allocated by devm_xxx are bound to pci->dev. But it is harmless if don't free it and let kernel to free it when pci->dev is released.
update:
It suddenly occurs to me: We should make the device into D3 before shutdown. If we release the resources, audio may not be able to enter D3 clearly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@libinyang see what I meant in PR #2791