Skip to contentSkip to conversation

ASoC: spacemit: add i2s support for K1 SoC

bug report Dan Carpenter 3 participants 5 messages Oct 24, 2025 – Oct 27, 2025

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

Hello Troy Mitchell,

Commit fce217449075 ("ASoC: spacemit: add i2s support for K1 SoC") from Oct 17, 2025 (linux-next), leads to the following Smatch static checker warning:

	sound/soc/spacemit/k1_i2s.c:435 spacemit_i2s_probe()
	error: uninitialized symbol 'dai'.

sound/soc/spacemit/k1_i2s.c

    389 static int spacemit_i2s_probe(struct platform_device *pdev)
    390 {
    391         struct snd_soc_dai_driver *dai;
    392         struct spacemit_i2s_dev *i2s;
    393         struct resource *res;
    394         struct clk *clk;
    395         int ret;
    396 
    397         i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL);
    398         if (!i2s)
    399                 return -ENOMEM;
    400 
    401         i2s->dev = &pdev->dev;
    402 
    403         i2s->sysclk = devm_clk_get_enabled(i2s->dev, "sysclk");
    404         if (IS_ERR(i2s->sysclk))
    405                 return dev_err_probe(i2s->dev, PTR_ERR(i2s->sysclk),
    406                                      "failed to enable sysbase clock\n");
    407 
    408         i2s->bclk = devm_clk_get_enabled(i2s->dev, "bclk");
    409         if (IS_ERR(i2s->bclk))
    410                 return dev_err_probe(i2s->dev, PTR_ERR(i2s->bclk), "failed to enable bit clock\n");
    411 
    412         clk = devm_clk_get_enabled(i2s->dev, "sspa_bus");
    413         if (IS_ERR(clk))
    414                 return dev_err_probe(i2s->dev, PTR_ERR(clk), "failed to enable sspa_bus clock\n");
    415 
    416         i2s->sspa_clk = devm_clk_get_enabled(i2s->dev, "sspa");
    417         if (IS_ERR(clk))
    418                 return dev_err_probe(i2s->dev, PTR_ERR(clk), "failed to enable sspa clock\n");
    419 
    420         i2s->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
    421         if (IS_ERR(i2s->base))
    422                 return dev_err_probe(i2s->dev, PTR_ERR(i2s->base), "failed to map registers\n");
    423 
    424         i2s->reset = devm_reset_control_get_exclusive(&pdev->dev, NULL);
    425         if (IS_ERR(i2s->reset))
    426                 return dev_err_probe(i2s->dev, PTR_ERR(i2s->reset),
    427                                      "failed to get reset control");
    428 
    429         dev_set_drvdata(i2s->dev, i2s);
    430 
    431         spacemit_i2s_init_dai(i2s, &dai, res->start + SSDATR);
                                           ^^^^

dai is not initialized on failure. Generally in the kernel we always check for allocation failures. Even when they can't happen in real life. I was hoping they were going to make a rule that allocations under 4k wouldn't have to be checked but it hasn't happened yet.

    432 
    433         ret = devm_snd_soc_register_component(i2s->dev,
    434                                               &spacemit_i2s_component,
--> 435                                               dai, 1);
    436         if (ret)
    437                 return dev_err_probe(i2s->dev, ret, "failed to register component");
    438 
    439         return devm_snd_dmaengine_pcm_register(&pdev->dev, &spacemit_dmaengine_pcm_config, 0);
    440 }

regards,
dan carpenter

reviewer
#1 lore raw
Quoted 54 lines · Dan Carpenter

Hello Troy Mitchell,

Commit fce217449075 ("ASoC: spacemit: add i2s support for K1 SoC") from Oct 17, 2025 (linux-next), leads to the following Smatch static checker warning:

	sound/soc/spacemit/k1_i2s.c:435 spacemit_i2s_probe()
	error: uninitialized symbol 'dai'.

sound/soc/spacemit/k1_i2s.c

    389 static int spacemit_i2s_probe(struct platform_device *pdev)
    390 {
    391         struct snd_soc_dai_driver *dai;
    392         struct spacemit_i2s_dev *i2s;
    393         struct resource *res;
    394         struct clk *clk;
    395         int ret;
    396 
    397         i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL);
    398         if (!i2s)
    399                 return -ENOMEM;
    400 
    401         i2s->dev = &pdev->dev;
    402 
    403         i2s->sysclk = devm_clk_get_enabled(i2s->dev, "sysclk");
    404         if (IS_ERR(i2s->sysclk))
    405                 return dev_err_probe(i2s->dev, PTR_ERR(i2s->sysclk),
    406                                      "failed to enable sysbase clock\n");
    407 
    408         i2s->bclk = devm_clk_get_enabled(i2s->dev, "bclk");
    409         if (IS_ERR(i2s->bclk))
    410                 return dev_err_probe(i2s->dev, PTR_ERR(i2s->bclk), "failed to enable bit clock\n");
    411 
    412         clk = devm_clk_get_enabled(i2s->dev, "sspa_bus");
    413         if (IS_ERR(clk))
    414                 return dev_err_probe(i2s->dev, PTR_ERR(clk), "failed to enable sspa_bus clock\n");
    415 
    416         i2s->sspa_clk = devm_clk_get_enabled(i2s->dev, "sspa");
    417         if (IS_ERR(clk))
    418                 return dev_err_probe(i2s->dev, PTR_ERR(clk), "failed to enable sspa clock\n");
    419 
    420         i2s->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
    421         if (IS_ERR(i2s->base))
    422                 return dev_err_probe(i2s->dev, PTR_ERR(i2s->base), "failed to map registers\n");
    423 
    424         i2s->reset = devm_reset_control_get_exclusive(&pdev->dev, NULL);
    425         if (IS_ERR(i2s->reset))
    426                 return dev_err_probe(i2s->dev, PTR_ERR(i2s->reset),
    427                                      "failed to get reset control");
    428 
    429         dev_set_drvdata(i2s->dev, i2s);
    430 
    431         spacemit_i2s_init_dai(i2s, &dai, res->start + SSDATR);
                                           ^^^^
