Skip to contentSkip to conversation

TDA1997x: fix tda1997x_remove()

PATCH In review Krzysztof Hałasa 2 participants 2 messages Jul 30, 2021 – Aug 19, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 TDA1997x: fix tda1997x_remove()

TDA1997x driver tried to hold two values in a single variable:
device's "client data" pointer was first set to "sd" in v4l2_i2c_subdev_init(), then it was overwritten explicitly using dev_set_drvdata() with "state". This caused tda1997x_remove() to fail badly.

drivers/media/i2c/tda1997x.c +2 -2
index 17be95c0dcb3..fb37918b7fb5 100644
@@ -2490,7 +2490,8 @@ static const struct media_entity_operations tda1997x_media_ops = {
 static int tda1997x_pcm_startup(struct snd_pcm_substream *substream,
 				struct snd_soc_dai *dai)
 {
-	struct tda1997x_state *state = snd_soc_dai_get_drvdata(dai);
+	struct v4l2_subdev *sd = snd_soc_dai_get_drvdata(dai);
+	struct tda1997x_state *state = to_state(sd);
 	struct snd_soc_component *component = dai->component;
 	struct snd_pcm_runtime *rtd = substream->runtime;
 	int rate, err;
@@ -2799,7 +2800,6 @@ static int tda1997x_probe(struct i2c_client *client,
 			dev_err(&client->dev, "register audio codec failed\n");
 			goto err_free_media;
 		}
-		dev_set_drvdata(&state->client->dev, state);
 		v4l_info(state->client, "registered audio codec\n");
 	}
 
Signature · 5 lines
Krzysztof "Chris" Hałasa

Sieć Badawcza Łukasiewicz
Przemysłowy Instytut Automatyki i Pomiarów PIAP
Al. Jerozolimskie 202, 02-486 Warszawa
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 25 lines · Krzysztof Hałasa

TDA1997x driver tried to hold two values in a single variable:
device's "client data" pointer was first set to "sd" in v4l2_i2c_subdev_init(), then it was overwritten explicitly using dev_set_drvdata() with "state". This caused tda1997x_remove() to fail badly.

drivers/media/i2c/tda1997x.c +2 -1
index 17be95c0dcb3..fb37918b7fb5 100644
@@ -2490,7 +2490,8 @@ static const struct media_entity_operations tda1997x_media_ops = {
 static int tda1997x_pcm_startup(struct snd_pcm_substream *substream,
                                struct snd_soc_dai *dai)
 {
-       struct tda1997x_state *state = snd_soc_dai_get_drvdata(dai);
+       struct v4l2_subdev *sd = snd_soc_dai_get_drvdata(dai);
+       struct tda1997x_state *state = to_state(sd);
        struct snd_soc_component *component = dai->component;
        struct snd_pcm_runtime *rtd = substream->runtime;
        int rate, err;

drivers/media/i2c/tda1997x.c static int tda1997x_probe(struct i2c_client *client, · line 2805

Quoted 7 lines
drivers/media/i2c/tda1997x.c +0 -1
@@ -2799,7 +2800,6 @@ static int tda1997x_probe(struct i2c_client *client,
                        dev_err(&client->dev, "register audio codec failed\n");
                        goto err_free_media;
                }
-               dev_set_drvdata(&state->client->dev, state);
                v4l_info(state->client, "registered audio codec\n");
        }
 

Tim