[PATCH v2 01/11] pwm: Make .get_state() callback return an error code

Neil Armstrong neil.armstrong at linaro.org
Thu Dec 1 00:03:45 PST 2022


On 30/11/2022 16:21, Uwe Kleine-König wrote:
> .get_state() might fail in some cases. To make it possible that a driver
> signals such a failure change the prototype of .get_state() to return an
> error code.
> 
> This patch was created using coccinelle and the following semantic patch:
> 
> @p1@
> identifier getstatefunc;
> identifier driver;
> @@
>   struct pwm_ops driver = {
>          ...,
>          .get_state = getstatefunc
>          ,...
>   };
> 
> @p2@
> identifier p1.getstatefunc;
> identifier chip, pwm, state;
> @@
> -void
> +int
>   getstatefunc(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state)
>   {
>     ...
> -  return;
> +  return 0;
>     ...
>   }
> 
> plus the actual change of the prototype in include/linux/pwm.h (plus some
> manual fixing of indentions and empty lines).
> 
> So for now all drivers return success unconditionally. They are adapted
> in the following patches to make the changes easier reviewable.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig at pengutronix.de>
> ---
>   drivers/gpio/gpio-mvebu.c             |  9 ++++++---
>   drivers/gpu/drm/bridge/ti-sn65dsi86.c | 14 ++++++++------
>   drivers/leds/rgb/leds-qcom-lpg.c      | 14 ++++++++------
>   drivers/pwm/pwm-atmel.c               |  6 ++++--
>   drivers/pwm/pwm-bcm-iproc.c           |  8 +++++---
>   drivers/pwm/pwm-crc.c                 | 10 ++++++----
>   drivers/pwm/pwm-cros-ec.c             |  8 +++++---
>   drivers/pwm/pwm-dwc.c                 |  6 ++++--
>   drivers/pwm/pwm-hibvt.c               |  6 ++++--
>   drivers/pwm/pwm-imx-tpm.c             |  8 +++++---
>   drivers/pwm/pwm-imx27.c               |  8 +++++---
>   drivers/pwm/pwm-intel-lgm.c           |  6 ++++--
>   drivers/pwm/pwm-iqs620a.c             |  6 ++++--
>   drivers/pwm/pwm-keembay.c             |  6 ++++--
>   drivers/pwm/pwm-lpss.c                |  6 ++++--
>   drivers/pwm/pwm-meson.c               |  8 +++++---
>   drivers/pwm/pwm-mtk-disp.c            | 12 +++++++-----
>   drivers/pwm/pwm-pca9685.c             |  8 +++++---
>   drivers/pwm/pwm-raspberrypi-poe.c     |  8 +++++---
>   drivers/pwm/pwm-rockchip.c            | 12 +++++++-----
>   drivers/pwm/pwm-sifive.c              |  6 ++++--
>   drivers/pwm/pwm-sl28cpld.c            |  8 +++++---
>   drivers/pwm/pwm-sprd.c                |  8 +++++---
>   drivers/pwm/pwm-stm32-lp.c            |  8 +++++---
>   drivers/pwm/pwm-sun4i.c               | 12 +++++++-----
>   drivers/pwm/pwm-sunplus.c             |  6 ++++--
>   drivers/pwm/pwm-visconti.c            |  6 ++++--
>   drivers/pwm/pwm-xilinx.c              |  8 +++++---
>   include/linux/pwm.h                   |  4 ++--
>   29 files changed, 146 insertions(+), 89 deletions(-)
> 

<snip>

> diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c
> index 57112f438c6d..16d79ca5d8f5 100644
> --- a/drivers/pwm/pwm-meson.c
> +++ b/drivers/pwm/pwm-meson.c
> @@ -318,8 +318,8 @@ static unsigned int meson_pwm_cnt_to_ns(struct pwm_chip *chip,
>   	return cnt * fin_ns * (channel->pre_div + 1);
>   }
>   
> -static void meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
> -				struct pwm_state *state)
> +static int meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
> +			       struct pwm_state *state)
>   {
>   	struct meson_pwm *meson = to_meson_pwm(chip);
>   	struct meson_pwm_channel_data *channel_data;
> @@ -327,7 +327,7 @@ static void meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
>   	u32 value, tmp;
>   
>   	if (!state)
> -		return;
> +		return 0;
>   
>   	channel = &meson->channels[pwm->hwpwm];
>   	channel_data = &meson_pwm_per_channel_data[pwm->hwpwm];
> @@ -357,6 +357,8 @@ static void meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
>   		state->period = 0;
>   		state->duty_cycle = 0;
>   	}
> +
> +	return 0;
>   }
>   
>   static const struct pwm_ops meson_pwm_ops = {

<snip>

For pwm-meson:

Reviewed-by: Neil Armstrong <neil.armstrong at linaro.org>




More information about the Linux-mediatek mailing list