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

nobuhiro1.iwamatsu
2022-12-01T09:32:18Z

> -----Original Message-----
> From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> Sent: Thursday, December 1, 2022 12:22 AM
> To: Thierry Reding <thierry.reding@gmail.com>
> Cc: Conor Dooley <conor.dooley@microchip.com>; Linus Walleij
> <linus.walleij@linaro.org>; Bartosz Golaszewski <brgl@bgdev.pl>; Douglas
> Anderson <dianders@chromium.org>; Pavel Machek <pavel@ucw.cz>;
> Claudiu Beznea <claudiu.beznea@microchip.com>; Nicolas Ferre
> <nicolas.ferre@microchip.com>; Alexandre Belloni
> <alexandre.belloni@bootlin.com>; Ray Jui <rjui@broadcom.com>; Scott
> Branden <sbranden@broadcom.com>; Broadcom internal kernel review list
> <bcm-kernel-feedback-list@broadcom.com>; Benson Leung
> <bleung@chromium.org>; Guenter Roeck <groeck@chromium.org>; Shawn
> Guo <shawnguo@kernel.org>; Sascha Hauer <s.hauer@pengutronix.de>;
> Pengutronix Kernel Team <kernel@pengutronix.de>; Fabio Estevam
> <festevam@gmail.com>; NXP Linux Team <linux-imx@nxp.com>; Kevin
> Hilman <khilman@baylibre.com>; Jerome Brunet <jbrunet@baylibre.com>;
> Martin Blumenstingl <martin.blumenstingl@googlemail.com>; Matthias
> Brugger <matthias.bgg@gmail.com>; Florian Fainelli <f.fainelli@gmail.com>;
> Heiko Stuebner <heiko@sntech.de>; Palmer Dabbelt
> <palmer@dabbelt.com>; Paul Walmsley <paul.walmsley@sifive.com>;
> Michael Walle <michael@walle.cc>; Orson Zhai <orsonzhai@gmail.com>;
> Baolin Wang <baolin.wang@linux.alibaba.com>; Chunyan Zhang
> <zhang.lyra@gmail.com>; Fabrice Gasnier <fabrice.gasnier@foss.st.com>;
> Maxime Coquelin <mcoquelin.stm32@gmail.com>; Alexandre Torgue
> <alexandre.torgue@foss.st.com>; Chen-Yu Tsai <wens@csie.org>; Samuel
> Holland <samuel@sholland.org>; Hammer Hsieh
> <hammerh0314@gmail.com>; iwamatsu nobuhiro(岩松 信洋 □ＳＷＣ◯ＡＣ
> Ｔ) <nobuhiro1.iwamatsu@toshiba.co.jp>; Sean Anderson
> <sean.anderson@seco.com>; Michal Simek <michal.simek@xilinx.com>;
> Bjorn Andersson <andersson@kernel.org>; Stephen Boyd
> <swboyd@chromium.org>; Matthias Kaehlcke <mka@chromium.org>; Satya
> Priya <quic_c_skakit@quicinc.com>; linux-pwm@vger.kernel.org;
> linux-gpio@vger.kernel.org; dri-devel@lists.freedesktop.org;
> linux-leds@vger.kernel.org; linux-arm-kernel@lists.infradead.org;
> chrome-platform@lists.linux.dev; linux-amlogic@lists.infradead.org;
> linux-mediatek@lists.infradead.org; linux-rpi-kernel@lists.infradead.org;
> linux-rockchip@lists.infradead.org; linux-riscv@lists.infradead.org;
> linux-stm32@st-md-mailman.stormreply.com; linux-sunxi@lists.linux.dev
> Subject: [PATCH v2 01/11] pwm: Make .get_state() callback return an error
> code
>
> .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@pengutronix.de>

<snip>

> a/drivers/pwm/pwm-visconti.c b/drivers/pwm/pwm-visconti.c index
> 927c4cbb1daf..e3fb79b3e2a7 100644
> --- a/drivers/pwm/pwm-visconti.c
> +++ b/drivers/pwm/pwm-visconti.c
> @@ -103,8 +103,8 @@ static int visconti_pwm_apply(struct pwm_chip *chip,
> struct pwm_device *pwm,
> return 0;
> }
>
> -static void visconti_pwm_get_state(struct pwm_chip *chip, struct
> pwm_device *pwm,
> - struct pwm_state *state)
> +static int visconti_pwm_get_state(struct pwm_chip *chip, struct
> pwm_device *pwm,
> + struct pwm_state *state)
> {
> struct visconti_pwm_chip *priv = visconti_pwm_from_chip(chip);
> u32 period, duty, pwmc0, pwmc0_clk;
> @@ -122,6 +122,8 @@ static void visconti_pwm_get_state(struct pwm_chip
> *chip, struct pwm_device *pwm
> state->polarity = PWM_POLARITY_NORMAL;
>
> state->enabled = true;
> +
> + return 0;
> }
>
> static const struct pwm_ops visconti_pwm_ops = { diff --git

<snip>

for the Visconti pwd:
Reviewed-by: Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp>