Skip to contentSkip to conversation

ALSA: hda/tas2781-spi: Set tas_hda->dev in probe

PATCH In review Akhil Arul 2 participants 2 messages Nov 20

Subsystems (2)
lore
Share & tools
lore

Akhil Arul

author
#0 lore raw

PATCH 1/1 ALSA: hda/tas2781-spi: Set tas_hda->dev in probe

tas2781_hda_remove() is shared by the I2C and SPI drivers and uses tas_hda->dev for component_del() and for the runtime PM calls. The I2C probe sets that field, the SPI probe does not, so for SPI it stays NULL from the devm_kzalloc(). Unbinding the device through sysfs then warns in component_del() and crashes on the NULL device in pm_runtime_get_sync():

  WARNING: drivers/base/component.c:839 at component_del+0x149/0x170
  Call Trace:
   tas2781_hda_remove+0x16/0x60 [snd_hda_scodec_tas2781]
   device_release_driver_internal+0x19e/0x200
   unbind_store+0xa4/0xb0
  Oops: general protection fault, kernel NULL pointer dereference 0x1d1
  RIP: 0010:__pm_runtime_resume+0x1a/0x90
   tas2781_hda_remove+0x23/0x60 [snd_hda_scodec_tas2781]

The same path runs from the driver remove callback and from the component_add() failure path in tas2781_hda_spi_probe().

Before the common library was introduced, the SPI driver had its own remove function that used tas_priv->dev. Set tas_hda->dev in tas2781_hda_spi_probe(), as the I2C driver does.

Tested the probe/unbind path with KASAN and lockdep enabled: without this change, unbinding the device gives the warning and oops above; with it, unbind, bind and unbind again complete without any splat.

Fixes 28a09d9e42c5 ("ALSA: hda/tas2781: Create an independent lib to save the shared parts for both SPI and I2C driver")
---
 sound/hda/codecs/side-codecs/tas2781_hda_spi.c | 1 +
 1 file changed, 1 insertion(+)
sound/hda/codecs/side-codecs/tas2781_hda_spi.c +1 -0
index da71b57a26e..4bcee8362b6 100644
@@ -781,6 +781,7 @@ static int tas2781_hda_spi_probe(struct spi_device *spi)
 	if (!hda_priv)
 		return -ENOMEM;
 
+	tas_hda->dev = &spi->dev;
 	tas_hda->hda_priv = hda_priv;
 	spi->max_speed_hz = TAS2781_SPI_MAX_FREQ;
 
Signature · 1 line
2.56.1
#1 lore raw
Quoted 27 lines · Akhil Arul

tas2781_hda_remove() is shared by the I2C and SPI drivers and uses tas_hda->dev for component_del() and for the runtime PM calls. The I2C probe sets that field, the SPI probe does not, so for SPI it stays NULL from the devm_kzalloc(). Unbinding the device through sysfs then warns in component_del() and crashes on the NULL device in pm_runtime_get_sync():

  WARNING: drivers/base/component.c:839 at component_del+0x149/0x170
  Call Trace:
   tas2781_hda_remove+0x16/0x60 [snd_hda_scodec_tas2781]
   device_release_driver_internal+0x19e/0x200
   unbind_store+0xa4/0xb0
  Oops: general protection fault, kernel NULL pointer dereference 0x1d1
  RIP: 0010:__pm_runtime_resume+0x1a/0x90
   tas2781_hda_remove+0x23/0x60 [snd_hda_scodec_tas2781]

The same path runs from the driver remove callback and from the component_add() failure path in tas2781_hda_spi_probe().

Before the common library was introduced, the SPI driver had its own remove function that used tas_priv->dev. Set tas_hda->dev in tas2781_hda_spi_probe(), as the I2C driver does.

Tested the probe/unbind path with KASAN and lockdep enabled: without this change, unbinding the device gives the warning and oops above; with it, unbind, bind and unbind again complete without any splat.

Quoted 5 lines
Fixes 28a09d9e42c5 ("ALSA: hda/tas2781: Create an independent lib to save the shared parts for both SPI and I2C driver")

Applied now. Thanks.

Takashi