[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH-for-5.1 3/3] hw: Remove unnecessary DEVICE() cast
- To: Philippe Mathieu-Daudé <f4bug@xxxxxxxxx>
- From: Markus Armbruster <armbru@xxxxxxxxxx>
- Date: Tue, 14 Apr 2020 13:31:59 +0200
- Cc: Peter Maydell <peter.maydell@xxxxxxxxxx>, David Hildenbrand <david@xxxxxxxxxx>, Jason Wang <jasowang@xxxxxxxxxx>, Mark Cave-Ayland <mark.cave-ayland@xxxxxxxxxxxx>, qemu-devel@xxxxxxxxxx, Gerd Hoffmann <kraxel@xxxxxxxxxx>, "Edgar E. Iglesias" <edgar.iglesias@xxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, qemu-block@xxxxxxxxxx, Paul Durrant <paul@xxxxxxx>, Halil Pasic <pasic@xxxxxxxxxxxxx>, Christian Borntraeger <borntraeger@xxxxxxxxxx>, Aleksandar Markovic <aleksandar.qemu.devel@xxxxxxxxx>, Joel Stanley <joel@xxxxxxxxx>, Anthony Perard <anthony.perard@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, Richard Henderson <rth@xxxxxxxxxxx>, Philippe Mathieu-Daudé <philmd@xxxxxxxxxx>, Eduardo Habkost <ehabkost@xxxxxxxxxx>, Corey Minyard <minyard@xxxxxxx>, "Dr. David Alan Gilbert" <dgilbert@xxxxxxxxxx>, qemu-s390x@xxxxxxxxxx, qemu-arm@xxxxxxxxxx, Peter Chubb <peter.chubb@xxxxxxxxxxxx>, Cédric Le Goater <clg@xxxxxxxx>, John Snow <jsnow@xxxxxxxxxx>, David Gibson <david@xxxxxxxxxxxxxxxxxxxxx>, "Daniel P. Berrangé" <berrange@xxxxxxxxxx>, Andrew Jeffery <andrew@xxxxxxxx>, Cornelia Huck <cohuck@xxxxxxxxxx>, Laurent Vivier <laurent@xxxxxxxxx>, qemu-ppc@xxxxxxxxxx, Paolo Bonzini <pbonzini@xxxxxxxxxx>, Aurelien Jarno <aurelien@xxxxxxxxxxx>
- Delivery-date: Tue, 14 Apr 2020 11:32:16 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
Philippe Mathieu-Daudé <f4bug@xxxxxxxxx> writes:
> The DEVICE() macro is defined as:
>
> #define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
>
> Remove unnecessary DEVICE() casts.
>
> Patch created mechanically using spatch with this script:
>
> @@
> typedef DeviceState;
> DeviceState *s;
> @@
> - DEVICE(s)
> + s
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@xxxxxxxxx>
DEVICE(obj) expands to
OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
and then to
((DeviceState *)object_dynamic_cast_assert((Object *)(obj), (name),
__FILE__, __LINE__, __func__))
object_dynamic_cast_assert() asserts @obj can be safely converted to the
type named by @name, and returns @obj.
Your patch drops the assertion.
The assertion can only fail when @obj points to something other than its
stated type, i.e. when we're in undefined behavior country.
Preferably with this argument worked into your commit message:
Reviewed-by: Markus Armbruster <armbru@xxxxxxxxxx>
There are many similar macros. Should they get the same treatment?
|