[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH-for-5.1 3/3] hw: Remove unnecessary DEVICE() cast
From: |
Markus Armbruster |
Subject: |
Re: [PATCH-for-5.1 3/3] hw: Remove unnecessary DEVICE() cast |
Date: |
Tue, 14 Apr 2020 13:31:59 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) |
Philippe Mathieu-Daudé <address@hidden> 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é <address@hidden>
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 <address@hidden>
There are many similar macros. Should they get the same treatment?