Re: [PATCH 1/4] hwmon: (oxp-sensors) Separate logic from device-specific data

From: Guenter Roeck
Date: Thu Dec 26 2024 - 16:04:20 EST


On Thu, Dec 26, 2024 at 06:00:16PM +0100, tjakobi@xxxxxxxxxxxxxxxxxxxxx wrote:
> From: Tobias Jakobi <tjakobi@xxxxxxxxxxxxxxxxxxxxx>
>
> We currently have large switch-statements in all functions that
> write to EC registers, even though the bulk of the supported
> devices functions more or less the same.
>
> Factor the device-specific data out into a struct oxp_config. This
> only leaves logic in the corresponding functions and should make
> adding future devices much easier and less error-prone.
>
> Also introduce struct oxp_data which is going to be used in a
> later commit to cache device state.
>
> Signed-off-by: Tobias Jakobi <tjakobi@xxxxxxxxxxxxxxxxxxxxx>
> ---
> drivers/hwmon/oxp-sensors.c | 517 +++++++++++++++---------------------
> 1 file changed, 215 insertions(+), 302 deletions(-)
>
>
...
> -static int oxp_pwm_disable(void)
> +static int oxp_pwm_disable(const struct oxp_config *config)
> {
> - switch (board) {
> - case orange_pi_neo:
> - return write_to_ec(ORANGEPI_SENSOR_PWM_ENABLE_REG, PWM_MODE_AUTO);
> - case aok_zoe_a1:
> - case aya_neo_2:
> - case aya_neo_air:
> - case aya_neo_air_1s:
> - case aya_neo_air_plus_mendo:
> - case aya_neo_air_pro:
> - case aya_neo_flip:
> - case aya_neo_geek:
> - case aya_neo_kun:
> - case oxp_2:
> - case oxp_fly:
> - case oxp_mini_amd:
> - case oxp_mini_amd_a07:
> - case oxp_mini_amd_pro:
> - case oxp_x1:
> - return write_to_ec(OXP_SENSOR_PWM_ENABLE_REG, PWM_MODE_AUTO);
> - default:
> - return -EINVAL;
> - }
> + if (test_bit(OXP_FEATURE_PWM, &config->features))
> + return write_to_ec(config->sensor_pwm_enable_reg, PWM_MODE_AUTO);
> +

This and all the other feature checks are completely wrong.
Those checks whould happen once in the is_visible functions,
and there should not be any such runtime checks. If a feature
is not available, the associated attributes should not be created
in the first place.

If such checks happen in the current code, that should be fixed
in the is_visible functions. Any existing runtime feature checks
should be removed.

Guenter