ASoC: SOF: Fix NULL pointer exception in sof_pci_probe callback#3606
ASoC: SOF: Fix NULL pointer exception in sof_pci_probe callback#3606plbossart merged 1 commit intothesofproject:topic/sof-devfrom
Conversation
We are accessing "desc->ops" in sof_pci_probe without checking "desc" pointer. This results in NULL pointer exception if pci_id->driver_data i.e desc pointer isn't defined in sof device probe: BUG: kernel NULL pointer dereference, address: 0000000000000060 PGD 0 P4D 0 Oops: 0000 [#1] PREEMPT SMP NOPTI RIP: 0010:sof_pci_probe+0x1e/0x17f [snd_sof_pci] Code: Unable to access opcode bytes at RIP 0xffffffffc043dff4. RSP: 0018:ffffac4b03b9b8d8 EFLAGS: 00010246 Add NULL pointer check for sof_dev_desc pointer to avoid such exception. Signed-off-by: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
| dev_err(dev, "error: no matching PCI descriptor\n"); | ||
| return -ENODEV; | ||
| } | ||
|
|
There was a problem hiding this comment.
@ajitkupandey this can only happen if you add a PCI_DEVICE without the matching .driver_data set, right? That's typically only in developer workspaces, and even then that's pretty bad, isn't it?
There was a problem hiding this comment.
Yes this happens only when .driver_data isn't set in pci driver. Actually i ended up in this exception once due to missing driver data so thought to fix this one. I agree that's pretty bad and part of developer workspace only but I guess avoiding exceptions in core code is always good.
If this double NULL check looks weird here may be fixup like adding a "pci_id->driver_data" NULL check in sof pci device probe like "hda_pci_intel_probe" before invoking sof_pci_probe can be done to avoid such exceptions.
There was a problem hiding this comment.
It's fine to do it here, just that you should add in the commit message that this is a paranoia check for something that should not happen for an actual released product.
We are accessing "desc->ops" in sof_pci_probe without checking "desc"
pointer. This results in NULL pointer exception if pci_id->driver_data
i.e desc pointer isn't defined in sof device probe:
BUG: kernel NULL pointer dereference, address: 0000000000000060
PGD 0 P4D 0
Oops: 0000 [#1] PREEMPT SMP NOPTI
RIP: 0010:sof_pci_probe+0x1e/0x17f [snd_sof_pci]
Code: Unable to access opcode bytes at RIP 0xffffffffc043dff4.
RSP: 0018:ffffac4b03b9b8d8 EFLAGS: 00010246
Add NULL pointer check for sof_dev_desc pointer to avoid such exception.
Signed-off-by: Ajit Kumar Pandey AjitKumar.Pandey@amd.com