* [bug report] ASoC: spacemit: add i2s support for K1 SoC
@ 2025-10-24 11:25 Dan Carpenter
2025-10-24 11:37 ` Troy Mitchell
0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2025-10-24 11:25 UTC (permalink / raw)
To: Troy Mitchell; +Cc: linux-sound, spacemit
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [bug report] ASoC: spacemit: add i2s support for K1 SoC
2025-10-24 11:25 [bug report] ASoC: spacemit: add i2s support for K1 SoC Dan Carpenter
@ 2025-10-24 11:37 ` Troy Mitchell
2025-10-24 11:43 ` Dan Carpenter
0 siblings, 1 reply; 5+ messages in thread
From: Troy Mitchell @ 2025-10-24 11:37 UTC (permalink / raw)
To: Dan Carpenter, Troy Mitchell; +Cc: linux-sound, spacemit
On Fri, Oct 24, 2025 at 02:25:40PM +0300, Dan Carpenter wrote:
> 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.
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
>
> 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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [bug report] ASoC: spacemit: add i2s support for K1 SoC
2025-10-24 11:37 ` Troy Mitchell
@ 2025-10-24 11:43 ` Dan Carpenter
2025-10-24 16:06 ` Alex Elder
0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2025-10-24 11:43 UTC (permalink / raw)
To: Troy Mitchell; +Cc: linux-sound, spacemit
On Fri, Oct 24, 2025 at 07:37:51PM +0800, Troy Mitchell wrote:
> On Fri, Oct 24, 2025 at 02:25:40PM +0300, Dan Carpenter wrote:
> > 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.
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [bug report] ASoC: spacemit: add i2s support for K1 SoC
2025-10-24 11:43 ` Dan Carpenter
@ 2025-10-24 16:06 ` Alex Elder
2025-10-27 2:50 ` Troy Mitchell
0 siblings, 1 reply; 5+ messages in thread
From: Alex Elder @ 2025-10-24 16:06 UTC (permalink / raw)
To: Dan Carpenter, Troy Mitchell; +Cc: linux-sound, spacemit
On 10/24/25 6:43 AM, Dan Carpenter wrote:
> On Fri, Oct 24, 2025 at 07:37:51PM +0800, Troy Mitchell wrote:
>> On Fri, Oct 24, 2025 at 02:25:40PM +0300, Dan Carpenter wrote:
>>> 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.
>> 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
>
> regards,
> dan carpenter
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [bug report] ASoC: spacemit: add i2s support for K1 SoC
2025-10-24 16:06 ` Alex Elder
@ 2025-10-27 2:50 ` Troy Mitchell
0 siblings, 0 replies; 5+ messages in thread
From: Troy Mitchell @ 2025-10-27 2:50 UTC (permalink / raw)
To: Alex Elder, Dan Carpenter, Troy Mitchell; +Cc: linux-sound, spacemit
On Fri, Oct 24, 2025 at 11:06:04AM -0500, Alex Elder wrote:
> On 10/24/25 6:43 AM, Dan Carpenter wrote:
> > On Fri, Oct 24, 2025 at 07:37:51PM +0800, Troy Mitchell wrote:
> > > On Fri, Oct 24, 2025 at 02:25:40PM +0300, Dan Carpenter wrote:
> > > > 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.
> > > 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.)
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
>
> -Alex
>
> >
> > regards,
> > dan carpenter
> >
> >
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-10-27 2:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-24 11:25 [bug report] ASoC: spacemit: add i2s support for K1 SoC Dan Carpenter
2025-10-24 11:37 ` Troy Mitchell
2025-10-24 11:43 ` Dan Carpenter
2025-10-24 16:06 ` Alex Elder
2025-10-27 2:50 ` Troy Mitchell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox