Skip to contentSkip to conversation

sound/hda: Add NULL check to component match callback function

PATCH In review Won Chung 6 participants 23 messages Mar 30, 2022 – Apr 1, 2022

Subsystems (2)
lore
Share & tools
lore

Won Chung

author
#0 lore raw

PATCH v2 1/1 sound/hda: Add NULL check to component match callback function

Component match callback function needs to check if expected data is passed to it. Without this check, it can cause a NULL pointer dereference when another driver registers a component before i915 drivers have their component master fully bind.

Fixes 7b882fe3e3e8b ("ALSA: hda - handle multiple i915 device instances")

---
- Add "Fixes" tag
- Send to [email protected]

 sound/hda/hdac_i915.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/hda/hdac_i915.c +2 -2
index efe810af28c5..958b0975fa40 100644
@@ -102,13 +102,13 @@ static int i915_component_master_match(struct device *dev, int subcomponent,
 	struct pci_dev *hdac_pci, *i915_pci;
 	struct hdac_bus *bus = data;
 
-	if (!dev_is_pci(dev))
+	if (!dev_is_pci(dev) || !bus)
 		return 0;
 
 	hdac_pci = to_pci_dev(bus->dev);
 	i915_pci = to_pci_dev(dev);
 
-	if (!strcmp(dev->driver->name, "i915") &&
+	if (dev->driver && !strcmp(dev->driver->name, "i915") &&
 	    subcomponent == I915_COMPONENT_AUDIO &&
 	    connectivity_check(i915_pci, hdac_pci))
 		return 1;
Signature · 1 line
2.35.1.1021.g381101b075-goog
#1 lore raw
Quoted 6 lines · Won Chung

Component match callback function needs to check if expected data is passed to it. Without this check, it can cause a NULL pointer dereference when another driver registers a component before i915 drivers have their component master fully bind.

Quoted 7 lines
Fixes 7b882fe3e3e8b ("ALSA: hda - handle multiple i915 device instances")

---
- Add "Fixes" tag
- Send to [email protected]

You rather need to add "Cc: [email protected]" line to the patch itself (around sign-off block), not actually Cc'ing the mail. I edited manually, but please do it so at the next time.

Although I applied the patch as-is now, I wonder...

sound/hda/hdac_i915.c static int i915_component_master_match(struct device *dev, int subcomponent, · line 111

Quoted 2 lines
sound/hda/hdac_i915.c +1 -1
-	if (!strcmp(dev->driver->name, "i915") &&
+	if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Takashi

author
#2 lore raw
Quoted 27 lines · Takashi Iwai
Quoted 6 lines · Won Chung

Component match callback function needs to check if expected data is passed to it. Without this check, it can cause a NULL pointer dereference when another driver registers a component before i915 drivers have their component master fully bind.

Quoted 7 lines
Fixes 7b882fe3e3e8b ("ALSA: hda - handle multiple i915 device instances")

---
- Add "Fixes" tag
- Send to [email protected]

You rather need to add "Cc: [email protected]" line to the patch itself (around sign-off block), not actually Cc'ing the mail. I edited manually, but please do it so at the next time.

Although I applied the patch as-is now, I wonder...

sound/hda/hdac_i915.c static int i915_component_master_match(struct device *dev, int subcomponent, · line 111

Quoted 2 lines
sound/hda/hdac_i915.c +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&
Quoted 8 lines

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Would it be okay for me to resend a new patch with the flags corrected? I have mistakenly added Heikki and Mika as "Signed-off-by" instead of "Suggested-by". I am sorry for that.

Thanks,
Won

#3 lore raw
Quoted 36 lines · Won Chung
Quoted 34 lines · Takashi Iwai
Quoted 6 lines · Won Chung

Component match callback function needs to check if expected data is passed to it. Without this check, it can cause a NULL pointer dereference when another driver registers a component before i915 drivers have their component master fully bind.

Quoted 7 lines
Fixes 7b882fe3e3e8b ("ALSA: hda - handle multiple i915 device instances")

---
- Add "Fixes" tag
- Send to [email protected]

You rather need to add "Cc: [email protected]" line to the patch itself (around sign-off block), not actually Cc'ing the mail. I edited manually, but please do it so at the next time.

Although I applied the patch as-is now, I wonder...

sound/hda/hdac_i915.c static int i915_component_master_match(struct device *dev, int subcomponent, · line 111

Quoted 2 lines
sound/hda/hdac_i915.c +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

Quoted 3 lines

Would it be okay for me to resend a new patch with the flags corrected? I have mistakenly added Heikki and Mika as "Signed-off-by" instead of "Suggested-by". I am sorry for that.

Ah that's bad. I'll reset the branch, then. Please resubmit properly.

thanks,

Takashi

#4 lore raw
Quoted 19 lines · Takashi Iwai
Quoted 10 lines
Quoted 10 lines

sound/hda/hdac_i915.c static int i915_component_master_match(struct device *dev, int subcomponent, · line 111

Quoted 2 lines
sound/hda/hdac_i915.c +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Quoted 4 lines

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

The code that declares a device as component does not have to be the driver of that device.

In our case the components are USB ports, and they are devices that are actually never bind to any drivers: drivers/usb/core/port.c

thanks,

Signature · 1 line
heikki
#5 lore raw
Quoted 26 lines · Heikki Krogerus
Quoted 19 lines · Takashi Iwai
Quoted 10 lines
Quoted 10 lines

sound/hda/hdac_i915.c static int i915_component_master_match(struct device *dev, int subcomponent, · line 111

Quoted 2 lines
sound/hda/hdac_i915.c +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Quoted 4 lines

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

Quoted 5 lines

The code that declares a device as component does not have to be the driver of that device.

In our case the components are USB ports, and they are devices that are actually never bind to any drivers: drivers/usb/core/port.c

OK, that's what I wanted to know. It'd be helpful if it's more clearly mentioned in the commit log.

BTW, the same problem must be seen in MEI drivers, too.

Takashi

#6 lore raw
Quoted 28 lines · Takashi Iwai
Quoted 26 lines · Heikki Krogerus
Quoted 23 lines · Takashi Iwai
Quoted 10 lines
Quoted 10 lines

sound/hda/hdac_i915.c static int i915_component_master_match(struct device *dev, int subcomponent, · line 111

Quoted 2 lines
sound/hda/hdac_i915.c +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

Quoted 8 lines
Quoted 5 lines

The code that declares a device as component does not have to be the driver of that device.

In our case the components are USB ports, and they are devices that are actually never bind to any drivers: drivers/usb/core/port.c

OK, that's what I wanted to know. It'd be helpful if it's more clearly mentioned in the commit log.

Agree.

Quoted 1 line

BTW, the same problem must be seen in MEI drivers, too.

Wasn't there a patch for those too? I lost track...

thanks,

Signature · 1 line
heikki
#7 lore raw
Quoted 36 lines · Heikki Krogerus
Quoted 34 lines · Takashi Iwai
Quoted 31 lines · Heikki Krogerus
Quoted 19 lines · Takashi Iwai
Quoted 10 lines
Quoted 10 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Quoted 4 lines

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

The code that declares a device as component does not have to be the driver of that device.

In our case the components are USB ports, and they are devices that are actually never bind to any drivers: drivers/usb/core/port.c

Quoted 8 lines
Quoted 2 lines

OK, that's what I wanted to know. It'd be helpful if it's more clearly mentioned in the commit log.

Agree.

Quoted 1 line

BTW, the same problem must be seen in MEI drivers, too.

Wasn't there a patch for those too? I lost track...

I don't know, I just checked the latest Linus tree.

And, looking at the HD-audio code, I still wonder how NULL dev->driver can reach there. Is there any PCI device that is added to component without binding to a driver? We have dev_is_pci() check at the beginning, so non-PCI devices should bail out there...

I'm not against adding NULL checks, but just for better understanding the situation.

Takashi

#8 lore raw
Quoted 46 lines · Takashi Iwai
Quoted 43 lines · Heikki Krogerus
Quoted 28 lines · Takashi Iwai
Quoted 26 lines · Heikki Krogerus
Quoted 23 lines · Takashi Iwai
Quoted 10 lines
Quoted 10 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

Quoted 8 lines
Quoted 5 lines

The code that declares a device as component does not have to be the driver of that device.

In our case the components are USB ports, and they are devices that are actually never bind to any drivers: drivers/usb/core/port.c

OK, that's what I wanted to know. It'd be helpful if it's more clearly mentioned in the commit log.

Agree.

Quoted 1 line

BTW, the same problem must be seen in MEI drivers, too.

Quoted 8 lines
Quoted 1 line

Wasn't there a patch for those too? I lost track...

I don't know, I just checked the latest Linus tree.

And, looking at the HD-audio code, I still wonder how NULL dev->driver can reach there. Is there any PCI device that is added to component without binding to a driver? We have dev_is_pci() check at the beginning, so non-PCI devices should bail out there...

Further reading on, I'm really confused. How data=NULL can be passed to this function? The data argument is the value passed from the component_match_add_typed() call in HD-audio driver, hence it must be always the snd_hdac_bus object.

And, I guess the i915 string check can be omitted completely, at least, for HD-audio driver. It already have a check of the parent of the device and that should be enough.

Takashi

#9 lore raw
Quoted 58 lines · Takashi Iwai
Quoted 46 lines · Takashi Iwai
Quoted 43 lines · Heikki Krogerus
Quoted 28 lines · Takashi Iwai
Quoted 26 lines · Heikki Krogerus
Quoted 23 lines · Takashi Iwai
Quoted 10 lines
Quoted 10 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

Quoted 8 lines
Quoted 5 lines

The code that declares a device as component does not have to be the driver of that device.

In our case the components are USB ports, and they are devices that are actually never bind to any drivers: drivers/usb/core/port.c

OK, that's what I wanted to know. It'd be helpful if it's more clearly mentioned in the commit log.

Agree.

Quoted 1 line

BTW, the same problem must be seen in MEI drivers, too.

Quoted 8 lines
Quoted 1 line

Wasn't there a patch for those too? I lost track...

I don't know, I just checked the latest Linus tree.

And, looking at the HD-audio code, I still wonder how NULL dev->driver can reach there. Is there any PCI device that is added to component without binding to a driver? We have dev_is_pci() check at the beginning, so non-PCI devices should bail out there...

Quoted 8 lines

Further reading on, I'm really confused. How data=NULL can be passed to this function? The data argument is the value passed from the component_match_add_typed() call in HD-audio driver, hence it must be always the snd_hdac_bus object.

And, I guess the i915 string check can be omitted completely, at least, for HD-audio driver. It already have a check of the parent of the device and that should be enough.

That said, something like below (supposing data NULL check being superfluous), instead.

Takashi

sound/hda/hdac_i915.c +2 -7
@@ -102,18 +102,13 @@ static int i915_component_master_match(struct device *dev, int subcomponent,
 	struct pci_dev *hdac_pci, *i915_pci;
 	struct hdac_bus *bus = data;
 
-	if (!dev_is_pci(dev))
+	if (subcomponent != I915_COMPONENT_AUDIO || !dev_is_pci(dev))
 		return 0;
 
 	hdac_pci = to_pci_dev(bus->dev);
 	i915_pci = to_pci_dev(dev);
 
-	if (!strcmp(dev->driver->name, "i915") &&
-	    subcomponent == I915_COMPONENT_AUDIO &&
-	    connectivity_check(i915_pci, hdac_pci))
-		return 1;
-
-	return 0;
+	return connectivity_check(i915_pci, hdac_pci);
 }
 
 /* check whether intel graphics is present */
#10 lore raw

Hi Takashi,

Quoted 78 lines · Takashi Iwai
Quoted 58 lines · Takashi Iwai
Quoted 46 lines · Takashi Iwai
Quoted 43 lines · Heikki Krogerus
Quoted 28 lines · Takashi Iwai
Quoted 26 lines · Heikki Krogerus
Quoted 23 lines · Takashi Iwai
Quoted 10 lines
Quoted 10 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

Quoted 8 lines
Quoted 5 lines

The code that declares a device as component does not have to be the driver of that device.

In our case the components are USB ports, and they are devices that are actually never bind to any drivers: drivers/usb/core/port.c

OK, that's what I wanted to know. It'd be helpful if it's more clearly mentioned in the commit log.

Agree.

Quoted 1 line

BTW, the same problem must be seen in MEI drivers, too.

Quoted 8 lines
Quoted 1 line

Wasn't there a patch for those too? I lost track...

I don't know, I just checked the latest Linus tree.

And, looking at the HD-audio code, I still wonder how NULL dev->driver can reach there. Is there any PCI device that is added to component without binding to a driver? We have dev_is_pci() check at the beginning, so non-PCI devices should bail out there...

Quoted 8 lines

Further reading on, I'm really confused. How data=NULL can be passed to this function? The data argument is the value passed from the component_match_add_typed() call in HD-audio driver, hence it must be always the snd_hdac_bus object.

And, I guess the i915 string check can be omitted completely, at least, for HD-audio driver. It already have a check of the parent of the device and that should be enough.

That said, something like below (supposing data NULL check being superfluous), instead.

Takashi

sound/hda/hdac_i915.c static int i915_component_master_match(struct device *dev, int subcomponent, · line 107

Quoted 7 lines
sound/hda/hdac_i915.c +1 -1
@@ -102,18 +102,13 @@ static int i915_component_master_match(struct device *dev, int subcomponent,
 	struct pci_dev *hdac_pci, *i915_pci;
 	struct hdac_bus *bus = data;
 
-	if (!dev_is_pci(dev))
+	if (subcomponent != I915_COMPONENT_AUDIO || !dev_is_pci(dev))
 		return 0;
 

If I recall this bug correctly, it's not the usb port perse that is falling through this !dev_is_pci(dev) check, it's actually the usb4-port in a new proposed patch by Heikki and Mika to extend the usb type-c component to encompass the usb4 specific pieces too. Is it possible usb4 ports are considered pci devices, and that's how we got into this situation?

Also, a little more background information: This crash happens because in our kernel configs, we config'd the usb4 driver as =y (built in) instead of =m module, which meant that the usb4 port's driver was adding a component likely much earlier than hdac_i915.

Thanks,
Benson

Quoted 14 lines
sound/hda/hdac_i915.c +1 -6
 	hdac_pci = to_pci_dev(bus->dev);
 	i915_pci = to_pci_dev(dev);
 
-	if (!strcmp(dev->driver->name, "i915") &&
-	    subcomponent == I915_COMPONENT_AUDIO &&
-	    connectivity_check(i915_pci, hdac_pci))
-		return 1;
-
-	return 0;
+	return connectivity_check(i915_pci, hdac_pci);
 }
 
 /* check whether intel graphics is present */
Signature · 7 lines
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
[email protected]
Chromium OS Project
[email protected]
#11 lore raw
Quoted 85 lines · Benson Leung

Hi Takashi,

Quoted 81 lines · Takashi Iwai
Quoted 58 lines · Takashi Iwai
Quoted 46 lines · Takashi Iwai
Quoted 43 lines · Heikki Krogerus
Quoted 28 lines · Takashi Iwai
Quoted 26 lines · Heikki Krogerus
Quoted 23 lines · Takashi Iwai
Quoted 10 lines
Quoted 10 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

Quoted 8 lines
Quoted 5 lines

The code that declares a device as component does not have to be the driver of that device.

In our case the components are USB ports, and they are devices that are actually never bind to any drivers: drivers/usb/core/port.c

OK, that's what I wanted to know. It'd be helpful if it's more clearly mentioned in the commit log.

Agree.

Quoted 1 line

BTW, the same problem must be seen in MEI drivers, too.

Quoted 8 lines
Quoted 1 line

Wasn't there a patch for those too? I lost track...

I don't know, I just checked the latest Linus tree.

And, looking at the HD-audio code, I still wonder how NULL dev->driver can reach there. Is there any PCI device that is added to component without binding to a driver? We have dev_is_pci() check at the beginning, so non-PCI devices should bail out there...

Quoted 8 lines

Further reading on, I'm really confused. How data=NULL can be passed to this function? The data argument is the value passed from the component_match_add_typed() call in HD-audio driver, hence it must be always the snd_hdac_bus object.

And, I guess the i915 string check can be omitted completely, at least, for HD-audio driver. It already have a check of the parent of the device and that should be enough.

That said, something like below (supposing data NULL check being superfluous), instead.

Takashi

sound/hda/hdac_i915.c +0 -0
@@ -102,18 +102,13 @@ static int i915_component_master_match(struct device *dev, int subcomponent,
 	struct pci_dev *hdac_pci, *i915_pci;
 	struct hdac_bus *bus = data;
 
Quoted 10 lines

sound/hda/hdac_i915.c static int i915_component_master_match(struct device *dev, int subcomponent, · line 107

Quoted 4 lines
sound/hda/hdac_i915.c +1 -1
-	if (!dev_is_pci(dev))
+	if (subcomponent != I915_COMPONENT_AUDIO || !dev_is_pci(dev))
 		return 0;
 

If I recall this bug correctly, it's not the usb port perse that is falling through this !dev_is_pci(dev) check, it's actually the usb4-port in a new proposed patch by Heikki and Mika to extend the usb type-c component to encompass the usb4 specific pieces too. Is it possible usb4 ports are considered pci devices, and that's how we got into this situation?

Yes, that explains for one of two changes in the original patch. But why data==NULL check is needed is still unclear.

Quoted 4 lines

Also, a little more background information: This crash happens because in our kernel configs, we config'd the usb4 driver as =y (built in) instead of =m module, which meant that the usb4 port's driver was adding a component likely much earlier than hdac_i915.

Thanks, it's what I supposed, too.

Takashi

#12 lore raw
In reply to Benson Leung

Hi,

Quoted 6 lines · Benson Leung
Quoted 6 lines
sound/hda/hdac_i915.c +0 -0
@@ -102,18 +102,13 @@ static int i915_component_master_match(struct device *dev, int subcomponent,
 	struct pci_dev *hdac_pci, *i915_pci;
 	struct hdac_bus *bus = data;
 
Quoted 10 lines

sound/hda/hdac_i915.c static int i915_component_master_match(struct device *dev, int subcomponent, · line 107

Quoted 4 lines
sound/hda/hdac_i915.c +1 -1
-	if (!dev_is_pci(dev))
+	if (subcomponent != I915_COMPONENT_AUDIO || !dev_is_pci(dev))
 		return 0;
 

If I recall this bug correctly, it's not the usb port perse that is falling through this !dev_is_pci(dev) check, it's actually the usb4-port in a new proposed patch by Heikki and Mika to extend the usb type-c component to encompass the usb4 specific pieces too. Is it possible usb4 ports are considered pci devices, and that's how we got into this situation?

For usb4_port the dev_ic_pci(dev) returns false:

  #define dev_is_pci(d) ((d)->bus == &pci_bus_type)

We don't attach them to PCI bus (well they are not PCI devices).

maintainer
#13 lore raw
In reply to Benson Leung
Quoted 95 lines · Benson Leung

Hi Takashi,

Quoted 78 lines · Takashi Iwai
Quoted 58 lines · Takashi Iwai
Quoted 46 lines · Takashi Iwai
Quoted 43 lines · Heikki Krogerus
Quoted 28 lines · Takashi Iwai
Quoted 26 lines · Heikki Krogerus
Quoted 23 lines · Takashi Iwai
Quoted 10 lines
Quoted 10 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

Quoted 8 lines
Quoted 5 lines

The code that declares a device as component does not have to be the driver of that device.

In our case the components are USB ports, and they are devices that are actually never bind to any drivers: drivers/usb/core/port.c

OK, that's what I wanted to know. It'd be helpful if it's more clearly mentioned in the commit log.

Agree.

Quoted 1 line

BTW, the same problem must be seen in MEI drivers, too.

Quoted 8 lines
Quoted 1 line

Wasn't there a patch for those too? I lost track...

I don't know, I just checked the latest Linus tree.

And, looking at the HD-audio code, I still wonder how NULL dev->driver can reach there. Is there any PCI device that is added to component without binding to a driver? We have dev_is_pci() check at the beginning, so non-PCI devices should bail out there...

Quoted 8 lines

Further reading on, I'm really confused. How data=NULL can be passed to this function? The data argument is the value passed from the component_match_add_typed() call in HD-audio driver, hence it must be always the snd_hdac_bus object.

And, I guess the i915 string check can be omitted completely, at least, for HD-audio driver. It already have a check of the parent of the device and that should be enough.

That said, something like below (supposing data NULL check being superfluous), instead.

Takashi

sound/hda/hdac_i915.c static int i915_component_master_match(struct device *dev, int subcomponent, · line 107

Quoted 7 lines
sound/hda/hdac_i915.c +1 -1
@@ -102,18 +102,13 @@ static int i915_component_master_match(struct device *dev, int subcomponent,
 	struct pci_dev *hdac_pci, *i915_pci;
 	struct hdac_bus *bus = data;
 
-	if (!dev_is_pci(dev))
+	if (subcomponent != I915_COMPONENT_AUDIO || !dev_is_pci(dev))
 		return 0;
 

If I recall this bug correctly, it's not the usb port perse that is falling through this !dev_is_pci(dev) check, it's actually the usb4-port in a new proposed patch by Heikki and Mika to extend the usb type-c component to encompass the usb4 specific pieces too. Is it possible usb4 ports are considered pci devices, and that's how we got into this situation?

Quoted 4 lines

Also, a little more background information: This crash happens because in our kernel configs, we config'd the usb4 driver as =y (built in) instead of =m module, which meant that the usb4 port's driver was adding a component likely much earlier than hdac_i915.

So is this actually triggering on 5.17 right now? Or is it due to some other not-applied changes you are testing at the moment?

confused,

greg k-h

author
#14 lore raw
Quoted 102 lines · Greg KH
Quoted 95 lines · Benson Leung

Hi Takashi,

Quoted 78 lines · Takashi Iwai
Quoted 58 lines · Takashi Iwai
Quoted 46 lines · Takashi Iwai
Quoted 43 lines · Heikki Krogerus
Quoted 28 lines · Takashi Iwai
Quoted 26 lines · Heikki Krogerus
Quoted 23 lines · Takashi Iwai
Quoted 10 lines
Quoted 10 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

Quoted 8 lines
Quoted 5 lines

The code that declares a device as component does not have to be the driver of that device.

In our case the components are USB ports, and they are devices that are actually never bind to any drivers: drivers/usb/core/port.c

OK, that's what I wanted to know. It'd be helpful if it's more clearly mentioned in the commit log.

Agree.

Quoted 1 line

BTW, the same problem must be seen in MEI drivers, too.

Quoted 8 lines
Quoted 1 line

Wasn't there a patch for those too? I lost track...

I don't know, I just checked the latest Linus tree.

And, looking at the HD-audio code, I still wonder how NULL dev->driver can reach there. Is there any PCI device that is added to component without binding to a driver? We have dev_is_pci() check at the beginning, so non-PCI devices should bail out there...

Quoted 8 lines

Further reading on, I'm really confused. How data=NULL can be passed to this function? The data argument is the value passed from the component_match_add_typed() call in HD-audio driver, hence it must be always the snd_hdac_bus object.

And, I guess the i915 string check can be omitted completely, at least, for HD-audio driver. It already have a check of the parent of the device and that should be enough.

That said, something like below (supposing data NULL check being superfluous), instead.

Takashi

sound/hda/hdac_i915.c static int i915_component_master_match(struct device *dev, int subcomponent, · line 107

Quoted 7 lines
sound/hda/hdac_i915.c +1 -1
@@ -102,18 +102,13 @@ static int i915_component_master_match(struct device *dev, int subcomponent,
    struct pci_dev *hdac_pci, *i915_pci;
    struct hdac_bus *bus = data;
 
-   if (!dev_is_pci(dev))
+   if (subcomponent != I915_COMPONENT_AUDIO || !dev_is_pci(dev))
            return 0;
 

If I recall this bug correctly, it's not the usb port perse that is falling through this !dev_is_pci(dev) check, it's actually the usb4-port in a new proposed patch by Heikki and Mika to extend the usb type-c component to encompass the usb4 specific pieces too. Is it possible usb4 ports are considered pci devices, and that's how we got into this situation?

Quoted 4 lines

Also, a little more background information: This crash happens because in our kernel configs, we config'd the usb4 driver as =y (built in) instead of =m module, which meant that the usb4 port's driver was adding a component likely much earlier than hdac_i915.

Quoted 6 lines

So is this actually triggering on 5.17 right now? Or is it due to some other not-applied changes you are testing at the moment?

confused,

greg k-h

Hi Greg,

I believe it is not causing an issue in 5.17 at the moment. It is triggered when we try to apply new changes and test it locally. (registering a component for usb4_port)

Thanks,
Won

maintainer
#15 lore raw
Quoted 108 lines · Won Chung
Quoted 107 lines · Greg KH
Quoted 95 lines · Benson Leung

Hi Takashi,

Quoted 78 lines · Takashi Iwai
Quoted 58 lines · Takashi Iwai
Quoted 46 lines · Takashi Iwai
Quoted 43 lines · Heikki Krogerus
Quoted 28 lines · Takashi Iwai
Quoted 26 lines · Heikki Krogerus
Quoted 23 lines · Takashi Iwai
Quoted 10 lines
Quoted 10 lines
Quoted 2 lines

- if (!strcmp(dev->driver->name, "i915") &&
+ if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

Quoted 8 lines
Quoted 5 lines

The code that declares a device as component does not have to be the driver of that device.

In our case the components are USB ports, and they are devices that are actually never bind to any drivers: drivers/usb/core/port.c

OK, that's what I wanted to know. It'd be helpful if it's more clearly mentioned in the commit log.

Agree.

Quoted 1 line

BTW, the same problem must be seen in MEI drivers, too.

Quoted 8 lines
Quoted 1 line

Wasn't there a patch for those too? I lost track...

I don't know, I just checked the latest Linus tree.

And, looking at the HD-audio code, I still wonder how NULL dev->driver can reach there. Is there any PCI device that is added to component without binding to a driver? We have dev_is_pci() check at the beginning, so non-PCI devices should bail out there...

Quoted 8 lines

Further reading on, I'm really confused. How data=NULL can be passed to this function? The data argument is the value passed from the component_match_add_typed() call in HD-audio driver, hence it must be always the snd_hdac_bus object.

And, I guess the i915 string check can be omitted completely, at least, for HD-audio driver. It already have a check of the parent of the device and that should be enough.

That said, something like below (supposing data NULL check being superfluous), instead.

Takashi

sound/hda/hdac_i915.c static int i915_component_master_match(struct device *dev, int subcomponent, · line 107

Quoted 7 lines
sound/hda/hdac_i915.c +1 -1
@@ -102,18 +102,13 @@ static int i915_component_master_match(struct device *dev, int subcomponent,
    struct pci_dev *hdac_pci, *i915_pci;
    struct hdac_bus *bus = data;
 
-   if (!dev_is_pci(dev))
+   if (subcomponent != I915_COMPONENT_AUDIO || !dev_is_pci(dev))
            return 0;
 

If I recall this bug correctly, it's not the usb port perse that is falling through this !dev_is_pci(dev) check, it's actually the usb4-port in a new proposed patch by Heikki and Mika to extend the usb type-c component to encompass the usb4 specific pieces too. Is it possible usb4 ports are considered pci devices, and that's how we got into this situation?

Quoted 4 lines

Also, a little more background information: This crash happens because in our kernel configs, we config'd the usb4 driver as =y (built in) instead of =m module, which meant that the usb4 port's driver was adding a component likely much earlier than hdac_i915.

So is this actually triggering on 5.17 right now? Or is it due to some other not-applied changes you are testing at the moment?

confused,

Quoted 7 lines
Quoted 1 line

greg k-h

Hi Greg,

I believe it is not causing an issue in 5.17 at the moment. It is triggered when we try to apply new changes and test it locally. (registering a component for usb4_port)

Then why would it ever be needed to be backported to a stable kernel?

Please be more careful.

greg k-h

#16 lore raw

Hi Greg,

Quoted 14 lines · Greg KH
Quoted 5 lines · Won Chung
Quoted 5 lines

So is this actually triggering on 5.17 right now? Or is it due to some other not-applied changes you are testing at the moment?

confused,

Quoted 7 lines
Quoted 1 line

greg k-h

Hi Greg,

I believe it is not causing an issue in 5.17 at the moment. It is triggered when we try to apply new changes and test it locally. (registering a component for usb4_port)

Quoted 5 lines

Then why would it ever be needed to be backported to a stable kernel?

Please be more careful.

greg k-h

Sorry about that. I gave Won bad advice to cc stable. You're right, it will only be relevant when a future patch lands in usb4.

Thanks,
Benson

Signature · 7 lines
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
[email protected]
Chromium OS Project
[email protected]
maintainer
#17 lore raw
Quoted 17 lines · Benson Leung

Hi Greg,

Quoted 14 lines · Greg KH
Quoted 12 lines · Won Chung
Quoted 6 lines

So is this actually triggering on 5.17 right now? Or is it due to some other not-applied changes you are testing at the moment?

confused,

greg k-h

Hi Greg,

I believe it is not causing an issue in 5.17 at the moment. It is triggered when we try to apply new changes and test it locally. (registering a component for usb4_port)

Quoted 8 lines
Quoted 5 lines

Then why would it ever be needed to be backported to a stable kernel?

Please be more careful.

greg k-h

Sorry about that. I gave Won bad advice to cc stable. You're right, it will only be relevant when a future patch lands in usb4.

It isn't even relevant now, please only worry about this when you have your patches ready for submission that causes this breakage.

thanks,

greg k-h

#18 lore raw
In reply to Takashi Iwai

Hi Takashi,

Quoted 65 lines · Takashi Iwai
Quoted 63 lines · Takashi Iwai
Quoted 46 lines · Takashi Iwai
Quoted 43 lines · Heikki Krogerus
Quoted 28 lines · Takashi Iwai
Quoted 26 lines · Heikki Krogerus
Quoted 23 lines · Takashi Iwai
Quoted 10 lines
Quoted 10 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

Quoted 8 lines
Quoted 5 lines

The code that declares a device as component does not have to be the driver of that device.

In our case the components are USB ports, and they are devices that are actually never bind to any drivers: drivers/usb/core/port.c

OK, that's what I wanted to know. It'd be helpful if it's more clearly mentioned in the commit log.

Agree.

Quoted 1 line

BTW, the same problem must be seen in MEI drivers, too.

Quoted 8 lines
Quoted 1 line

Wasn't there a patch for those too? I lost track...

I don't know, I just checked the latest Linus tree.

And, looking at the HD-audio code, I still wonder how NULL dev->driver can reach there. Is there any PCI device that is added to component without binding to a driver? We have dev_is_pci() check at the beginning, so non-PCI devices should bail out there...

Further reading on, I'm really confused. How data=NULL can be passed to this function? The data argument is the value passed from the component_match_add_typed() call in HD-audio driver, hence it must be always the snd_hdac_bus object.

Quoted 6 lines
Quoted 3 lines

And, I guess the i915 string check can be omitted completely, at least, for HD-audio driver. It already have a check of the parent of the device and that should be enough.

That said, something like below (supposing data NULL check being superfluous), instead.

I don't think data can be NULL. There is no need for that check like you said.

Quoted 13 lines
sound/hda/hdac_i915.c +1 -1
@@ -102,18 +102,13 @@ static int i915_component_master_match(struct device *dev, int subcomponent,
 	struct pci_dev *hdac_pci, *i915_pci;
 	struct hdac_bus *bus = data;
 
-	if (!dev_is_pci(dev))
+	if (subcomponent != I915_COMPONENT_AUDIO || !dev_is_pci(dev))
 		return 0;
 
 	hdac_pci = to_pci_dev(bus->dev);
 	i915_pci = to_pci_dev(dev);
 

sound/hda/hdac_i915.c static int i915_component_master_match(struct device *dev, int subcomponent, · line 114

Quoted 10 lines
sound/hda/hdac_i915.c +1 -6
-	if (!strcmp(dev->driver->name, "i915") &&
-	    subcomponent == I915_COMPONENT_AUDIO &&
-	    connectivity_check(i915_pci, hdac_pci))
-		return 1;
-
-	return 0;
+	return connectivity_check(i915_pci, hdac_pci);
 }
 
 /* check whether intel graphics is present */

That looks really nice to me!

thanks,

Signature · 1 line
heikki
maintainer
#19 lore raw
In reply to Heikki Krogerus
Quoted 25 lines · Heikki Krogerus
Quoted 19 lines · Takashi Iwai
Quoted 10 lines
Quoted 10 lines

sound/hda/hdac_i915.c static int i915_component_master_match(struct device *dev, int subcomponent, · line 111

Quoted 2 lines
sound/hda/hdac_i915.c +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Quoted 4 lines

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

Quoted 5 lines

The code that declares a device as component does not have to be the driver of that device.

In our case the components are USB ports, and they are devices that are actually never bind to any drivers: drivers/usb/core/port.c

Why is a USB device being passed to this code that assumes it is looking for a PCI device with a specific driver name? As I mentioned on the mei patch, triggering off of a name is really a bad idea, as is assuming the device type without any assurance it is such a device (there's a reason we didn't provide device type identification in the driver core, don't abuse that please...)

thanks,

greg k-h

#20 lore raw

Hi Greg,

Quoted 32 lines · Greg KH
Quoted 25 lines · Heikki Krogerus
Quoted 19 lines · Takashi Iwai
Quoted 10 lines
Quoted 10 lines

sound/hda/hdac_i915.c static int i915_component_master_match(struct device *dev, int subcomponent, · line 111

Quoted 2 lines
sound/hda/hdac_i915.c +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Quoted 4 lines

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

Quoted 5 lines

The code that declares a device as component does not have to be the driver of that device.

In our case the components are USB ports, and they are devices that are actually never bind to any drivers: drivers/usb/core/port.c

Quoted 6 lines

Why is a USB device being passed to this code that assumes it is looking for a PCI device with a specific driver name? As I mentioned on the mei patch, triggering off of a name is really a bad idea, as is assuming the device type without any assurance it is such a device (there's a reason we didn't provide device type identification in the driver core, don't abuse that please...)

I totally agree. This driver is making a whole bunch of assumptions when it should not make any assumptions. And yes, one of those assumptions is that the driver of the device has a specific name, and that is totally crazy. So why is it making those assumptions? I have no idea, but is does, and they are now causing the first problem - NULL pointer dereference.

This patch (and that other) is only proposing a simple way to solve that NULL pointer dereference issue by adding some sanity checks. If that's no OK, and the whole driver should be refactored instead, then that is perfectly OK by me, but that has to be done by somebody who understands what exactly is the driver and the device it's controlling doing (and for).

thanks,

Signature · 1 line
heikki
maintainer
#21 lore raw
Quoted 49 lines · Heikki Krogerus

Hi Greg,

Quoted 32 lines · Greg KH
Quoted 25 lines · Heikki Krogerus
Quoted 19 lines · Takashi Iwai
Quoted 10 lines
Quoted 10 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Quoted 4 lines

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

Quoted 5 lines

The code that declares a device as component does not have to be the driver of that device.

In our case the components are USB ports, and they are devices that are actually never bind to any drivers: drivers/usb/core/port.c

Quoted 6 lines

Why is a USB device being passed to this code that assumes it is looking for a PCI device with a specific driver name? As I mentioned on the mei patch, triggering off of a name is really a bad idea, as is assuming the device type without any assurance it is such a device (there's a reason we didn't provide device type identification in the driver core, don't abuse that please...)

I totally agree. This driver is making a whole bunch of assumptions when it should not make any assumptions. And yes, one of those assumptions is that the driver of the device has a specific name, and that is totally crazy. So why is it making those assumptions? I have no idea, but is does, and they are now causing the first problem - NULL pointer dereference.

Quoted 6 lines

This patch (and that other) is only proposing a simple way to solve that NULL pointer dereference issue by adding some sanity checks. If that's no OK, and the whole driver should be refactored instead, then that is perfectly OK by me, but that has to be done by somebody who understands what exactly is the driver and the device it's controlling doing (and for).

This all needs to be refactored to not do this at all.

thanks,

greg k-h

#22 lore raw
In reply to Heikki Krogerus
Quoted 43 lines · Heikki Krogerus

Hi Greg,

Quoted 32 lines · Greg KH
Quoted 25 lines · Heikki Krogerus
Quoted 19 lines · Takashi Iwai
Quoted 10 lines
Quoted 10 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-     if (!strcmp(dev->driver->name, "i915") &&
+     if (dev->driver && !strcmp(dev->driver->name, "i915") &&

Can NULL dev->driver be really seen? I thought the components are added by the drivers, hence they ought to have the driver field set. But there can be corner cases I overlooked.

thanks,

Quoted 8 lines
Quoted 1 line

Takashi

Hi Takashi,

When I try using component_add in a different driver (usb4 in my case), I think dev->driver here is NULL because the i915 drivers do not have their component master fully bound when this new component is registered. When I test it, it seems to be causing a crash.

Quoted 4 lines

Hm, from where component_add*() is called? Basically dev->driver must be already set before the corresponding driver gets bound at __driver_probe_deviec(). So, if the device is added to component from the corresponding driver's probe, dev->driver must be non-NULL.

Quoted 5 lines

The code that declares a device as component does not have to be the driver of that device.

In our case the components are USB ports, and they are devices that are actually never bind to any drivers: drivers/usb/core/port.c

Quoted 6 lines

Why is a USB device being passed to this code that assumes it is looking for a PCI device with a specific driver name? As I mentioned on the mei patch, triggering off of a name is really a bad idea, as is assuming the device type without any assurance it is such a device (there's a reason we didn't provide device type identification in the driver core, don't abuse that please...)

Quoted 6 lines

I totally agree. This driver is making a whole bunch of assumptions when it should not make any assumptions. And yes, one of those assumptions is that the driver of the device has a specific name, and that is totally crazy. So why is it making those assumptions? I have no idea, but is does, and they are now causing the first problem - NULL pointer dereference.

Well, it's a sort of best-effort approach for the component framework. Currently the framework passes a device pointer without knowing what it is and every master component tries to match with it unless it's already bound. Because of that, the driver has to judge which one is the right one by itself. The device driver's string is a loose matching target that practically worked, so far.

Maybe we should define unique subcomponent numbers and rather check the passed number at matching. (Though, only relying on the number is dangerous, too.)

Takashi