On Tue, Sep 9, 2025 at 3:20 PM cuitao <cuitao@kylinos.cn> wrote:
>
> Add a check for the return value of kobject_create_and_add to ensure
> that the kobj allocation succeeds.
>
> Signed-off-by: cuitao <cuitao@kylinos.cn>
> ---
> v2: Removed the unnecessary modifications.
> https://lore.kernel.org/all/CAAhV-H7ECnVeOgf93SEXLHLc4wvhQMjQXDbGKCR-KXKWf8Vgtg@mail.gmail.com/
> ---
> arch/loongarch/kernel/env.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/loongarch/kernel/env.c b/arch/loongarch/kernel/env.c
> index c0a5dc9aeae2..f4ae894f4219 100644
> --- a/arch/loongarch/kernel/env.c
> +++ b/arch/loongarch/kernel/env.c
> @@ -109,6 +109,10 @@ static int __init boardinfo_init(void)
> struct kobject *loongson_kobj;
>
> loongson_kobj = kobject_create_and_add("loongson", firmware_kobj);
> + if (!loongson_kobj) {
> + pr_warn("loongson: Firmware registration failed.\n");
The check is useful but the warning is unnecessary, because it is not
fatal for system use.
Huacai
> + return -ENOMEM;
> + }
>
> return sysfs_create_file(loongson_kobj, &boardinfo_attr.attr);
> }
> --
> 2.48.1
>