Quoted 4 lines

dai is not initialized on failure. Generally in the kernel we always check for allocation failures. Even when they can't happen in real life. I was hoping they were going to make a rule that allocations under 4k wouldn't have to be checked but it hasn't happened yet.

Should I send a fix patch now, or should I wait for the maintainer to revert it first, and then fix this error and send?

Thanks for your report!

- Troy

Quoted 14 lines
    432 
    433         ret = devm_snd_soc_register_component(i2s->dev,
    434                                               &spacemit_i2s_component,
--> 435                                               dai, 1);
    436         if (ret)
    437                 return dev_err_probe(i2s->dev, ret, "failed to register component");
    438 
    439         return devm_snd_dmaengine_pcm_register(&pdev->dev, &spacemit_dmaengine_pcm_config, 0);
    440 }

regards,
dan carpenter

#2 lore raw
Quoted 14 lines · Troy Mitchell
Quoted 9 lines · Dan Carpenter
    424         i2s->reset = devm_reset_control_get_exclusive(&pdev->dev, NULL);
    425         if (IS_ERR(i2s->reset))
    426                 return dev_err_probe(i2s->dev, PTR_ERR(i2s->reset),
    427                                      "failed to get reset control");
    428 
    429         dev_set_drvdata(i2s->dev, i2s);
    430 
    431         spacemit_i2s_init_dai(i2s, &dai, res->start + SSDATR);
                                           ^^^^
Quoted 4 lines

dai is not initialized on failure. Generally in the kernel we always check for allocation failures. Even when they can't happen in real life. I was hoping they were going to make a rule that allocations under 4k wouldn't have to be checked but it hasn't happened yet.

Quoted 5 lines

Should I send a fix patch now, or should I wait for the maintainer to revert it first, and then fix this error and send?

Thanks for your report!

You should send a follow on patch which just fixes the one issue. If the maintainer wants to squash them together that's very easy to do in git.

regards,
dan carpenter

#3 lore raw
Quoted 15 lines · Dan Carpenter
Quoted 14 lines · Troy Mitchell
Quoted 13 lines · Dan Carpenter
     424         i2s->reset = devm_reset_control_get_exclusive(&pdev->dev, NULL);
     425         if (IS_ERR(i2s->reset))
     426                 return dev_err_probe(i2s->dev, PTR_ERR(i2s->reset),
     427                                      "failed to get reset control");
     428
     429         dev_set_drvdata(i2s->dev, i2s);
     430
     431         spacemit_i2s_init_dai(i2s, &dai, res->start + SSDATR);
                                            ^^^^

dai is not initialized on failure. Generally in the kernel we always check for allocation failures. Even when they can't happen in real life. I was hoping they were going to make a rule that allocations under 4k wouldn't have to be checked but it hasn't happened yet.

Quoted 8 lines
Quoted 5 lines

Should I send a fix patch now, or should I wait for the maintainer to revert it first, and then fix this error and send?

Thanks for your report!

You should send a follow on patch which just fixes the one issue. If the maintainer wants to squash them together that's very easy to do in git.

Yes I agree, send a new patch, no point in reverting. But I think a fix commit is better than squashing (for what that's worth).

A very simple fix is assigning *dp to NULL in spacemit_i2s_init_dai().

        if (dp)
                *dp = dai ? : NULL;

Also: Why aren't you checking for spacemit_i2s_init_dai() returning an error? (Another--separate--suggested fix.)

-Alex

Quoted 5 lines

regards,
dan carpenter

reviewer
#4 lore raw
Quoted 29 lines · Alex Elder
Quoted 15 lines · Dan Carpenter
Quoted 14 lines · Troy Mitchell
Quoted 13 lines · Dan Carpenter
     424         i2s->reset = devm_reset_control_get_exclusive(&pdev->dev, NULL);
     425         if (IS_ERR(i2s->reset))
     426                 return dev_err_probe(i2s->dev, PTR_ERR(i2s->reset),
     427                                      "failed to get reset control");
     428
     429         dev_set_drvdata(i2s->dev, i2s);
     430
     431         spacemit_i2s_init_dai(i2s, &dai, res->start + SSDATR);
                                            ^^^^

dai is not initialized on failure. Generally in the kernel we always check for allocation failures. Even when they can't happen in real life. I was hoping they were going to make a rule that allocations under 4k wouldn't have to be checked but it hasn't happened yet.

Quoted 8 lines
Quoted 5 lines

Should I send a fix patch now, or should I wait for the maintainer to revert it first, and then fix this error and send?

Thanks for your report!

You should send a follow on patch which just fixes the one issue. If the maintainer wants to squash them together that's very easy to do in git.

Yes I agree, send a new patch, no point in reverting. But I think a fix commit is better than squashing (for what that's worth).

Quoted 7 lines

A very simple fix is assigning *dp to NULL in spacemit_i2s_init_dai().

        if (dp)
                *dp = dai ? : NULL;

Also: Why aren't you checking for spacemit_i2s_init_dai() returning an error? (Another--separate--suggested fix.)

The cause of this error was that we did not check the return value. Indeed, this was an oversight on my part, and I have sent a fix for it.

- Troy

Quoted 10 lines

-Alex

Quoted 5 lines

regards,
dan carpenter