Re: [PATCH] clk: davinci: Add NULL check in davinci_lpsc_clk_register()

David Lechner
2025-04-01T17:21:38Z

On 4/1/25 11:46 AM, Markus Elfring wrote:
>> devm_kasprintf() return NULL if memory allocation fails. Currently,
> …
> call? failed?
>
>
>> Add NULL check after devm_kasprintf() to prevent this issue.
>
> I propose to avoid duplicate source code also for the completion of
> the corresponding exception handling.
>
> * You may avoid repeated function calls by using another label instead.
> https://wiki.sei.cmu.edu/confluence/display/c/MEM12-C.+Consider+using+a+goto+chain+when+leaving+a+function+on+error+when+using+and+releasing+resources#MEM12C.Considerusingagotochainwhenleavingafunctiononerrorwhenusingandreleasingresources-CompliantSolution(copy_process()fromLinuxkernel)

That would be OK too. I didn't worry about it in this case though
since we are only duplicating 1 very short line of code. And the
smaller diff has a better chance of successfully backporting to older
stable kernels that will also pick up this patch.

>
> * How do you think about to benefit any more from the application of the attribute “__free”?
> https://elixir.bootlin.com/linux/v6.14-rc6/source/include/linux/slab.h#L472

Not a good fit for this specific use case.

>
>
> Regards,
> Markus