All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: bibo mao <maobibo@loongson.cn>
Cc: Song Gao <gaosong@loongson.cn>,
	 Jiaxun Yang <jiaxun.yang@flygoat.com>,
	qemu-devel@nongnu.org,  Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH v2 2/3] hw/loongarch/virt: Remove unnecessary NULL pointer checking
Date: Fri, 14 Mar 2025 10:38:42 +0100	[thread overview]
Message-ID: <87ldt8q7dp.fsf@pond.sub.org> (raw)
In-Reply-To: <63fc3b2b-140c-a4e4-c3ec-536cc31d9f11@loongson.cn> (bibo mao's message of "Fri, 14 Mar 2025 17:25:45 +0800")

bibo mao <maobibo@loongson.cn> writes:

On 2025/3/14 下午5:11, Markus Armbruster wrote:
>> Bibo Mao <maobibo@loongson.cn> writes:
>> 
>>> There is NULL pointer checking function error_propagate() already,
>>> it is not necessary to add checking for function parameter. Here remove
>>> NULL pointer checking with function parameter.
>>>
>>> Signed-off-by: Bibo Mao <maobibo@loongson.cn>

[...]

>>> @@ -1001,9 +999,8 @@ static void virt_cpu_plug(HotplugHandler *hotplug_dev,
>>         cpu_slot = virt_find_cpu_slot(MACHINE(lvms), cpu->phy_id);
>>         cpu_slot->cpu = CPU(dev);
>>         if (lvms->ipi) {
>>             hotplug_handler_plug(HOTPLUG_HANDLER(lvms->ipi), dev, &err);
>>             if (err) {
>>                 error_propagate(errp, err);
>>                 return;
>>             }
>>         }
>> 
>>         if (lvms->extioi) {
>>             hotplug_handler_plug(HOTPLUG_HANDLER(lvms->extioi), dev, &err);
>>             if (err) {
>>                 error_propagate(errp, err);
>>                 return;
>>             }
>>         }
>>>   
>>>       if (lvms->acpi_ged) {
>>>           hotplug_handler_plug(HOTPLUG_HANDLER(lvms->acpi_ged), dev, &err);
>>> -        if (err) {
>>> -            error_propagate(errp, err);
>>> -        }
>>> +        error_propagate(errp, err);
>>> +        return;
>>>       }
>>>   
>>>       return;
>> 
>> Better make this work exactly like the other checks above, and drop the
>> final return, which serves no purpose:
>> 
>>             if (err) {
>>                 error_propagate(errp, err);
>>                 return;
>>             }
>>         }
> Here is report from commandline, it say err NULL check is not necessary
> spatch --sp-file scripts/coccinelle/error_propagate_null.cocci --dir 
> hw/loongarch/
>
> @@ -1001,9 +997,7 @@ static void virt_cpu_plug(HotplugHandler
>
>       if (lvms->acpi_ged) {
>           hotplug_handler_plug(HOTPLUG_HANDLER(lvms->acpi_ged), dev, &err);
> -        if (err) {
> -            error_propagate(errp, err);
> -        }
> +        error_propagate(errp, err);
>       }

This change is correct.  The change I suggests is also correct.  I
prefer mine because it's less easy to screw up.  If you add another
check at the end, my version keeps working, while yours needs an update,
which is easy to miss.



  reply	other threads:[~2025-03-14  9:39 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-14  8:41 [PATCH v2 0/3] target/loongarch: Solve some issues reported from coccinelle Bibo Mao
2025-03-14  8:41 ` [PATCH v2 1/3] target/loongarch: Fix error handling of KVM feature checks Bibo Mao
2025-03-14 11:31   ` Philippe Mathieu-Daudé
2025-03-14  8:42 ` [PATCH v2 2/3] hw/loongarch/virt: Remove unnecessary NULL pointer checking Bibo Mao
2025-03-14  9:11   ` Markus Armbruster
2025-03-14  9:25     ` bibo mao
2025-03-14  9:38       ` Markus Armbruster [this message]
2025-03-14  9:55         ` bibo mao
2025-03-14  8:42 ` [PATCH v2 3/3] target/loongarch: Remove unnecessary temporary variable assignment Bibo Mao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ldt8q7dp.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=gaosong@loongson.cn \
    --cc=jiaxun.yang@flygoat.com \
    --cc=maobibo@loongson.cn \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.