Messages in this thread | | | Date | Fri, 6 May 2022 17:10:24 +0300 | Subject | Re: [PATCH v7 04/20] kernel: Add combined power-off+restart handler call chain API | From | Dmitry Osipenko <> |
| |
On 4/20/22 21:47, Rafael J. Wysocki wrote: >>>> + POWEROFF_PREPARE, >>>> +}; >>>> + >>>> +/** >>>> + * struct power_off_data - Power-off callback argument >>>> + * >>>> + * @cb_data: Callback data. >>>> + */ >>>> +struct power_off_data { >>>> + void *cb_data; >>>> +}; >>>> + >>>> +/** >>>> + * struct power_off_prep_data - Power-off preparation callback argument >>>> + * >>>> + * @cb_data: Callback data. >>>> + */ >>>> +struct power_off_prep_data { >>>> + void *cb_data; >>>> +}; >>> Why does this need to be a separate data type? >> To allow us extend the "struct power_off_prep_data" with more parameters >> later on without a need to update each driver with the new arguments.
> I'm not really sure what you mean here. Can you give an example? >
The restart callbacks use more than the cb_data and we have:
struct restart_data { void *cb_data; const char *cmd; bool stop_chain; enum reboot_mode mode; };
If we'll ever need to extended struct power_off_data similarly to the restart_data, then we will need to update all the power-off callbacks instead of adding a new field to the power_off_data.
Hence, for example, if you'll want to extend power_off_data with "enum poweroff_mode mode", then for each driver you'll need to do this change:
-power_off(void *cb_data) +power_off(void *cb_data, enum poweroff_mode mode)
and you won't need to do that using struct power_off_data.
Why do we need this? Because I saw in the past people changing kernel APIs that way when they wanted to add new arguments and then needed to update every call site around the kernel.
-- Best regards, Dmitry
| |